drop audit fields for office tables, update api-docs, update DDL and schemas.
This commit is contained in:
@@ -1613,13 +1613,15 @@ Request Body:
|
||||
{
|
||||
"name": "Example New Branch",
|
||||
"dateFormat": "dd MMMM yyyy",
|
||||
"locale": "en",
|
||||
"openingDate": "01 July 2007",
|
||||
"parentId": 2,
|
||||
"externalId": "SYS54-88"
|
||||
}
|
||||
</code>
|
||||
<code class="method-response">{
|
||||
"resourceId": 9
|
||||
"officeId": 3,
|
||||
"resourceId": 3
|
||||
}
|
||||
</code>
|
||||
</div>
|
||||
@@ -1640,7 +1642,10 @@ Request Body:
|
||||
}
|
||||
</code>
|
||||
<code class="method-response">{
|
||||
"resourceId": 1
|
||||
"officeId": 3,
|
||||
"resourceId": 3,
|
||||
"changes": {
|
||||
"name": "Name is updated"
|
||||
}
|
||||
</code>
|
||||
</div>
|
||||
|
||||
@@ -165,10 +165,6 @@ CREATE TABLE `m_office` (
|
||||
`external_id` varchar(100) DEFAULT NULL,
|
||||
`name` varchar(50) 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`),
|
||||
UNIQUE KEY `name_org` (`name`),
|
||||
UNIQUE KEY `externalid_org` (`external_id`),
|
||||
@@ -185,10 +181,6 @@ CREATE TABLE `m_office_transaction` (
|
||||
`transaction_amount` decimal(19,6) NOT NULL,
|
||||
`transaction_date` date NOT 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`),
|
||||
KEY `FK1E37728B93C6C1B6` (`to_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`;
|
||||
+11
-9
@@ -1,10 +1,8 @@
|
||||
package org.mifosplatform.organisation.office.api;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
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.service.CommandWrapperBuilder;
|
||||
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.data.CommandProcessingResult;
|
||||
import org.mifosplatform.infrastructure.core.serialization.ApiRequestJsonSerializationSettings;
|
||||
import org.mifosplatform.infrastructure.core.serialization.DefaultToApiJsonSerializer;
|
||||
import org.mifosplatform.infrastructure.security.service.PlatformSecurityContext;
|
||||
import org.mifosplatform.organisation.office.data.OfficeData;
|
||||
import org.mifosplatform.organisation.office.data.OfficeLookup;
|
||||
import org.mifosplatform.organisation.office.service.OfficeReadPlatformService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.Scope;
|
||||
@@ -40,7 +36,8 @@ import org.springframework.stereotype.Component;
|
||||
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",
|
||||
"openingDate", "hierarchy", "parentId", "parentName", "allowedParents"));
|
||||
@@ -87,7 +84,7 @@ public class OfficesApiResource {
|
||||
|
||||
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);
|
||||
|
||||
final ApiRequestJsonSerializationSettings settings = apiRequestParameterHelper.process(uriInfo.getQueryParameters());
|
||||
@@ -99,7 +96,9 @@ public class OfficesApiResource {
|
||||
@Produces({ MediaType.APPLICATION_JSON })
|
||||
public String createOffice(final String apiRequestBodyAsJson) {
|
||||
|
||||
final CommandWrapper commandRequest = new CommandWrapperBuilder().createOffice().withJson(apiRequestBodyAsJson)
|
||||
final CommandWrapper commandRequest = new CommandWrapperBuilder() //
|
||||
.createOffice() //
|
||||
.withJson(apiRequestBodyAsJson) //
|
||||
.build();
|
||||
|
||||
final CommandProcessingResult result = this.commandsSourceWritePlatformService.logCommandSource(commandRequest);
|
||||
@@ -119,7 +118,7 @@ public class OfficesApiResource {
|
||||
|
||||
OfficeData office = this.readPlatformService.retrieveOffice(officeId);
|
||||
if (settings.isTemplate()) {
|
||||
List<OfficeLookup> allowedParents = this.readPlatformService.retrieveAllowedParents(officeId);
|
||||
Collection<OfficeData> allowedParents = this.readPlatformService.retrieveAllowedParents(officeId);
|
||||
office = OfficeData.appendedTemplate(office, allowedParents);
|
||||
}
|
||||
|
||||
@@ -132,7 +131,10 @@ public class OfficesApiResource {
|
||||
@Produces({ MediaType.APPLICATION_JSON })
|
||||
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);
|
||||
|
||||
|
||||
-73
@@ -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); }
|
||||
}
|
||||
}
|
||||
+9
-5
@@ -1,5 +1,6 @@
|
||||
package org.mifosplatform.organisation.office.data;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
import org.joda.time.LocalDate;
|
||||
@@ -17,25 +18,24 @@ public class OfficeData {
|
||||
private final String hierarchy;
|
||||
private final Long parentId;
|
||||
private final String parentName;
|
||||
|
||||
@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) {
|
||||
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);
|
||||
}
|
||||
|
||||
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,
|
||||
office.parentId, office.parentName, allowedParents);
|
||||
}
|
||||
|
||||
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.name = name;
|
||||
this.nameDecorated = nameDecorated;
|
||||
@@ -46,4 +46,8 @@ public class OfficeData {
|
||||
this.parentId = parentId;
|
||||
this.allowedParents = allowedParents;
|
||||
}
|
||||
|
||||
public boolean hasIdentifyOf(final Long officeId) {
|
||||
return this.id.equals(officeId);
|
||||
}
|
||||
}
|
||||
+5
-8
@@ -20,15 +20,14 @@ import javax.persistence.UniqueConstraint;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.joda.time.LocalDate;
|
||||
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.RootOfficeParentCannotBeUpdated;
|
||||
import org.mifosplatform.useradministration.domain.AppUser;
|
||||
import org.springframework.data.jpa.domain.AbstractPersistable;
|
||||
|
||||
@Entity
|
||||
@Table(name = "m_office", uniqueConstraints = { @UniqueConstraint(columnNames = { "name" }, name = "name_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)
|
||||
@JoinColumn(name = "parent_id")
|
||||
@@ -101,11 +100,9 @@ public class Office extends AbstractAuditableCustom<AppUser, Long> {
|
||||
final String localeAsInput = command.locale();
|
||||
|
||||
final String parentIdParamName = "parentId";
|
||||
|
||||
if (command.parameterExists(parentIdParamName) && this.parent == null) {
|
||||
throw new RootOfficeParentCannotBeUpdated();
|
||||
}
|
||||
|
||||
|
||||
if (command.parameterExists(parentIdParamName) && this.parent == null) { throw new RootOfficeParentCannotBeUpdated(); }
|
||||
|
||||
if (this.parent != null && command.isChangeInLongParameterNamed(parentIdParamName, this.parent.getId())) {
|
||||
final Long newValue = command.longValueOfParameterNamed(parentIdParamName);
|
||||
actualChanges.put(parentIdParamName, newValue);
|
||||
|
||||
+68
-14
@@ -1,18 +1,20 @@
|
||||
package org.mifosplatform.organisation.office.serialization;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
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.serialization.AbstractFromApiJsonDeserializer;
|
||||
import org.mifosplatform.infrastructure.core.serialization.FromApiJsonDeserializer;
|
||||
import org.mifosplatform.infrastructure.core.exception.PlatformApiDataValidationException;
|
||||
import org.mifosplatform.infrastructure.core.serialization.FromJsonHelper;
|
||||
import org.mifosplatform.organisation.office.command.OfficeCommand;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@@ -20,11 +22,10 @@ import com.google.gson.JsonElement;
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
|
||||
/**
|
||||
* Implementation of {@link FromApiJsonDeserializer} for {@link OfficeCommand}
|
||||
* 's.
|
||||
* Deserializer of JSON for office API.
|
||||
*/
|
||||
@Component
|
||||
public final class OfficeCommandFromApiJsonDeserializer extends AbstractFromApiJsonDeserializer<OfficeCommand> {
|
||||
public final class OfficeCommandFromApiJsonDeserializer {
|
||||
|
||||
/**
|
||||
* The parameters supported for this command.
|
||||
@@ -39,19 +40,72 @@ public final class OfficeCommandFromApiJsonDeserializer extends AbstractFromApiJ
|
||||
this.fromApiJsonHelper = fromApiJsonHelper;
|
||||
}
|
||||
|
||||
@Override
|
||||
public OfficeCommand commandFromApiJson(final String json) {
|
||||
public void validateForCreate(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 JsonElement element = fromApiJsonHelper.parse(json);
|
||||
final String name = fromApiJsonHelper.extractStringNamed("name", element);
|
||||
final String externalId = fromApiJsonHelper.extractStringNamed("externalId", element);
|
||||
final Long parentId = fromApiJsonHelper.extractLongNamed("parentId", element);
|
||||
final LocalDate openingLocalDate = fromApiJsonHelper.extractLocalDateNamed("openingDate", element);
|
||||
final List<ApiParameterError> dataValidationErrors = new ArrayList<ApiParameterError>();
|
||||
final DataValidatorBuilder baseDataValidator = new DataValidatorBuilder(dataValidationErrors).resource("office");
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
+6
-3
@@ -1,7 +1,6 @@
|
||||
package org.mifosplatform.organisation.office.service;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
import org.mifosplatform.organisation.office.data.OfficeData;
|
||||
import org.mifosplatform.organisation.office.data.OfficeLookup;
|
||||
@@ -12,14 +11,18 @@ public interface OfficeReadPlatformService {
|
||||
Collection<OfficeData> retrieveAllOffices();
|
||||
|
||||
Collection<OfficeData> retrieveAllOfficesForDropdown();
|
||||
|
||||
|
||||
/*
|
||||
* Deprecated so cane eventually remove need for OfficeLookup type - so use
|
||||
* retrieveAllOfficesForDropdown instead.
|
||||
*/
|
||||
Collection<OfficeLookup> retrieveAllOfficesForLookup();
|
||||
|
||||
OfficeData retrieveOffice(Long officeId);
|
||||
|
||||
OfficeData retrieveNewOfficeTemplate();
|
||||
|
||||
List<OfficeLookup> retrieveAllowedParents(Long officeId);
|
||||
Collection<OfficeData> retrieveAllowedParents(Long officeId);
|
||||
|
||||
Collection<OfficeTransactionData> retrieveAllOfficeTransactions();
|
||||
|
||||
|
||||
+14
-19
@@ -52,17 +52,16 @@ public class OfficeReadPlatformServiceImpl implements OfficeReadPlatformService
|
||||
@Override
|
||||
public OfficeData mapRow(final ResultSet rs, @SuppressWarnings("unused") final int rowNum) throws SQLException {
|
||||
|
||||
Long id = rs.getLong("id");
|
||||
String name = rs.getString("name");
|
||||
String nameDecorated = rs.getString("nameDecorated");
|
||||
String externalId = rs.getString("externalId");
|
||||
LocalDate openingDate = JdbcSupport.getLocalDate(rs, "openingDate");
|
||||
String hierarchy = rs.getString("hierarchy");
|
||||
Long parentId = JdbcSupport.getLong(rs, "parentId");
|
||||
String parentName = rs.getString("parentName");
|
||||
final Long id = rs.getLong("id");
|
||||
final String name = rs.getString("name");
|
||||
final String nameDecorated = rs.getString("nameDecorated");
|
||||
final String externalId = rs.getString("externalId");
|
||||
final LocalDate openingDate = JdbcSupport.getLocalDate(rs, "openingDate");
|
||||
final String hierarchy = rs.getString("hierarchy");
|
||||
final Long parentId = JdbcSupport.getLong(rs, "parentId");
|
||||
final String parentName = rs.getString("parentName");
|
||||
|
||||
List<OfficeLookup> allowedParents = new ArrayList<OfficeLookup>();
|
||||
return new OfficeData(id, name, nameDecorated, externalId, openingDate, hierarchy, parentId, parentName, allowedParents);
|
||||
return new OfficeData(id, name, nameDecorated, externalId, openingDate, hierarchy, parentId, parentName, null);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -202,22 +201,19 @@ public class OfficeReadPlatformServiceImpl implements OfficeReadPlatformService
|
||||
|
||||
context.authenticatedUser();
|
||||
|
||||
List<OfficeLookup> parentLookups = new ArrayList<OfficeLookup>();
|
||||
|
||||
return OfficeData.template(parentLookups, new LocalDate());
|
||||
return OfficeData.template(null, new LocalDate());
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<OfficeLookup> retrieveAllowedParents(final Long officeId) {
|
||||
public Collection<OfficeData> retrieveAllowedParents(final Long officeId) {
|
||||
|
||||
context.authenticatedUser();
|
||||
List<OfficeLookup> filterParentLookups = new ArrayList<OfficeLookup>();
|
||||
Collection<OfficeData> filterParentLookups = new ArrayList<OfficeData>();
|
||||
|
||||
if (isNotHeadOffice(officeId)) {
|
||||
List<OfficeLookup> parentLookups = new ArrayList<OfficeLookup>(retrieveAllOfficesForLookup());
|
||||
|
||||
for (OfficeLookup office : parentLookups) {
|
||||
Collection<OfficeData> parentLookups = retrieveAllOfficesForDropdown();
|
||||
|
||||
for (OfficeData office : parentLookups) {
|
||||
if (!office.hasIdentifyOf(officeId)) {
|
||||
filterParentLookups.add(office);
|
||||
}
|
||||
@@ -225,7 +221,6 @@ public class OfficeReadPlatformServiceImpl implements OfficeReadPlatformService
|
||||
}
|
||||
|
||||
return filterParentLookups;
|
||||
|
||||
}
|
||||
|
||||
private boolean isNotHeadOffice(final Long officeId) {
|
||||
|
||||
+13
-7
@@ -14,7 +14,6 @@ import org.mifosplatform.organisation.monetary.domain.MonetaryCurrency;
|
||||
import org.mifosplatform.organisation.monetary.domain.Money;
|
||||
import org.mifosplatform.organisation.monetary.exception.CurrencyNotFoundException;
|
||||
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.OfficeRepository;
|
||||
import org.mifosplatform.organisation.office.domain.OfficeTransaction;
|
||||
@@ -63,11 +62,14 @@ public class OfficeWritePlatformServiceJpaRepositoryImpl implements OfficeWriteP
|
||||
try {
|
||||
final AppUser currentUser = context.authenticatedUser();
|
||||
|
||||
final OfficeCommand officeCommand = this.fromApiJsonDeserializer.commandFromApiJson(command.json());
|
||||
officeCommand.validateForCreate();
|
||||
this.fromApiJsonDeserializer.validateForCreate(command.json());
|
||||
|
||||
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);
|
||||
|
||||
// pre save to generate id for use in office hierarchy
|
||||
@@ -92,15 +94,19 @@ public class OfficeWritePlatformServiceJpaRepositoryImpl implements OfficeWriteP
|
||||
try {
|
||||
final AppUser currentUser = context.authenticatedUser();
|
||||
|
||||
final OfficeCommand officeCommand = this.fromApiJsonDeserializer.commandFromApiJson(command.json());
|
||||
officeCommand.validateForUpdate();
|
||||
this.fromApiJsonDeserializer.validateForUpdate(command.json());
|
||||
|
||||
Long parentId = null;
|
||||
if (command.parameterExists("parentId")) {
|
||||
parentId = command.longValueOfParameterNamed("parentId");
|
||||
}
|
||||
|
||||
final Office office = validateUserPriviledgeOnOfficeAndRetrieve(currentUser, officeId);
|
||||
|
||||
final Map<String, Object> changes = office.update(command);
|
||||
|
||||
if (changes.containsKey("parentId")) {
|
||||
final Office parent = validateUserPriviledgeOnOfficeAndRetrieve(currentUser, officeCommand.getParentId());
|
||||
final Office parent = validateUserPriviledgeOnOfficeAndRetrieve(currentUser, parentId);
|
||||
office.update(parent);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user