diff --git a/api-docs/apiLive.htm b/api-docs/apiLive.htm index 6e94d6580..99aeff999 100644 --- a/api-docs/apiLive.htm +++ b/api-docs/apiLive.htm @@ -11778,14 +11778,77 @@ Request Body:

Allows you to model staff members. At present the key role of significance is whether this staff member is a loan officer or not.

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Field Descriptions
firstname
First Name of the new Employee.
lastname
Last Name of the new Employee. +
externalId
ID to put an external reference for an Employee.
mobileNo
Mobile number of an Employee. +
isLoanOfficer
Indicates whether the employee account is to be created as Loan Officer. If isLoanOfficer=true, then the employee is Loan Officer. If isLoanOfficer=false, then the employee is + not Loan Officer. +
isActive
Indicates whether the employee account is to be created as Active. If isActive=true, then employee is active. If isActive=false, then employee is inactive.
+  

Create a staff member

Creates a staff member.

+ + + + + + + +
Mandatory Fields
officeId, firstname, lastname
+
+ + + + + + + +
Optional Fields
isLoanOfficer, isActive
@@ -11801,7 +11864,8 @@ Request Body: "lastname": "Doe", "isLoanOfficer": "true", "externalId": "17H", - "mobileNo": "+353851239876" + "mobileNo": "+353851239876", + "isActive": "true" } diff --git a/mifosng-db/migrations/core_db/V137__added_is_active_column_in_m_staff.sql b/mifosng-db/migrations/core_db/V137__added_is_active_column_in_m_staff.sql new file mode 100644 index 000000000..2726e0874 --- /dev/null +++ b/mifosng-db/migrations/core_db/V137__added_is_active_column_in_m_staff.sql @@ -0,0 +1 @@ +ALTER TABLE `m_staff` ADD COLUMN `is_active` TINYINT(1) DEFAULT '0' AFTER `organisational_role_parent_staff_id`; \ No newline at end of file diff --git a/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/core/serialization/FromJsonHelper.java b/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/core/serialization/FromJsonHelper.java index 4d0cc7c58..92f0268d8 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/core/serialization/FromJsonHelper.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/core/serialization/FromJsonHelper.java @@ -102,7 +102,6 @@ public class FromJsonHelper { if (StringUtils.isNotBlank(json)) { parsedElement = this.parser.parse(json); } - return parsedElement; } diff --git a/mifosng-provider/src/main/java/org/mifosplatform/organisation/staff/api/StaffApiResource.java b/mifosng-provider/src/main/java/org/mifosplatform/organisation/staff/api/StaffApiResource.java index 6501b86d8..da1a447db 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/organisation/staff/api/StaffApiResource.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/organisation/staff/api/StaffApiResource.java @@ -49,7 +49,7 @@ public class StaffApiResource { * {@link StaffData}. */ private final Set RESPONSE_DATA_PARAMETERS = new HashSet(Arrays.asList("id", "firstname", "lastname", "displayName", - "officeId", "officeName", "loanOfficerFlag", "externalId", "mobileNo", "allowedOffices")); + "officeId", "officeName", "loanOfficerFlag", "externalId", "mobileNo", "allowedOffices", "isActive")); private final String resourceNameForPermissions = "STAFF"; @@ -120,8 +120,7 @@ public class StaffApiResource { if (settings.isTemplate()) { final Collection allowedOffices = this.officeReadPlatformService.retrieveAllOfficesForDropdown(); staff = StaffData.templateData(staff, allowedOffices); - } - + } return this.toApiJsonSerializer.serialize(settings, staff, this.RESPONSE_DATA_PARAMETERS); } diff --git a/mifosng-provider/src/main/java/org/mifosplatform/organisation/staff/data/StaffData.java b/mifosng-provider/src/main/java/org/mifosplatform/organisation/staff/data/StaffData.java index fb04a8d73..3ffbb3e1a 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/organisation/staff/data/StaffData.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/organisation/staff/data/StaffData.java @@ -16,36 +16,35 @@ public class StaffData { private final Long id; private final String externalId; - private final String firstname; private final String lastname; private final String displayName; private final String mobileNo; - private final Long officeId; private final String officeName; private final Boolean isLoanOfficer; + private final Boolean isActive; @SuppressWarnings("unused") private final Collection allowedOffices; public static StaffData templateData(final StaffData staff, final Collection allowedOffices) { return new StaffData(staff.id, staff.firstname, staff.lastname, staff.displayName, staff.officeId, staff.officeName, - staff.isLoanOfficer, staff.externalId, staff.mobileNo, allowedOffices); + staff.isLoanOfficer, staff.externalId, staff.mobileNo, allowedOffices, staff.isActive); } public static StaffData lookup(final Long id, final String displayName) { - return new StaffData(id, null, null, displayName, null, null, null, null, null, null); + return new StaffData(id, null, null, displayName, null, null, null, null, null, null, null); } public static StaffData instance(final Long id, final String firstname, final String lastname, final String displayName, - final Long officeId, final String officeName, final Boolean isLoanOfficer, final String externalId, final String mobileNo) { - return new StaffData(id, firstname, lastname, displayName, officeId, officeName, isLoanOfficer, externalId, mobileNo, null); + final Long officeId, final String officeName, final Boolean isLoanOfficer, final String externalId, final String mobileNo, final boolean isActive) { + return new StaffData(id, firstname, lastname, displayName, officeId, officeName, isLoanOfficer, externalId, mobileNo, null, isActive); } private StaffData(final Long id, final String firstname, final String lastname, final String displayName, final Long officeId, final String officeName, final Boolean isLoanOfficer, final String externalId, final String mobileNo, - final Collection allowedOffices) { + final Collection allowedOffices, final Boolean isActive) { this.id = id; this.firstname = firstname; this.lastname = lastname; @@ -56,6 +55,7 @@ public class StaffData { this.officeId = officeId; this.mobileNo = mobileNo; this.allowedOffices = allowedOffices; + this.isActive = isActive; } public Long getId() { diff --git a/mifosng-provider/src/main/java/org/mifosplatform/organisation/staff/domain/Staff.java b/mifosng-provider/src/main/java/org/mifosplatform/organisation/staff/domain/Staff.java index bad2cbdbc..9085df388 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/organisation/staff/domain/Staff.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/organisation/staff/domain/Staff.java @@ -51,6 +51,9 @@ public class Staff extends AbstractPersistable { @Column(name = "organisational_role_enum", nullable = true) private Integer organisationalRoleType; + + @Column (name="is_active" , nullable = false) + private boolean active; @ManyToOne @JoinColumn(name = "organisational_role_parent_staff_id", nullable = true) @@ -72,8 +75,11 @@ public class Staff extends AbstractPersistable { final String isLoanOfficerParamName = "isLoanOfficer"; final boolean isLoanOfficer = command.booleanPrimitiveValueOfParameterNamed(isLoanOfficerParamName); + + final String isActiveParamName = "isActive"; + final boolean isActive = command.booleanPrimitiveValueOfParameterNamed(isActiveParamName); - return new Staff(staffOffice, firstname, lastname, externalId, mobileNo, isLoanOfficer); + return new Staff(staffOffice, firstname, lastname, externalId, mobileNo, isLoanOfficer, isActive); } protected Staff() { @@ -81,13 +87,14 @@ public class Staff extends AbstractPersistable { } private Staff(final Office staffOffice, final String firstname, final String lastname, final String externalId, final String mobileNo, - final boolean isLoanOfficer) { + final boolean isLoanOfficer, final Boolean isActive) { this.office = staffOffice; this.firstname = StringUtils.defaultIfEmpty(firstname, null); this.lastname = StringUtils.defaultIfEmpty(lastname, null); this.externalId = StringUtils.defaultIfEmpty(externalId, null); this.mobileNo = StringUtils.defaultIfEmpty(mobileNo, null); this.loanOfficer = isLoanOfficer; + this.active = (isActive == null) ? false : isActive; deriveDisplayName(firstname); } @@ -155,6 +162,13 @@ public class Staff extends AbstractPersistable { actualChanges.put(isLoanOfficerParamName, newValue); this.loanOfficer = newValue; } + + final String isActiveParamName = "isActive"; + if (command.isChangeInBooleanParameterNamed(isActiveParamName, this.active)) { + final boolean newValue = command.booleanPrimitiveValueOfParameterNamed(isActiveParamName); + actualChanges.put(isActiveParamName, newValue); + this.active = newValue; + } return actualChanges; } @@ -166,6 +180,14 @@ public class Staff extends AbstractPersistable { public boolean isLoanOfficer() { return this.loanOfficer; } + + public boolean isNotActive() { + return !isActive(); + } + + public boolean isActive() { + return this.active; + } private void deriveDisplayName(final String firstname) { if (!StringUtils.isBlank(firstname)) { diff --git a/mifosng-provider/src/main/java/org/mifosplatform/organisation/staff/serialization/StaffCommandFromApiJsonDeserializer.java b/mifosng-provider/src/main/java/org/mifosplatform/organisation/staff/serialization/StaffCommandFromApiJsonDeserializer.java index fe6763110..a18cedcba 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/organisation/staff/serialization/StaffCommandFromApiJsonDeserializer.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/organisation/staff/serialization/StaffCommandFromApiJsonDeserializer.java @@ -33,7 +33,7 @@ public final class StaffCommandFromApiJsonDeserializer { * The parameters supported for this command. */ private final Set supportedParameters = new HashSet(Arrays.asList("firstname", "lastname", "officeId", "externalId", - "mobileNo", "isLoanOfficer")); + "mobileNo", "isLoanOfficer", "isActive")); private final FromJsonHelper fromApiJsonHelper; @@ -72,6 +72,11 @@ public final class StaffCommandFromApiJsonDeserializer { final Boolean loanOfficerFlag = this.fromApiJsonHelper.extractBooleanNamed("isLoanOfficer", element); baseDataValidator.reset().parameter("isLoanOfficer").value(loanOfficerFlag).notNull(); } + + if (this.fromApiJsonHelper.parameterExists("isActive", element)) { + final Boolean activeFlag = this.fromApiJsonHelper.extractBooleanNamed("isActive", element); + baseDataValidator.reset().parameter("isActive").value(activeFlag).notNull(); + } throwExceptionIfValidationWarningsExist(dataValidationErrors); } @@ -110,7 +115,12 @@ public final class StaffCommandFromApiJsonDeserializer { final Boolean loanOfficerFlag = this.fromApiJsonHelper.extractBooleanNamed("isLoanOfficer", element); baseDataValidator.reset().parameter("isLoanOfficer").value(loanOfficerFlag).notNull(); } - + + if (this.fromApiJsonHelper.parameterExists("isActive", element)) { + final Boolean activeFlag = this.fromApiJsonHelper.extractBooleanNamed("isActive", element); + baseDataValidator.reset().parameter("isActive").value(activeFlag).notNull(); + } + throwExceptionIfValidationWarningsExist(dataValidationErrors); } diff --git a/mifosng-provider/src/main/java/org/mifosplatform/organisation/staff/service/StaffReadPlatformServiceImpl.java b/mifosng-provider/src/main/java/org/mifosplatform/organisation/staff/service/StaffReadPlatformServiceImpl.java index 9f431abf6..c78f9efa4 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/organisation/staff/service/StaffReadPlatformServiceImpl.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/organisation/staff/service/StaffReadPlatformServiceImpl.java @@ -38,7 +38,7 @@ public class StaffReadPlatformServiceImpl implements StaffReadPlatformService { public String schema() { return " s.id as id,s.office_id as officeId, o.name as officeName, s.firstname as firstname, s.lastname as lastname," - + " s.display_name as displayName, s.is_loan_officer as isLoanOfficer, s.external_id as externalId, s.mobile_no as mobileNo from m_staff s " + + " s.display_name as displayName, s.is_loan_officer as isLoanOfficer, s.external_id as externalId, s.mobile_no as mobileNo, s.is_active as isActive from m_staff s " + " join m_office o on o.id = s.office_id"; } @@ -54,8 +54,9 @@ public class StaffReadPlatformServiceImpl implements StaffReadPlatformService { final String officeName = rs.getString("officeName"); final String externalId = rs.getString("externalId"); final String mobileNo = rs.getString("mobileNo"); + final boolean isActive = rs.getBoolean("isActive"); - return StaffData.instance(id, firstname, lastname, displayName, officeId, officeName, isLoanOfficer, externalId, mobileNo); + return StaffData.instance(id, firstname, lastname, displayName, officeId, officeName, isLoanOfficer, externalId, mobileNo, isActive); } } @@ -64,10 +65,10 @@ public class StaffReadPlatformServiceImpl implements StaffReadPlatformService { public String schema(final boolean loanOfficersOnly) { final StringBuilder sqlBuilder = new StringBuilder(200); + sqlBuilder.append("s.id as id, s.office_id as officeId, ohierarchy.name as officeName,"); sqlBuilder.append("s.firstname as firstname, s.lastname as lastname,"); - sqlBuilder - .append("s.display_name as displayName, s.is_loan_officer as isLoanOfficer, s.external_id as externalId, s.mobile_no as mobileNo "); + sqlBuilder.append("s.display_name as displayName, s.is_loan_officer as isLoanOfficer, s.external_id as externalId, s.mobile_no as mobileNo "); sqlBuilder.append("from m_office o "); sqlBuilder.append("join m_office ohierarchy on o.hierarchy like concat(ohierarchy.hierarchy, '%') "); sqlBuilder.append("join m_staff s on s.office_id = ohierarchy.id "); @@ -93,8 +94,9 @@ public class StaffReadPlatformServiceImpl implements StaffReadPlatformService { final boolean isLoanOfficer = rs.getBoolean("isLoanOfficer"); final String externalId = rs.getString("externalId"); final String mobileNo = rs.getString("mobileNo"); + final boolean isActive = rs.getBoolean("isActive"); - return StaffData.instance(id, firstname, lastname, displayName, officeId, officeName, isLoanOfficer, externalId, mobileNo); + return StaffData.instance(id, firstname, lastname, displayName, officeId, officeName, isLoanOfficer, externalId, mobileNo, isActive); } } @@ -120,7 +122,6 @@ public class StaffReadPlatformServiceImpl implements StaffReadPlatformService { final Long id = rs.getLong("id"); final String displayName = rs.getString("displayName"); - return StaffData.lookup(id, displayName); } } @@ -192,7 +193,6 @@ public class StaffReadPlatformServiceImpl implements StaffReadPlatformService { if (StringUtils.isNotBlank(extraCriteria)) { extraCriteria = extraCriteria.substring(4); } - return extraCriteria; } @@ -201,7 +201,6 @@ public class StaffReadPlatformServiceImpl implements StaffReadPlatformService { String sql = "select " + this.staffInOfficeHierarchyMapper.schema(loanOfficersOnly); sql = sql + " order by s.lastname"; - return this.jdbcTemplate.query(sql, this.staffInOfficeHierarchyMapper, new Object[] { officeId }); } } \ No newline at end of file diff --git a/mifosng-provider/src/main/java/org/mifosplatform/organisation/staff/service/StaffWritePlatformServiceJpaRepositoryImpl.java b/mifosng-provider/src/main/java/org/mifosplatform/organisation/staff/service/StaffWritePlatformServiceJpaRepositoryImpl.java index 5db2ef828..b0d58377f 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/organisation/staff/service/StaffWritePlatformServiceJpaRepositoryImpl.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/organisation/staff/service/StaffWritePlatformServiceJpaRepositoryImpl.java @@ -100,7 +100,6 @@ public class StaffWritePlatformServiceJpaRepositoryImpl implements StaffWritePla return CommandProcessingResult.empty(); } } - /* * Guaranteed to throw an exception no matter what the data integrity issue * is.