removed unused code for now.
This commit is contained in:
+40
-50
@@ -5,15 +5,10 @@ import java.sql.SQLException;
|
|||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
|
|
||||||
import org.mifosng.platform.api.data.DocumentData;
|
import org.mifosng.platform.api.data.DocumentData;
|
||||||
import org.mifosng.platform.client.service.ClientReadPlatformService;
|
|
||||||
import org.mifosng.platform.exceptions.DocumentNotFoundException;
|
import org.mifosng.platform.exceptions.DocumentNotFoundException;
|
||||||
import org.mifosng.platform.infrastructure.JdbcSupport;
|
import org.mifosng.platform.infrastructure.JdbcSupport;
|
||||||
import org.mifosng.platform.infrastructure.TenantAwareRoutingDataSource;
|
import org.mifosng.platform.infrastructure.TenantAwareRoutingDataSource;
|
||||||
import org.mifosng.platform.loan.service.LoanReadPlatformService;
|
|
||||||
import org.mifosng.platform.organisation.service.OfficeReadPlatformService;
|
|
||||||
import org.mifosng.platform.security.PlatformSecurityContext;
|
import org.mifosng.platform.security.PlatformSecurityContext;
|
||||||
import org.mifosng.platform.staff.service.StaffReadPlatformService;
|
|
||||||
import org.mifosng.platform.user.service.AppUserReadPlatformService;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.dao.EmptyResultDataAccessException;
|
import org.springframework.dao.EmptyResultDataAccessException;
|
||||||
import org.springframework.jdbc.core.JdbcTemplate;
|
import org.springframework.jdbc.core.JdbcTemplate;
|
||||||
@@ -21,72 +16,69 @@ import org.springframework.jdbc.core.RowMapper;
|
|||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
public class DocumentReadPlatformServiceImpl implements
|
public class DocumentReadPlatformServiceImpl implements DocumentReadPlatformService {
|
||||||
DocumentReadPlatformService {
|
|
||||||
|
|
||||||
private final JdbcTemplate jdbcTemplate;
|
private final JdbcTemplate jdbcTemplate;
|
||||||
|
|
||||||
// TODO: use these services to check if passed in entities for document
|
// TODO: use these services to check if passed in entities for document
|
||||||
// management exists (and ensure appropriate errors are thrown)
|
// management exists (and ensure appropriate errors are thrown)
|
||||||
private final PlatformSecurityContext context;
|
private final PlatformSecurityContext context;
|
||||||
private final OfficeReadPlatformService officeReadPlatformService;
|
// private final OfficeReadPlatformService officeReadPlatformService;
|
||||||
private final ClientReadPlatformService clientReadPlatformService;
|
// private final ClientReadPlatformService clientReadPlatformService;
|
||||||
private final LoanReadPlatformService loanReadPlatformService;
|
// private final LoanReadPlatformService loanReadPlatformService;
|
||||||
private final StaffReadPlatformService staffReadPlatformService;
|
// private final StaffReadPlatformService staffReadPlatformService;
|
||||||
private final AppUserReadPlatformService appUserReadPlatformService;
|
// private final AppUserReadPlatformService appUserReadPlatformService;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
public DocumentReadPlatformServiceImpl(
|
public DocumentReadPlatformServiceImpl(
|
||||||
final PlatformSecurityContext context,
|
final PlatformSecurityContext context,
|
||||||
final TenantAwareRoutingDataSource dataSource,
|
final TenantAwareRoutingDataSource dataSource
|
||||||
final OfficeReadPlatformService officeReadPlatformService,
|
// final OfficeReadPlatformService officeReadPlatformService,
|
||||||
final AppUserReadPlatformService appUserReadPlatformService,
|
// final AppUserReadPlatformService appUserReadPlatformService,
|
||||||
final ClientReadPlatformService clientReadPlatformService,
|
// final ClientReadPlatformService clientReadPlatformService,
|
||||||
final LoanReadPlatformService loanReadPlatformService,
|
// final LoanReadPlatformService loanReadPlatformService,
|
||||||
final StaffReadPlatformService staffReadPlatformService) {
|
// final StaffReadPlatformService staffReadPlatformService
|
||||||
|
) {
|
||||||
this.context = context;
|
this.context = context;
|
||||||
this.officeReadPlatformService = officeReadPlatformService;
|
// this.officeReadPlatformService = officeReadPlatformService;
|
||||||
this.appUserReadPlatformService = appUserReadPlatformService;
|
// this.appUserReadPlatformService = appUserReadPlatformService;
|
||||||
|
// this.clientReadPlatformService = clientReadPlatformService;
|
||||||
|
// this.loanReadPlatformService = loanReadPlatformService;
|
||||||
|
// this.staffReadPlatformService = staffReadPlatformService;
|
||||||
this.jdbcTemplate = new JdbcTemplate(dataSource);
|
this.jdbcTemplate = new JdbcTemplate(dataSource);
|
||||||
this.clientReadPlatformService = clientReadPlatformService;
|
|
||||||
this.loanReadPlatformService = loanReadPlatformService;
|
|
||||||
this.staffReadPlatformService = staffReadPlatformService;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Collection<DocumentData> retrieveAllDocuments(String entityType,
|
public Collection<DocumentData> retrieveAllDocuments(final String entityType, final Long entityId) {
|
||||||
Long entityId) {
|
|
||||||
|
context.authenticatedUser();
|
||||||
|
|
||||||
// TODO verify if the entities are valid and a user
|
// TODO verify if the entities are valid and a user
|
||||||
// has data
|
// has data
|
||||||
// scope for the particular entities
|
// scope for the particular entities
|
||||||
DocumentMapper mapper = new DocumentMapper();
|
DocumentMapper mapper = new DocumentMapper();
|
||||||
String sql = "select " + mapper.schema() + " order by d.id";
|
String sql = "select " + mapper.schema() + " order by d.id";
|
||||||
return this.jdbcTemplate.query(sql, mapper, new Object[] { entityType,
|
return this.jdbcTemplate.query(sql, mapper, new Object[] {entityType, entityId});
|
||||||
entityId });
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public DocumentData retrieveDocument(String entityType, Long entityId,
|
public DocumentData retrieveDocument(final String entityType, final Long entityId, final Long documentId) {
|
||||||
Long documentId) {
|
|
||||||
try {
|
try {
|
||||||
|
context.authenticatedUser();
|
||||||
|
|
||||||
// TODO verify if the entities are valid and a
|
// TODO verify if the entities are valid and a
|
||||||
// user has data
|
// user has data
|
||||||
// scope for the particular entities
|
// scope for the particular entities
|
||||||
DocumentMapper mapper = new DocumentMapper();
|
DocumentMapper mapper = new DocumentMapper();
|
||||||
String sql = "select " + mapper.schema() + " and d.id=? ";
|
String sql = "select " + mapper.schema() + " and d.id=? ";
|
||||||
return this.jdbcTemplate.queryForObject(sql, mapper, new Object[] {
|
return this.jdbcTemplate.queryForObject(sql, mapper, new Object[] {entityType, entityId, documentId });
|
||||||
entityType, entityId, documentId });
|
|
||||||
} catch (EmptyResultDataAccessException e) {
|
} catch (EmptyResultDataAccessException e) {
|
||||||
throw new DocumentNotFoundException(entityType, entityId,
|
throw new DocumentNotFoundException(entityType, entityId, documentId);
|
||||||
documentId);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final class DocumentMapper implements
|
private static final class DocumentMapper implements RowMapper<DocumentData> {
|
||||||
RowMapper<DocumentData> {
|
|
||||||
|
|
||||||
public DocumentMapper() {
|
|
||||||
}
|
|
||||||
|
|
||||||
public String schema() {
|
public String schema() {
|
||||||
return "d.id as id, d.parent_entity_type as parentEntityType, d.parent_entity_id as parentEntityId, d.name as name, "
|
return "d.id as id, d.parent_entity_type as parentEntityType, d.parent_entity_id as parentEntityId, d.name as name, "
|
||||||
@@ -96,22 +88,20 @@ public class DocumentReadPlatformServiceImpl implements
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public DocumentData mapRow(final ResultSet rs, final int rowNum)
|
public DocumentData mapRow(final ResultSet rs, @SuppressWarnings("unused") final int rowNum) throws SQLException {
|
||||||
throws SQLException {
|
|
||||||
|
|
||||||
Long id = JdbcSupport.getLong(rs, "id");
|
final Long id = JdbcSupport.getLong(rs, "id");
|
||||||
Long parentEntityId = JdbcSupport.getLong(rs, "parentEntityId");
|
final Long parentEntityId = JdbcSupport.getLong(rs, "parentEntityId");
|
||||||
Long fileSize = JdbcSupport.getLong(rs, "fileSize");
|
final Long fileSize = JdbcSupport.getLong(rs, "fileSize");
|
||||||
String parentEntityType = rs.getString("parentEntityType");
|
final String parentEntityType = rs.getString("parentEntityType");
|
||||||
String name = rs.getString("name");
|
final String name = rs.getString("name");
|
||||||
String fileName = rs.getString("fileName");
|
final String fileName = rs.getString("fileName");
|
||||||
String fileType = rs.getString("fileType");
|
final String fileType = rs.getString("fileType");
|
||||||
String description = rs.getString("description");
|
final String description = rs.getString("description");
|
||||||
String location = rs.getString("location");
|
final String location = rs.getString("location");
|
||||||
|
|
||||||
return new DocumentData(id, parentEntityType, parentEntityId, name,
|
return new DocumentData(id, parentEntityType, parentEntityId, name,
|
||||||
fileName, fileSize, fileType, description, location);
|
fileName, fileSize, fileType, description, location);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
+27
-31
@@ -6,19 +6,15 @@ import java.io.InputStream;
|
|||||||
|
|
||||||
import org.mifosng.platform.api.commands.DocumentCommand;
|
import org.mifosng.platform.api.commands.DocumentCommand;
|
||||||
import org.mifosng.platform.api.data.EntityIdentifier;
|
import org.mifosng.platform.api.data.EntityIdentifier;
|
||||||
import org.mifosng.platform.client.domain.ClientRepository;
|
|
||||||
import org.mifosng.platform.common.ApplicationConstants;
|
import org.mifosng.platform.common.ApplicationConstants;
|
||||||
import org.mifosng.platform.common.FileUtils;
|
import org.mifosng.platform.common.FileUtils;
|
||||||
import org.mifosng.platform.documentmanagement.domain.Document;
|
import org.mifosng.platform.documentmanagement.domain.Document;
|
||||||
import org.mifosng.platform.documentmanagement.domain.DocumentRepository;
|
import org.mifosng.platform.documentmanagement.domain.DocumentRepository;
|
||||||
import org.mifosng.platform.exceptions.DocumentNotFoundException;
|
|
||||||
import org.mifosng.platform.exceptions.DocumentManagementException;
|
import org.mifosng.platform.exceptions.DocumentManagementException;
|
||||||
|
import org.mifosng.platform.exceptions.DocumentNotFoundException;
|
||||||
import org.mifosng.platform.exceptions.InvalidEntityTypeForDocumentManagementException;
|
import org.mifosng.platform.exceptions.InvalidEntityTypeForDocumentManagementException;
|
||||||
import org.mifosng.platform.exceptions.PlatformDataIntegrityException;
|
import org.mifosng.platform.exceptions.PlatformDataIntegrityException;
|
||||||
import org.mifosng.platform.loan.domain.LoanRepository;
|
|
||||||
import org.mifosng.platform.organisation.domain.OfficeRepository;
|
|
||||||
import org.mifosng.platform.security.PlatformSecurityContext;
|
import org.mifosng.platform.security.PlatformSecurityContext;
|
||||||
import org.mifosng.platform.staff.domain.StaffRepository;
|
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
@@ -30,41 +26,40 @@ import org.springframework.transaction.annotation.Transactional;
|
|||||||
public class DocumentWritePlatformServiceJpaRepositoryImpl implements
|
public class DocumentWritePlatformServiceJpaRepositoryImpl implements
|
||||||
DocumentWritePlatformService {
|
DocumentWritePlatformService {
|
||||||
|
|
||||||
private final static Logger logger = LoggerFactory
|
private final static Logger logger = LoggerFactory.getLogger(DocumentWritePlatformServiceJpaRepositoryImpl.class);
|
||||||
.getLogger(DocumentWritePlatformServiceJpaRepositoryImpl.class);
|
|
||||||
|
|
||||||
// TODO: Use these services to ensure that the appropriate entities exist,
|
// TODO: Use these services to ensure that the appropriate entities exist,
|
||||||
// are active, check data scope for user etc
|
// are active, check data scope for user etc
|
||||||
private final PlatformSecurityContext context;
|
private final PlatformSecurityContext context;
|
||||||
private final ClientRepository clientRepository;
|
// private final ClientRepository clientRepository;
|
||||||
private final OfficeRepository officeRepository;
|
// private final OfficeRepository officeRepository;
|
||||||
private final LoanRepository loanRepository;
|
// private final LoanRepository loanRepository;
|
||||||
private final StaffRepository staffRepository;
|
// private final StaffRepository staffRepository;
|
||||||
private final DocumentRepository documentRepository;
|
private final DocumentRepository documentRepository;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
public DocumentWritePlatformServiceJpaRepositoryImpl(
|
public DocumentWritePlatformServiceJpaRepositoryImpl(
|
||||||
final PlatformSecurityContext context,
|
final PlatformSecurityContext context,
|
||||||
final ClientRepository clientRepository,
|
// final ClientRepository clientRepository,
|
||||||
final DocumentRepository documentRepository,
|
// final OfficeRepository officeRepository,
|
||||||
final OfficeRepository officeRepository,
|
// final LoanRepository loanRepository,
|
||||||
final LoanRepository loanRepository,
|
// final StaffRepository staffRepository,
|
||||||
final StaffRepository staffRepository) {
|
final DocumentRepository documentRepository) {
|
||||||
this.context = context;
|
this.context = context;
|
||||||
this.clientRepository = clientRepository;
|
// this.clientRepository = clientRepository;
|
||||||
|
// this.officeRepository = officeRepository;
|
||||||
|
// this.loanRepository = loanRepository;
|
||||||
|
// this.staffRepository = staffRepository;
|
||||||
this.documentRepository = documentRepository;
|
this.documentRepository = documentRepository;
|
||||||
this.officeRepository = officeRepository;
|
|
||||||
this.loanRepository = loanRepository;
|
|
||||||
this.staffRepository = staffRepository;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Transactional
|
@Transactional
|
||||||
@Override
|
@Override
|
||||||
public Long createDocument(DocumentCommand documentCommand,
|
public Long createDocument(final DocumentCommand documentCommand, final InputStream inputStream) {
|
||||||
InputStream inputStream) {
|
|
||||||
try {
|
try {
|
||||||
DocumentCommandValidator validator = new DocumentCommandValidator(
|
context.authenticatedUser();
|
||||||
documentCommand);
|
|
||||||
|
DocumentCommandValidator validator = new DocumentCommandValidator(documentCommand);
|
||||||
|
|
||||||
validateParentEntityType(documentCommand);
|
validateParentEntityType(documentCommand);
|
||||||
|
|
||||||
@@ -105,12 +100,12 @@ public class DocumentWritePlatformServiceJpaRepositoryImpl implements
|
|||||||
|
|
||||||
@Transactional
|
@Transactional
|
||||||
@Override
|
@Override
|
||||||
public EntityIdentifier updateDocument(DocumentCommand documentCommand,
|
public EntityIdentifier updateDocument(final DocumentCommand documentCommand, final InputStream inputStream) {
|
||||||
InputStream inputStream) {
|
|
||||||
try {
|
try {
|
||||||
|
context.authenticatedUser();
|
||||||
|
|
||||||
String oldLocation = null;
|
String oldLocation = null;
|
||||||
DocumentCommandValidator validator = new DocumentCommandValidator(
|
DocumentCommandValidator validator = new DocumentCommandValidator(documentCommand);
|
||||||
documentCommand);
|
|
||||||
validator.validateForUpdate();
|
validator.validateForUpdate();
|
||||||
// TODO check if entity id is valid and within data scope for the
|
// TODO check if entity id is valid and within data scope for the
|
||||||
// user
|
// user
|
||||||
@@ -164,11 +159,12 @@ public class DocumentWritePlatformServiceJpaRepositoryImpl implements
|
|||||||
|
|
||||||
@Transactional
|
@Transactional
|
||||||
@Override
|
@Override
|
||||||
public EntityIdentifier deleteDocument(DocumentCommand documentCommand) {
|
public EntityIdentifier deleteDocument(final DocumentCommand documentCommand) {
|
||||||
|
context.authenticatedUser();
|
||||||
|
|
||||||
validateParentEntityType(documentCommand);
|
validateParentEntityType(documentCommand);
|
||||||
// TODO: Check document is present under this entity Id
|
// TODO: Check document is present under this entity Id
|
||||||
Document document = this.documentRepository.findOne(documentCommand
|
Document document = this.documentRepository.findOne(documentCommand.getId());
|
||||||
.getId());
|
|
||||||
if (document == null) {
|
if (document == null) {
|
||||||
throw new DocumentNotFoundException(
|
throw new DocumentNotFoundException(
|
||||||
documentCommand.getParentEntityType(),
|
documentCommand.getParentEntityType(),
|
||||||
|
|||||||
Reference in New Issue
Block a user