Merge pull request #707 from Vishwa1311/MIFOSX845

SQL patch named "V137__added_is_active_column_in_m_staff.sql" has been added and also I have updated the API-docs for Staff.
This commit is contained in:
Vishwas Babu A J
2013-12-29 09:05:36 -08:00
9 changed files with 118 additions and 25 deletions
+65 -1
View File
@@ -11778,14 +11778,77 @@ Request Body:
<p>Allows you to model staff members. At present the key role
of significance is whether this staff member is a loan officer or
not.</p>
<table class=matrixHeading>
<tr class="matrixHeadingBG">
<td><div class="mifosXHeading2">Field Descriptions</div></td>
</tr>
<tr class=alt>
<td>firstname</td>
</tr>
<tr>
<td class=fielddesc>First Name of the new Employee.</td>
</tr>
<tr class=alt>
<td>lastname</td>
</tr>
<tr>
<td class=fielddesc>Last Name of the new Employee.
</td>
</tr>
<tr class=alt>
<td>externalId</td>
</tr>
<tr>
<td class=fielddesc>ID to put an external reference for an Employee.</td>
</tr>
<tr class=alt>
<td>mobileNo</td>
</tr>
<tr>
<td class=fielddesc>Mobile number of an Employee.
</td>
</tr>
<tr class=alt>
<td>isLoanOfficer</td>
</tr>
<tr>
<td class=fielddesc>Indicates whether the employee account is to be created as <b>Loan Officer</b>. If isLoanOfficer=true, then the employee is <b>Loan Officer</b>. If isLoanOfficer=false, then the employee is
<b>not Loan Officer.</b>
</td>
</tr>
<tr class=alt>
<td>isActive</td>
</tr>
<tr>
<td class=fielddesc>Indicates whether the employee account is to be created as <b>Active</b>. If isActive=true, then employee is active. If isActive=false, then employee is inactive.</td>
</tr>
</table>
</div>
</div>
<a id="staff_create" name="staff_create" class="old-syle-anchor">&nbsp;</a>
<div class="method-section">
<div class="method-description">
<h4>Create a staff member</h4>
<p>Creates a staff member.</p>
<table class=matrixHeading>
<tr class="matrixHeadingBG">
<td><div class="mifosXHeading2">Mandatory Fields</div></td>
</tr>
<tr class=alt>
<td>officeId, firstname, lastname</td>
</tr>
</table>
<br/>
<table class=matrixHeading>
<tr class="matrixHeadingBG">
<td><div class="mifosXHeading2">Optional Fields</div></td>
</tr>
<tr class=alt>
<td>isLoanOfficer, isActive</td>
</tr>
</table>
</div>
<div class="method-example">
<code class="method-declaration">
@@ -11801,7 +11864,8 @@ Request Body:
"lastname": "Doe",
"isLoanOfficer": "true",
"externalId": "17H",
"mobileNo": "+353851239876"
"mobileNo": "+353851239876",
"isActive": "true"
}
</code>
<code class="method-response">
@@ -0,0 +1 @@
ALTER TABLE `m_staff` ADD COLUMN `is_active` TINYINT(1) DEFAULT '0' AFTER `organisational_role_parent_staff_id`;
@@ -102,7 +102,6 @@ public class FromJsonHelper {
if (StringUtils.isNotBlank(json)) {
parsedElement = this.parser.parse(json);
}
return parsedElement;
}
@@ -49,7 +49,7 @@ public class StaffApiResource {
* {@link StaffData}.
*/
private final Set<String> RESPONSE_DATA_PARAMETERS = new HashSet<String>(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<OfficeData> allowedOffices = this.officeReadPlatformService.retrieveAllOfficesForDropdown();
staff = StaffData.templateData(staff, allowedOffices);
}
}
return this.toApiJsonSerializer.serialize(settings, staff, this.RESPONSE_DATA_PARAMETERS);
}
@@ -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<OfficeData> allowedOffices;
public static StaffData templateData(final StaffData staff, final Collection<OfficeData> 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<OfficeData> allowedOffices) {
final Collection<OfficeData> 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() {
@@ -51,6 +51,9 @@ public class Staff extends AbstractPersistable<Long> {
@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<Long> {
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<Long> {
}
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<Long> {
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<Long> {
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)) {
@@ -33,7 +33,7 @@ public final class StaffCommandFromApiJsonDeserializer {
* The parameters supported for this command.
*/
private final Set<String> supportedParameters = new HashSet<String>(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);
}
@@ -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 });
}
}
@@ -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.