removed unused code for now.

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