Merge pull request #498 from johnw65/externalIds
mifosx-567 externalId updates (this for staff)
This commit is contained in:
+11
-6
@@ -861,7 +861,7 @@
|
|||||||
<tr>
|
<tr>
|
||||||
<td><a href="#staff">Staff</a></td>
|
<td><a href="#staff">Staff</a></td>
|
||||||
<td>staff</td>
|
<td>staff</td>
|
||||||
<td><a href="#staff_create">Create a Staff</a></td>
|
<td><a href="#staff_create">Create a Staff Member</a></td>
|
||||||
<td><a href="#staff_list">List Staff</a></td>
|
<td><a href="#staff_list">List Staff</a></td>
|
||||||
<td></td>
|
<td></td>
|
||||||
<td></td>
|
<td></td>
|
||||||
@@ -10029,7 +10029,8 @@ Request Body:
|
|||||||
"officeId": 1,
|
"officeId": 1,
|
||||||
"firstname": "John",
|
"firstname": "John",
|
||||||
"lastname": "Doe",
|
"lastname": "Doe",
|
||||||
"isLoanOfficer": "true"
|
"isLoanOfficer": "true",
|
||||||
|
"externalId": "17H"
|
||||||
}
|
}
|
||||||
</code>
|
</code>
|
||||||
<code class="method-response">
|
<code class="method-response">
|
||||||
@@ -10062,7 +10063,8 @@ GET https://DomainName/api/v1/staff
|
|||||||
"displayName": "Doe, John",
|
"displayName": "Doe, John",
|
||||||
"officeId": 1,
|
"officeId": 1,
|
||||||
"officeName": "Head Office",
|
"officeName": "Head Office",
|
||||||
"isLoanOfficer": true
|
"isLoanOfficer": true,
|
||||||
|
"externalId": "17H"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
</code>
|
</code>
|
||||||
@@ -10087,7 +10089,8 @@ GET https://DomainName/api/v1/staff
|
|||||||
"displayName": "Doe, John",
|
"displayName": "Doe, John",
|
||||||
"officeId": 1,
|
"officeId": 1,
|
||||||
"officeName": "Head Office",
|
"officeName": "Head Office",
|
||||||
"isLoanOfficer": true
|
"isLoanOfficer": true,
|
||||||
|
"externalId": "17H"
|
||||||
}
|
}
|
||||||
</code>
|
</code>
|
||||||
</div>
|
</div>
|
||||||
@@ -10108,7 +10111,8 @@ PUT staff/1
|
|||||||
Content-Type: application/json
|
Content-Type: application/json
|
||||||
Request Body:
|
Request Body:
|
||||||
{
|
{
|
||||||
"isLoanOfficer": "false"
|
"isLoanOfficer": "false",
|
||||||
|
"externalId": "17Hbb"
|
||||||
}
|
}
|
||||||
</code>
|
</code>
|
||||||
<code class="method-response">
|
<code class="method-response">
|
||||||
@@ -10116,7 +10120,8 @@ Request Body:
|
|||||||
"officeId": 1,
|
"officeId": 1,
|
||||||
"resourceId": 1,
|
"resourceId": 1,
|
||||||
"changes": {
|
"changes": {
|
||||||
"isLoanOfficer": false
|
"isLoanOfficer": false,
|
||||||
|
"externalId": "17Hbb"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
</code>
|
</code>
|
||||||
|
|||||||
+1
-1
@@ -48,7 +48,7 @@ public class StaffApiResource {
|
|||||||
* {@link StaffData}.
|
* {@link StaffData}.
|
||||||
*/
|
*/
|
||||||
private final Set<String> RESPONSE_DATA_PARAMETERS = new HashSet<String>(Arrays.asList("id", "firstname", "lastname", "displayName",
|
private final Set<String> RESPONSE_DATA_PARAMETERS = new HashSet<String>(Arrays.asList("id", "firstname", "lastname", "displayName",
|
||||||
"officeId", "officeName", "loanOfficerFlag", "allowedOffices"));
|
"officeId", "officeName", "loanOfficerFlag", "externalId", "allowedOffices"));
|
||||||
|
|
||||||
private final String resourceNameForPermissions = "STAFF";
|
private final String resourceNameForPermissions = "STAFF";
|
||||||
|
|
||||||
|
|||||||
+7
-5
@@ -21,32 +21,34 @@ public class StaffData {
|
|||||||
private final Long officeId;
|
private final Long officeId;
|
||||||
private final String officeName;
|
private final String officeName;
|
||||||
private final Boolean isLoanOfficer;
|
private final Boolean isLoanOfficer;
|
||||||
|
private final String externalId;
|
||||||
|
|
||||||
@SuppressWarnings("unused")
|
@SuppressWarnings("unused")
|
||||||
private final Collection<OfficeData> allowedOffices;
|
private final Collection<OfficeData> allowedOffices;
|
||||||
|
|
||||||
public static StaffData templateData(final StaffData staff, 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,
|
return new StaffData(staff.id, staff.firstname, staff.lastname, staff.displayName, staff.officeId, staff.officeName,
|
||||||
staff.isLoanOfficer, allowedOffices);
|
staff.isLoanOfficer, staff.externalId, allowedOffices);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static StaffData lookup(final Long id, final String displayName) {
|
public static StaffData lookup(final Long id, final String displayName) {
|
||||||
return new StaffData(id, null, null, displayName, null, null, null, null);
|
return new StaffData(id, null, null, displayName, null, null, null, null, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static StaffData instance(final Long id, final String firstname, final String lastname, final String displayName,
|
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 Long officeId, final String officeName, final Boolean isLoanOfficer, final String externalId) {
|
||||||
return new StaffData(id, firstname, lastname, displayName, officeId, officeName, isLoanOfficer, null);
|
return new StaffData(id, firstname, lastname, displayName, officeId, officeName, isLoanOfficer, externalId, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
private StaffData(final Long id, final String firstname, final String lastname, final String displayName, final Long officeId,
|
private StaffData(final Long id, final String firstname, final String lastname, final String displayName, final Long officeId,
|
||||||
final String officeName, final Boolean isLoanOfficer, final Collection<OfficeData> allowedOffices) {
|
final String officeName, final Boolean isLoanOfficer, final String externalId, final Collection<OfficeData> allowedOffices) {
|
||||||
this.id = id;
|
this.id = id;
|
||||||
this.firstname = firstname;
|
this.firstname = firstname;
|
||||||
this.lastname = lastname;
|
this.lastname = lastname;
|
||||||
this.displayName = displayName;
|
this.displayName = displayName;
|
||||||
this.officeName = officeName;
|
this.officeName = officeName;
|
||||||
this.isLoanOfficer = isLoanOfficer;
|
this.isLoanOfficer = isLoanOfficer;
|
||||||
|
this.externalId = externalId;
|
||||||
this.officeId = officeId;
|
this.officeId = officeId;
|
||||||
this.allowedOffices = allowedOffices;
|
this.allowedOffices = allowedOffices;
|
||||||
}
|
}
|
||||||
|
|||||||
+18
-4
@@ -34,6 +34,9 @@ public class Staff extends AbstractPersistable<Long> {
|
|||||||
@Column(name = "display_name", length = 100)
|
@Column(name = "display_name", length = 100)
|
||||||
private String displayName;
|
private String displayName;
|
||||||
|
|
||||||
|
@Column(name = "external_id", length = 100, nullable = true, unique = true)
|
||||||
|
private String externalId;
|
||||||
|
|
||||||
// Office to which this employee belongs
|
// Office to which this employee belongs
|
||||||
@ManyToOne
|
@ManyToOne
|
||||||
@JoinColumn(name = "office_id", nullable = false)
|
@JoinColumn(name = "office_id", nullable = false)
|
||||||
@@ -58,25 +61,29 @@ public class Staff extends AbstractPersistable<Long> {
|
|||||||
|
|
||||||
final String lastnameParamName = "lastname";
|
final String lastnameParamName = "lastname";
|
||||||
String lastname = command.stringValueOfParameterNamed(lastnameParamName);
|
String lastname = command.stringValueOfParameterNamed(lastnameParamName);
|
||||||
|
|
||||||
|
final String externalIdParamName = "externalId";
|
||||||
|
String externalId = command.stringValueOfParameterNamed(externalIdParamName);
|
||||||
|
|
||||||
final String isLoanOfficerParamName = "isLoanOfficer";
|
final String isLoanOfficerParamName = "isLoanOfficer";
|
||||||
final boolean isLoanOfficer = command.booleanPrimitiveValueOfParameterNamed(isLoanOfficerParamName);
|
final boolean isLoanOfficer = command.booleanPrimitiveValueOfParameterNamed(isLoanOfficerParamName);
|
||||||
|
|
||||||
return new Staff(staffOffice, firstname, lastname, isLoanOfficer);
|
return new Staff(staffOffice, firstname, lastname, externalId, isLoanOfficer);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Staff createNew(final Office staffOffice, final String firstname, final String lastname, final boolean isLoanOfficer) {
|
public static Staff createNew(final Office staffOffice, final String firstname, final String lastname, final String externalId, final boolean isLoanOfficer) {
|
||||||
return new Staff(staffOffice, firstname, lastname, isLoanOfficer);
|
return new Staff(staffOffice, firstname, lastname, externalId, isLoanOfficer);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected Staff() {
|
protected Staff() {
|
||||||
//
|
//
|
||||||
}
|
}
|
||||||
|
|
||||||
private Staff(final Office staffOffice, final String firstname, final String lastname, final boolean isLoanOfficer) {
|
private Staff(final Office staffOffice, final String firstname, final String lastname, final String externalId, final boolean isLoanOfficer) {
|
||||||
this.office = staffOffice;
|
this.office = staffOffice;
|
||||||
this.firstname = StringUtils.defaultIfEmpty(firstname, null);
|
this.firstname = StringUtils.defaultIfEmpty(firstname, null);
|
||||||
this.lastname = StringUtils.defaultIfEmpty(lastname, null);
|
this.lastname = StringUtils.defaultIfEmpty(lastname, null);
|
||||||
|
this.externalId = externalId;
|
||||||
this.loanOfficer = isLoanOfficer;
|
this.loanOfficer = isLoanOfficer;
|
||||||
deriveDisplayName(firstname);
|
deriveDisplayName(firstname);
|
||||||
}
|
}
|
||||||
@@ -125,6 +132,13 @@ public class Staff extends AbstractPersistable<Long> {
|
|||||||
deriveDisplayName(this.firstname);
|
deriveDisplayName(this.firstname);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
final String externalIdParamName = "externalId";
|
||||||
|
if (command.isChangeInStringParameterNamed(externalIdParamName, this.externalId)) {
|
||||||
|
final String newValue = command.stringValueOfParameterNamed(externalIdParamName);
|
||||||
|
actualChanges.put(externalIdParamName, newValue);
|
||||||
|
this.externalId = newValue;
|
||||||
|
}
|
||||||
|
|
||||||
final String isLoanOfficerParamName = "isLoanOfficer";
|
final String isLoanOfficerParamName = "isLoanOfficer";
|
||||||
if (command.isChangeInBooleanParameterNamed(isLoanOfficerParamName, this.loanOfficer)) {
|
if (command.isChangeInBooleanParameterNamed(isLoanOfficerParamName, this.loanOfficer)) {
|
||||||
final boolean newValue = command.booleanPrimitiveValueOfParameterNamed(isLoanOfficerParamName);
|
final boolean newValue = command.booleanPrimitiveValueOfParameterNamed(isLoanOfficerParamName);
|
||||||
|
|||||||
+1
-1
@@ -31,7 +31,7 @@ public final class StaffCommandFromApiJsonDeserializer {
|
|||||||
/**
|
/**
|
||||||
* The parameters supported for this command.
|
* The parameters supported for this command.
|
||||||
*/
|
*/
|
||||||
private final Set<String> supportedParameters = new HashSet<String>(Arrays.asList("firstname", "lastname", "officeId", "isLoanOfficer"));
|
private final Set<String> supportedParameters = new HashSet<String>(Arrays.asList("firstname", "lastname", "officeId", "externalId", "isLoanOfficer"));
|
||||||
|
|
||||||
private final FromJsonHelper fromApiJsonHelper;
|
private final FromJsonHelper fromApiJsonHelper;
|
||||||
|
|
||||||
|
|||||||
+6
-4
@@ -38,7 +38,7 @@ public class StaffReadPlatformServiceImpl implements StaffReadPlatformService {
|
|||||||
|
|
||||||
public String schema() {
|
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,"
|
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 from m_staff s "
|
+ " s.display_name as displayName, s.is_loan_officer as isLoanOfficer, s.external_id as externalId from m_staff s "
|
||||||
+ " join m_office o on o.id = s.office_id";
|
+ " join m_office o on o.id = s.office_id";
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -52,8 +52,9 @@ public class StaffReadPlatformServiceImpl implements StaffReadPlatformService {
|
|||||||
final Long officeId = rs.getLong("officeId");
|
final Long officeId = rs.getLong("officeId");
|
||||||
final boolean isLoanOfficer = rs.getBoolean("isLoanOfficer");
|
final boolean isLoanOfficer = rs.getBoolean("isLoanOfficer");
|
||||||
final String officeName = rs.getString("officeName");
|
final String officeName = rs.getString("officeName");
|
||||||
|
final String externalId = rs.getString("externalId");
|
||||||
|
|
||||||
return StaffData.instance(id, firstname, lastname, displayName, officeId, officeName, isLoanOfficer);
|
return StaffData.instance(id, firstname, lastname, displayName, officeId, officeName, isLoanOfficer, externalId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -64,7 +65,7 @@ public class StaffReadPlatformServiceImpl implements StaffReadPlatformService {
|
|||||||
StringBuilder sqlBuilder = new StringBuilder(200);
|
StringBuilder sqlBuilder = new StringBuilder(200);
|
||||||
sqlBuilder.append("s.id as id, s.office_id as officeId, o.name as officeName,");
|
sqlBuilder.append("s.id as id, s.office_id as officeId, o.name as officeName,");
|
||||||
sqlBuilder.append("s.firstname as firstname, s.lastname as lastname,");
|
sqlBuilder.append("s.firstname as firstname, s.lastname as lastname,");
|
||||||
sqlBuilder.append("s.display_name as displayName, s.is_loan_officer as isLoanOfficer ");
|
sqlBuilder.append("s.display_name as displayName, s.is_loan_officer as isLoanOfficer, s.external_id as externalId ");
|
||||||
sqlBuilder.append("from m_office o ");
|
sqlBuilder.append("from m_office o ");
|
||||||
sqlBuilder.append("join m_office ohierarchy on o.hierarchy like concat(ohierarchy.hierarchy, '%') ");
|
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 ");
|
sqlBuilder.append("join m_staff s on s.office_id = ohierarchy.id ");
|
||||||
@@ -88,8 +89,9 @@ public class StaffReadPlatformServiceImpl implements StaffReadPlatformService {
|
|||||||
final Long officeId = rs.getLong("officeId");
|
final Long officeId = rs.getLong("officeId");
|
||||||
final String officeName = rs.getString("officeName");
|
final String officeName = rs.getString("officeName");
|
||||||
final boolean isLoanOfficer = rs.getBoolean("isLoanOfficer");
|
final boolean isLoanOfficer = rs.getBoolean("isLoanOfficer");
|
||||||
|
final String externalId = rs.getString("externalId");
|
||||||
|
|
||||||
return StaffData.instance(id, firstname, lastname, displayName, officeId, officeName, isLoanOfficer);
|
return StaffData.instance(id, firstname, lastname, displayName, officeId, officeName, isLoanOfficer, externalId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+8
-1
@@ -115,7 +115,14 @@ public class StaffWritePlatformServiceJpaRepositoryImpl implements StaffWritePla
|
|||||||
*/
|
*/
|
||||||
private void handleStaffDataIntegrityIssues(final JsonCommand command, final DataIntegrityViolationException dve) {
|
private void handleStaffDataIntegrityIssues(final JsonCommand command, final DataIntegrityViolationException dve) {
|
||||||
Throwable realCause = dve.getMostSpecificCause();
|
Throwable realCause = dve.getMostSpecificCause();
|
||||||
if (realCause.getMessage().contains("display_name")) {
|
|
||||||
|
if (realCause.getMessage().contains("external_id")) {
|
||||||
|
|
||||||
|
final String externalId = command.stringValueOfParameterNamed("externalId");
|
||||||
|
throw new PlatformDataIntegrityException("error.msg.staff.duplicate.externalId", "Staff with externalId `" + externalId
|
||||||
|
+ "` already exists", "externalId", externalId);
|
||||||
|
}
|
||||||
|
else if (realCause.getMessage().contains("display_name")) {
|
||||||
final String lastname = command.stringValueOfParameterNamed("lastname");
|
final String lastname = command.stringValueOfParameterNamed("lastname");
|
||||||
String displayName = lastname;
|
String displayName = lastname;
|
||||||
if (!StringUtils.isBlank(displayName)) {
|
if (!StringUtils.isBlank(displayName)) {
|
||||||
|
|||||||
Reference in New Issue
Block a user