drop audit fields for office tables, update api-docs, update DDL and schemas.

This commit is contained in:
Keith Woodlock
2013-01-26 20:23:22 +00:00
parent 1639fe695e
commit 071f5556f6
13 changed files with 1390 additions and 173 deletions
+7 -2
View File
@@ -1613,13 +1613,15 @@ Request Body:
{ {
"name": "Example New Branch", "name": "Example New Branch",
"dateFormat": "dd MMMM yyyy", "dateFormat": "dd MMMM yyyy",
"locale": "en",
"openingDate": "01 July 2007", "openingDate": "01 July 2007",
"parentId": 2, "parentId": 2,
"externalId": "SYS54-88" "externalId": "SYS54-88"
} }
</code> </code>
<code class="method-response">{ <code class="method-response">{
"resourceId": 9 "officeId": 3,
"resourceId": 3
} }
</code> </code>
</div> </div>
@@ -1640,7 +1642,10 @@ Request Body:
} }
</code> </code>
<code class="method-response">{ <code class="method-response">{
"resourceId": 1 "officeId": 3,
"resourceId": 3,
"changes": {
"name": "Name is updated"
} }
</code> </code>
</div> </div>
@@ -165,10 +165,6 @@ CREATE TABLE `m_office` (
`external_id` varchar(100) DEFAULT NULL, `external_id` varchar(100) DEFAULT NULL,
`name` varchar(50) NOT NULL, `name` varchar(50) NOT NULL,
`opening_date` date NOT NULL, `opening_date` date NOT NULL,
`createdby_id` bigint(20) DEFAULT NULL,
`created_date` datetime DEFAULT NULL,
`lastmodified_date` datetime DEFAULT NULL,
`lastmodifiedby_id` bigint(20) DEFAULT NULL,
PRIMARY KEY (`id`), PRIMARY KEY (`id`),
UNIQUE KEY `name_org` (`name`), UNIQUE KEY `name_org` (`name`),
UNIQUE KEY `externalid_org` (`external_id`), UNIQUE KEY `externalid_org` (`external_id`),
@@ -185,10 +181,6 @@ CREATE TABLE `m_office_transaction` (
`transaction_amount` decimal(19,6) NOT NULL, `transaction_amount` decimal(19,6) NOT NULL,
`transaction_date` date NOT NULL, `transaction_date` date NOT NULL,
`description` varchar(100) DEFAULT NULL, `description` varchar(100) DEFAULT NULL,
`created_date` datetime DEFAULT NULL,
`createdby_id` bigint(20) DEFAULT NULL,
`lastmodified_date` datetime DEFAULT NULL,
`lastmodifiedby_id` bigint(20) DEFAULT NULL,
PRIMARY KEY (`id`), PRIMARY KEY (`id`),
KEY `FK1E37728B93C6C1B6` (`to_office_id`), KEY `FK1E37728B93C6C1B6` (`to_office_id`),
KEY `FK1E37728B783C5C25` (`from_office_id`), KEY `FK1E37728B783C5C25` (`from_office_id`),
File diff suppressed because one or more lines are too long
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,11 @@
ALTER TABLE `m_office`
DROP COLUMN `lastmodifiedby_id` ,
DROP COLUMN `lastmodified_date` ,
DROP COLUMN `created_date`,
DROP COLUMN `createdby_id`;
ALTER TABLE `m_office_transaction`
DROP COLUMN `lastmodifiedby_id` ,
DROP COLUMN `lastmodified_date` ,
DROP COLUMN `created_date`,
DROP COLUMN `createdby_id`;
@@ -1,10 +1,8 @@
package org.mifosplatform.organisation.office.api; package org.mifosplatform.organisation.office.api;
import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collection; import java.util.Collection;
import java.util.HashSet; import java.util.HashSet;
import java.util.List;
import java.util.Set; import java.util.Set;
import javax.ws.rs.Consumes; import javax.ws.rs.Consumes;
@@ -21,14 +19,12 @@ import javax.ws.rs.core.UriInfo;
import org.mifosplatform.commands.domain.CommandWrapper; import org.mifosplatform.commands.domain.CommandWrapper;
import org.mifosplatform.commands.service.CommandWrapperBuilder; import org.mifosplatform.commands.service.CommandWrapperBuilder;
import org.mifosplatform.commands.service.PortfolioCommandSourceWritePlatformService; import org.mifosplatform.commands.service.PortfolioCommandSourceWritePlatformService;
import org.mifosplatform.infrastructure.codes.data.CodeData;
import org.mifosplatform.infrastructure.core.api.ApiRequestParameterHelper; import org.mifosplatform.infrastructure.core.api.ApiRequestParameterHelper;
import org.mifosplatform.infrastructure.core.data.CommandProcessingResult; import org.mifosplatform.infrastructure.core.data.CommandProcessingResult;
import org.mifosplatform.infrastructure.core.serialization.ApiRequestJsonSerializationSettings; import org.mifosplatform.infrastructure.core.serialization.ApiRequestJsonSerializationSettings;
import org.mifosplatform.infrastructure.core.serialization.DefaultToApiJsonSerializer; import org.mifosplatform.infrastructure.core.serialization.DefaultToApiJsonSerializer;
import org.mifosplatform.infrastructure.security.service.PlatformSecurityContext; import org.mifosplatform.infrastructure.security.service.PlatformSecurityContext;
import org.mifosplatform.organisation.office.data.OfficeData; import org.mifosplatform.organisation.office.data.OfficeData;
import org.mifosplatform.organisation.office.data.OfficeLookup;
import org.mifosplatform.organisation.office.service.OfficeReadPlatformService; import org.mifosplatform.organisation.office.service.OfficeReadPlatformService;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope; import org.springframework.context.annotation.Scope;
@@ -40,7 +36,8 @@ import org.springframework.stereotype.Component;
public class OfficesApiResource { public class OfficesApiResource {
/** /**
* The set of parameters that are supported in response for {@link CodeData} * The set of parameters that are supported in response for
* {@link OfficeData}.
*/ */
private final Set<String> RESPONSE_DATA_PARAMETERS = new HashSet<String>(Arrays.asList("id", "name", "nameDecorated", "externalId", private final Set<String> RESPONSE_DATA_PARAMETERS = new HashSet<String>(Arrays.asList("id", "name", "nameDecorated", "externalId",
"openingDate", "hierarchy", "parentId", "parentName", "allowedParents")); "openingDate", "hierarchy", "parentId", "parentName", "allowedParents"));
@@ -87,7 +84,7 @@ public class OfficesApiResource {
OfficeData office = this.readPlatformService.retrieveNewOfficeTemplate(); OfficeData office = this.readPlatformService.retrieveNewOfficeTemplate();
final List<OfficeLookup> allowedParents = new ArrayList<OfficeLookup>(this.readPlatformService.retrieveAllOfficesForLookup()); final Collection<OfficeData> allowedParents = this.readPlatformService.retrieveAllOfficesForDropdown();
office = OfficeData.appendedTemplate(office, allowedParents); office = OfficeData.appendedTemplate(office, allowedParents);
final ApiRequestJsonSerializationSettings settings = apiRequestParameterHelper.process(uriInfo.getQueryParameters()); final ApiRequestJsonSerializationSettings settings = apiRequestParameterHelper.process(uriInfo.getQueryParameters());
@@ -99,7 +96,9 @@ public class OfficesApiResource {
@Produces({ MediaType.APPLICATION_JSON }) @Produces({ MediaType.APPLICATION_JSON })
public String createOffice(final String apiRequestBodyAsJson) { public String createOffice(final String apiRequestBodyAsJson) {
final CommandWrapper commandRequest = new CommandWrapperBuilder().createOffice().withJson(apiRequestBodyAsJson) final CommandWrapper commandRequest = new CommandWrapperBuilder() //
.createOffice() //
.withJson(apiRequestBodyAsJson) //
.build(); .build();
final CommandProcessingResult result = this.commandsSourceWritePlatformService.logCommandSource(commandRequest); final CommandProcessingResult result = this.commandsSourceWritePlatformService.logCommandSource(commandRequest);
@@ -119,7 +118,7 @@ public class OfficesApiResource {
OfficeData office = this.readPlatformService.retrieveOffice(officeId); OfficeData office = this.readPlatformService.retrieveOffice(officeId);
if (settings.isTemplate()) { if (settings.isTemplate()) {
List<OfficeLookup> allowedParents = this.readPlatformService.retrieveAllowedParents(officeId); Collection<OfficeData> allowedParents = this.readPlatformService.retrieveAllowedParents(officeId);
office = OfficeData.appendedTemplate(office, allowedParents); office = OfficeData.appendedTemplate(office, allowedParents);
} }
@@ -132,7 +131,10 @@ public class OfficesApiResource {
@Produces({ MediaType.APPLICATION_JSON }) @Produces({ MediaType.APPLICATION_JSON })
public String updateOffice(@PathParam("officeId") final Long officeId, final String apiRequestBodyAsJson) { public String updateOffice(@PathParam("officeId") final Long officeId, final String apiRequestBodyAsJson) {
final CommandWrapper commandRequest = new CommandWrapperBuilder().updateOffice(officeId).withJson(apiRequestBodyAsJson).build(); final CommandWrapper commandRequest = new CommandWrapperBuilder() //
.updateOffice(officeId) //
.withJson(apiRequestBodyAsJson) //
.build();
final CommandProcessingResult result = this.commandsSourceWritePlatformService.logCommandSource(commandRequest); final CommandProcessingResult result = this.commandsSourceWritePlatformService.logCommandSource(commandRequest);
@@ -1,73 +0,0 @@
package org.mifosplatform.organisation.office.command;
import java.util.ArrayList;
import java.util.List;
import org.joda.time.LocalDate;
import org.mifosplatform.infrastructure.core.data.ApiParameterError;
import org.mifosplatform.infrastructure.core.data.DataValidatorBuilder;
import org.mifosplatform.infrastructure.core.exception.PlatformApiDataValidationException;
/**
* Immutable command for creating or updating details of a office.
*/
public class OfficeCommand {
private final String name;
private final String externalId;
private final LocalDate openingDate;
private final Long parentId;
public OfficeCommand(final String officeName, final String externalId, final Long parentId, final LocalDate openingDate) {
this.name = officeName;
this.externalId = externalId;
this.parentId = parentId;
this.openingDate = openingDate;
}
public String getName() {
return name;
}
public String getExternalId() {
return externalId;
}
public LocalDate getOpeningDate() {
return openingDate;
}
public Long getParentId() {
return parentId;
}
public void validateForCreate() {
List<ApiParameterError> dataValidationErrors = new ArrayList<ApiParameterError>();
DataValidatorBuilder baseDataValidator = new DataValidatorBuilder(dataValidationErrors).resource("office");
baseDataValidator.reset().parameter("name").value(this.name).notBlank();
baseDataValidator.reset().parameter("openingDate").value(this.openingDate).notBlank();
baseDataValidator.reset().parameter("externalId").value(this.externalId).notExceedingLengthOf(100);
baseDataValidator.reset().parameter("parentId").value(this.parentId).notNull().integerGreaterThanZero();
if (!dataValidationErrors.isEmpty()) { throw new PlatformApiDataValidationException("validation.msg.validation.errors.exist",
"Validation errors exist.", dataValidationErrors); }
}
public void validateForUpdate() {
List<ApiParameterError> dataValidationErrors = new ArrayList<ApiParameterError>();
DataValidatorBuilder baseDataValidator = new DataValidatorBuilder(dataValidationErrors).resource("office");
baseDataValidator.reset().parameter("name").value(this.name).ignoreIfNull().notBlank();
baseDataValidator.reset().parameter("openingDate").value(this.openingDate).ignoreIfNull().notBlank();
baseDataValidator.reset().parameter("externalId").value(this.externalId).ignoreIfNull().notExceedingLengthOf(100);
baseDataValidator.reset().parameter("parentId").value(this.parentId).ignoreIfNull().notNull().integerGreaterThanZero();
baseDataValidator.reset().anyOfNotNull(this.name, this.openingDate, this.externalId, this.parentId);
if (!dataValidationErrors.isEmpty()) { throw new PlatformApiDataValidationException("validation.msg.validation.errors.exist",
"Validation errors exist.", dataValidationErrors); }
}
}
@@ -1,5 +1,6 @@
package org.mifosplatform.organisation.office.data; package org.mifosplatform.organisation.office.data;
import java.util.Collection;
import java.util.List; import java.util.List;
import org.joda.time.LocalDate; import org.joda.time.LocalDate;
@@ -17,25 +18,24 @@ public class OfficeData {
private final String hierarchy; private final String hierarchy;
private final Long parentId; private final Long parentId;
private final String parentName; private final String parentName;
@SuppressWarnings("unused") @SuppressWarnings("unused")
private final List<OfficeLookup> allowedParents; private final Collection<OfficeData> allowedParents;
public static OfficeData dropdown(final Long id, final String name, final String nameDecorated) { public static OfficeData dropdown(final Long id, final String name, final String nameDecorated) {
return new OfficeData(id, name, nameDecorated, null, null, null, null, null, null); return new OfficeData(id, name, nameDecorated, null, null, null, null, null, null);
} }
public static OfficeData template(final List<OfficeLookup> parentLookups, final LocalDate defaultOpeningDate) { public static OfficeData template(final List<OfficeData> parentLookups, final LocalDate defaultOpeningDate) {
return new OfficeData(null, null, null, null, defaultOpeningDate, null, null, null, parentLookups); return new OfficeData(null, null, null, null, defaultOpeningDate, null, null, null, parentLookups);
} }
public static OfficeData appendedTemplate(final OfficeData office, final List<OfficeLookup> allowedParents) { public static OfficeData appendedTemplate(final OfficeData office, final Collection<OfficeData> allowedParents) {
return new OfficeData(office.id, office.name, office.nameDecorated, office.externalId, office.openingDate, office.hierarchy, return new OfficeData(office.id, office.name, office.nameDecorated, office.externalId, office.openingDate, office.hierarchy,
office.parentId, office.parentName, allowedParents); office.parentId, office.parentName, allowedParents);
} }
public OfficeData(final Long id, final String name, final String nameDecorated, final String externalId, final LocalDate openingDate, public OfficeData(final Long id, final String name, final String nameDecorated, final String externalId, final LocalDate openingDate,
String hierarchy, final Long parentId, final String parentName, final List<OfficeLookup> allowedParents) { final String hierarchy, final Long parentId, final String parentName, final Collection<OfficeData> allowedParents) {
this.id = id; this.id = id;
this.name = name; this.name = name;
this.nameDecorated = nameDecorated; this.nameDecorated = nameDecorated;
@@ -46,4 +46,8 @@ public class OfficeData {
this.parentId = parentId; this.parentId = parentId;
this.allowedParents = allowedParents; this.allowedParents = allowedParents;
} }
public boolean hasIdentifyOf(final Long officeId) {
return this.id.equals(officeId);
}
} }
@@ -20,15 +20,14 @@ import javax.persistence.UniqueConstraint;
import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.StringUtils;
import org.joda.time.LocalDate; import org.joda.time.LocalDate;
import org.mifosplatform.infrastructure.core.api.JsonCommand; import org.mifosplatform.infrastructure.core.api.JsonCommand;
import org.mifosplatform.infrastructure.core.domain.AbstractAuditableCustom;
import org.mifosplatform.organisation.office.exception.CannotUpdateOfficeWithParentOfficeSameAsSelf; import org.mifosplatform.organisation.office.exception.CannotUpdateOfficeWithParentOfficeSameAsSelf;
import org.mifosplatform.organisation.office.exception.RootOfficeParentCannotBeUpdated; import org.mifosplatform.organisation.office.exception.RootOfficeParentCannotBeUpdated;
import org.mifosplatform.useradministration.domain.AppUser; import org.springframework.data.jpa.domain.AbstractPersistable;
@Entity @Entity
@Table(name = "m_office", uniqueConstraints = { @UniqueConstraint(columnNames = { "name" }, name = "name_org"), @Table(name = "m_office", uniqueConstraints = { @UniqueConstraint(columnNames = { "name" }, name = "name_org"),
@UniqueConstraint(columnNames = { "external_id" }, name = "externalid_org") }) @UniqueConstraint(columnNames = { "external_id" }, name = "externalid_org") })
public class Office extends AbstractAuditableCustom<AppUser, Long> { public class Office extends AbstractPersistable<Long> {
@OneToMany(fetch = FetchType.EAGER) @OneToMany(fetch = FetchType.EAGER)
@JoinColumn(name = "parent_id") @JoinColumn(name = "parent_id")
@@ -102,9 +101,7 @@ public class Office extends AbstractAuditableCustom<AppUser, Long> {
final String parentIdParamName = "parentId"; final String parentIdParamName = "parentId";
if (command.parameterExists(parentIdParamName) && this.parent == null) { if (command.parameterExists(parentIdParamName) && this.parent == null) { throw new RootOfficeParentCannotBeUpdated(); }
throw new RootOfficeParentCannotBeUpdated();
}
if (this.parent != null && command.isChangeInLongParameterNamed(parentIdParamName, this.parent.getId())) { if (this.parent != null && command.isChangeInLongParameterNamed(parentIdParamName, this.parent.getId())) {
final Long newValue = command.longValueOfParameterNamed(parentIdParamName); final Long newValue = command.longValueOfParameterNamed(parentIdParamName);
@@ -1,18 +1,20 @@
package org.mifosplatform.organisation.office.serialization; package org.mifosplatform.organisation.office.serialization;
import java.lang.reflect.Type; import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.HashSet; import java.util.HashSet;
import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.StringUtils;
import org.joda.time.LocalDate; import org.joda.time.LocalDate;
import org.mifosplatform.infrastructure.core.data.ApiParameterError;
import org.mifosplatform.infrastructure.core.data.DataValidatorBuilder;
import org.mifosplatform.infrastructure.core.exception.InvalidJsonException; import org.mifosplatform.infrastructure.core.exception.InvalidJsonException;
import org.mifosplatform.infrastructure.core.serialization.AbstractFromApiJsonDeserializer; import org.mifosplatform.infrastructure.core.exception.PlatformApiDataValidationException;
import org.mifosplatform.infrastructure.core.serialization.FromApiJsonDeserializer;
import org.mifosplatform.infrastructure.core.serialization.FromJsonHelper; import org.mifosplatform.infrastructure.core.serialization.FromJsonHelper;
import org.mifosplatform.organisation.office.command.OfficeCommand;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
@@ -20,11 +22,10 @@ import com.google.gson.JsonElement;
import com.google.gson.reflect.TypeToken; import com.google.gson.reflect.TypeToken;
/** /**
* Implementation of {@link FromApiJsonDeserializer} for {@link OfficeCommand} * Deserializer of JSON for office API.
* 's.
*/ */
@Component @Component
public final class OfficeCommandFromApiJsonDeserializer extends AbstractFromApiJsonDeserializer<OfficeCommand> { public final class OfficeCommandFromApiJsonDeserializer {
/** /**
* The parameters supported for this command. * The parameters supported for this command.
@@ -39,19 +40,72 @@ public final class OfficeCommandFromApiJsonDeserializer extends AbstractFromApiJ
this.fromApiJsonHelper = fromApiJsonHelper; this.fromApiJsonHelper = fromApiJsonHelper;
} }
@Override public void validateForCreate(final String json) {
public OfficeCommand commandFromApiJson(final String json) {
if (StringUtils.isBlank(json)) { throw new InvalidJsonException(); } if (StringUtils.isBlank(json)) { throw new InvalidJsonException(); }
final Type typeOfMap = new TypeToken<Map<String, Object>>() {}.getType(); final Type typeOfMap = new TypeToken<Map<String, Object>>() {}.getType();
fromApiJsonHelper.checkForUnsupportedParameters(typeOfMap, json, supportedParameters); fromApiJsonHelper.checkForUnsupportedParameters(typeOfMap, json, supportedParameters);
final JsonElement element = fromApiJsonHelper.parse(json); final List<ApiParameterError> dataValidationErrors = new ArrayList<ApiParameterError>();
final String name = fromApiJsonHelper.extractStringNamed("name", element); final DataValidatorBuilder baseDataValidator = new DataValidatorBuilder(dataValidationErrors).resource("office");
final String externalId = fromApiJsonHelper.extractStringNamed("externalId", element);
final Long parentId = fromApiJsonHelper.extractLongNamed("parentId", element);
final LocalDate openingLocalDate = fromApiJsonHelper.extractLocalDateNamed("openingDate", element);
return new OfficeCommand(name, externalId, parentId, openingLocalDate); final JsonElement element = fromApiJsonHelper.parse(json);
final String name = fromApiJsonHelper.extractStringNamed("name", element);
baseDataValidator.reset().parameter("name").value(name).notBlank().notExceedingLengthOf(100);
final LocalDate openingDate = fromApiJsonHelper.extractLocalDateNamed("openingDate", element);
baseDataValidator.reset().parameter("openingDate").value(openingDate).notNull();
if (fromApiJsonHelper.parameterExists("externalId", element)) {
final String externalId = fromApiJsonHelper.extractStringNamed("externalId", element);
baseDataValidator.reset().parameter("externalId").value(externalId).notExceedingLengthOf(100);
}
if (fromApiJsonHelper.parameterExists("parentId", element)) {
final Long parentId = fromApiJsonHelper.extractLongNamed("parentId", element);
baseDataValidator.reset().parameter("parentId").value(parentId).notNull().integerGreaterThanZero();
}
throwExceptionIfValidationWarningsExist(dataValidationErrors);
}
private void throwExceptionIfValidationWarningsExist(final List<ApiParameterError> dataValidationErrors) {
if (!dataValidationErrors.isEmpty()) { throw new PlatformApiDataValidationException("validation.msg.validation.errors.exist",
"Validation errors exist.", dataValidationErrors); }
}
public void validateForUpdate(final String json) {
if (StringUtils.isBlank(json)) { throw new InvalidJsonException(); }
final Type typeOfMap = new TypeToken<Map<String, Object>>() {}.getType();
fromApiJsonHelper.checkForUnsupportedParameters(typeOfMap, json, supportedParameters);
final List<ApiParameterError> dataValidationErrors = new ArrayList<ApiParameterError>();
final DataValidatorBuilder baseDataValidator = new DataValidatorBuilder(dataValidationErrors).resource("office");
final JsonElement element = fromApiJsonHelper.parse(json);
if (fromApiJsonHelper.parameterExists("name", element)) {
final String name = fromApiJsonHelper.extractStringNamed("name", element);
baseDataValidator.reset().parameter("name").value(name).notBlank().notExceedingLengthOf(100);
}
if (fromApiJsonHelper.parameterExists("openingDate", element)) {
final LocalDate openingDate = fromApiJsonHelper.extractLocalDateNamed("openingDate", element);
baseDataValidator.reset().parameter("openingDate").value(openingDate).notNull();
}
if (fromApiJsonHelper.parameterExists("externalId", element)) {
final String externalId = fromApiJsonHelper.extractStringNamed("externalId", element);
baseDataValidator.reset().parameter("externalId").value(externalId).notExceedingLengthOf(100);
}
if (fromApiJsonHelper.parameterExists("parentId", element)) {
final Long parentId = fromApiJsonHelper.extractLongNamed("parentId", element);
baseDataValidator.reset().parameter("parentId").value(parentId).notNull().integerGreaterThanZero();
}
throwExceptionIfValidationWarningsExist(dataValidationErrors);
} }
} }
@@ -1,7 +1,6 @@
package org.mifosplatform.organisation.office.service; package org.mifosplatform.organisation.office.service;
import java.util.Collection; import java.util.Collection;
import java.util.List;
import org.mifosplatform.organisation.office.data.OfficeData; import org.mifosplatform.organisation.office.data.OfficeData;
import org.mifosplatform.organisation.office.data.OfficeLookup; import org.mifosplatform.organisation.office.data.OfficeLookup;
@@ -13,13 +12,17 @@ public interface OfficeReadPlatformService {
Collection<OfficeData> retrieveAllOfficesForDropdown(); Collection<OfficeData> retrieveAllOfficesForDropdown();
/*
* Deprecated so cane eventually remove need for OfficeLookup type - so use
* retrieveAllOfficesForDropdown instead.
*/
Collection<OfficeLookup> retrieveAllOfficesForLookup(); Collection<OfficeLookup> retrieveAllOfficesForLookup();
OfficeData retrieveOffice(Long officeId); OfficeData retrieveOffice(Long officeId);
OfficeData retrieveNewOfficeTemplate(); OfficeData retrieveNewOfficeTemplate();
List<OfficeLookup> retrieveAllowedParents(Long officeId); Collection<OfficeData> retrieveAllowedParents(Long officeId);
Collection<OfficeTransactionData> retrieveAllOfficeTransactions(); Collection<OfficeTransactionData> retrieveAllOfficeTransactions();
@@ -52,17 +52,16 @@ public class OfficeReadPlatformServiceImpl implements OfficeReadPlatformService
@Override @Override
public OfficeData mapRow(final ResultSet rs, @SuppressWarnings("unused") final int rowNum) throws SQLException { public OfficeData mapRow(final ResultSet rs, @SuppressWarnings("unused") final int rowNum) throws SQLException {
Long id = rs.getLong("id"); final Long id = rs.getLong("id");
String name = rs.getString("name"); final String name = rs.getString("name");
String nameDecorated = rs.getString("nameDecorated"); final String nameDecorated = rs.getString("nameDecorated");
String externalId = rs.getString("externalId"); final String externalId = rs.getString("externalId");
LocalDate openingDate = JdbcSupport.getLocalDate(rs, "openingDate"); final LocalDate openingDate = JdbcSupport.getLocalDate(rs, "openingDate");
String hierarchy = rs.getString("hierarchy"); final String hierarchy = rs.getString("hierarchy");
Long parentId = JdbcSupport.getLong(rs, "parentId"); final Long parentId = JdbcSupport.getLong(rs, "parentId");
String parentName = rs.getString("parentName"); final String parentName = rs.getString("parentName");
List<OfficeLookup> allowedParents = new ArrayList<OfficeLookup>(); return new OfficeData(id, name, nameDecorated, externalId, openingDate, hierarchy, parentId, parentName, null);
return new OfficeData(id, name, nameDecorated, externalId, openingDate, hierarchy, parentId, parentName, allowedParents);
} }
} }
@@ -202,22 +201,19 @@ public class OfficeReadPlatformServiceImpl implements OfficeReadPlatformService
context.authenticatedUser(); context.authenticatedUser();
List<OfficeLookup> parentLookups = new ArrayList<OfficeLookup>(); return OfficeData.template(null, new LocalDate());
return OfficeData.template(parentLookups, new LocalDate());
} }
@Override @Override
public List<OfficeLookup> retrieveAllowedParents(final Long officeId) { public Collection<OfficeData> retrieveAllowedParents(final Long officeId) {
context.authenticatedUser(); context.authenticatedUser();
List<OfficeLookup> filterParentLookups = new ArrayList<OfficeLookup>(); Collection<OfficeData> filterParentLookups = new ArrayList<OfficeData>();
if (isNotHeadOffice(officeId)) { if (isNotHeadOffice(officeId)) {
List<OfficeLookup> parentLookups = new ArrayList<OfficeLookup>(retrieveAllOfficesForLookup()); Collection<OfficeData> parentLookups = retrieveAllOfficesForDropdown();
for (OfficeLookup office : parentLookups) {
for (OfficeData office : parentLookups) {
if (!office.hasIdentifyOf(officeId)) { if (!office.hasIdentifyOf(officeId)) {
filterParentLookups.add(office); filterParentLookups.add(office);
} }
@@ -225,7 +221,6 @@ public class OfficeReadPlatformServiceImpl implements OfficeReadPlatformService
} }
return filterParentLookups; return filterParentLookups;
} }
private boolean isNotHeadOffice(final Long officeId) { private boolean isNotHeadOffice(final Long officeId) {
@@ -14,7 +14,6 @@ import org.mifosplatform.organisation.monetary.domain.MonetaryCurrency;
import org.mifosplatform.organisation.monetary.domain.Money; import org.mifosplatform.organisation.monetary.domain.Money;
import org.mifosplatform.organisation.monetary.exception.CurrencyNotFoundException; import org.mifosplatform.organisation.monetary.exception.CurrencyNotFoundException;
import org.mifosplatform.organisation.office.command.BranchMoneyTransferCommand; import org.mifosplatform.organisation.office.command.BranchMoneyTransferCommand;
import org.mifosplatform.organisation.office.command.OfficeCommand;
import org.mifosplatform.organisation.office.domain.Office; import org.mifosplatform.organisation.office.domain.Office;
import org.mifosplatform.organisation.office.domain.OfficeRepository; import org.mifosplatform.organisation.office.domain.OfficeRepository;
import org.mifosplatform.organisation.office.domain.OfficeTransaction; import org.mifosplatform.organisation.office.domain.OfficeTransaction;
@@ -63,11 +62,14 @@ public class OfficeWritePlatformServiceJpaRepositoryImpl implements OfficeWriteP
try { try {
final AppUser currentUser = context.authenticatedUser(); final AppUser currentUser = context.authenticatedUser();
final OfficeCommand officeCommand = this.fromApiJsonDeserializer.commandFromApiJson(command.json()); this.fromApiJsonDeserializer.validateForCreate(command.json());
officeCommand.validateForCreate();
final Office parent = validateUserPriviledgeOnOfficeAndRetrieve(currentUser, officeCommand.getParentId()); Long parentId = null;
if (command.parameterExists("parentId")) {
parentId = command.longValueOfParameterNamed("parentId");
}
final Office parent = validateUserPriviledgeOnOfficeAndRetrieve(currentUser, parentId);
final Office office = Office.fromJson(parent, command); final Office office = Office.fromJson(parent, command);
// pre save to generate id for use in office hierarchy // pre save to generate id for use in office hierarchy
@@ -92,15 +94,19 @@ public class OfficeWritePlatformServiceJpaRepositoryImpl implements OfficeWriteP
try { try {
final AppUser currentUser = context.authenticatedUser(); final AppUser currentUser = context.authenticatedUser();
final OfficeCommand officeCommand = this.fromApiJsonDeserializer.commandFromApiJson(command.json()); this.fromApiJsonDeserializer.validateForUpdate(command.json());
officeCommand.validateForUpdate();
Long parentId = null;
if (command.parameterExists("parentId")) {
parentId = command.longValueOfParameterNamed("parentId");
}
final Office office = validateUserPriviledgeOnOfficeAndRetrieve(currentUser, officeId); final Office office = validateUserPriviledgeOnOfficeAndRetrieve(currentUser, officeId);
final Map<String, Object> changes = office.update(command); final Map<String, Object> changes = office.update(command);
if (changes.containsKey("parentId")) { if (changes.containsKey("parentId")) {
final Office parent = validateUserPriviledgeOnOfficeAndRetrieve(currentUser, officeCommand.getParentId()); final Office parent = validateUserPriviledgeOnOfficeAndRetrieve(currentUser, parentId);
office.update(parent); office.update(parent);
} }