MIFOSX-1737: Center Staff Assignment History
This commit is contained in:
+66
-1
@@ -5,6 +5,8 @@
|
|||||||
*/
|
*/
|
||||||
package org.mifosplatform.integrationtests;
|
package org.mifosplatform.integrationtests;
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertEquals;
|
||||||
|
|
||||||
import java.sql.Timestamp;
|
import java.sql.Timestamp;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
@@ -147,7 +149,7 @@ public class CenterIntegrationTest {
|
|||||||
Assert.assertNotNull(center);
|
Assert.assertNotNull(center);
|
||||||
Assert.assertEquals(newName, center.getName());
|
Assert.assertEquals(newName, center.getName());
|
||||||
Assert.assertEquals(newExternalId, center.getExternalId());
|
Assert.assertEquals(newExternalId, center.getExternalId());
|
||||||
Assert.assertEquals(newStaffId, center.getStaffId());
|
Assert.assertEquals((Integer)newStaffId, center.getStaffId());
|
||||||
Assert.assertArrayEquals(newGroupMembers, center.getGroupMembers());
|
Assert.assertArrayEquals(newGroupMembers, center.getGroupMembers());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -180,4 +182,67 @@ public class CenterIntegrationTest {
|
|||||||
}
|
}
|
||||||
return groupMembers;
|
return groupMembers;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testStaffAssignmentDuringCenterCreation() {
|
||||||
|
|
||||||
|
Integer staffId = StaffHelper.createStaff(this.requestSpec, this.responseSpec);
|
||||||
|
System.out.println("--------------creating first staff with id-------------" + staffId);
|
||||||
|
Assert.assertNotNull(staffId);
|
||||||
|
|
||||||
|
int centerWithStaffId = CenterHelper.createCenterWithStaffId(this.requestSpec, this.responseSpec, staffId);
|
||||||
|
CenterDomain center = CenterHelper.retrieveByID(centerWithStaffId, requestSpec, responseSpec);
|
||||||
|
Assert.assertNotNull(center);
|
||||||
|
Assert.assertTrue(center.getId() == centerWithStaffId);
|
||||||
|
Assert.assertTrue(center.getStaffId() == staffId);
|
||||||
|
Assert.assertTrue(center.isActive() == true);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testAssignStaffToCenter() {
|
||||||
|
Integer staffId = StaffHelper.createStaff(this.requestSpec, this.responseSpec);
|
||||||
|
System.out.println("--------------creating first staff with id-------------" + staffId);
|
||||||
|
Assert.assertNotNull(staffId);
|
||||||
|
|
||||||
|
Integer groupID = CenterHelper.createCenter(this.requestSpec, this.responseSpec);
|
||||||
|
CenterHelper.verifyCenterCreatedOnServer(this.requestSpec, this.responseSpec, groupID);
|
||||||
|
|
||||||
|
HashMap assignStaffToCenterResponseMap = (HashMap) CenterHelper.assignStaff(this.requestSpec, this.responseSpec, groupID.toString(),
|
||||||
|
staffId.longValue());
|
||||||
|
assertEquals("Verify assigned staff id is the same as id sent", assignStaffToCenterResponseMap.get("staffId"), staffId);
|
||||||
|
|
||||||
|
CenterDomain center = CenterHelper.retrieveByID(groupID, requestSpec, responseSpec);
|
||||||
|
Assert.assertNotNull(center);
|
||||||
|
Assert.assertTrue(center.getId() == groupID);
|
||||||
|
Assert.assertTrue(center.getStaffId() == staffId);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testUnassignStaffToCenter() {
|
||||||
|
Integer staffId = StaffHelper.createStaff(this.requestSpec, this.responseSpec);
|
||||||
|
System.out.println("--------------creating first staff with id-------------" + staffId);
|
||||||
|
Assert.assertNotNull(staffId);
|
||||||
|
|
||||||
|
Integer groupID = CenterHelper.createCenter(this.requestSpec, this.responseSpec);
|
||||||
|
CenterHelper.verifyCenterCreatedOnServer(this.requestSpec, this.responseSpec, groupID);
|
||||||
|
|
||||||
|
HashMap assignStaffToCenterResponseMap = (HashMap) CenterHelper.assignStaff(this.requestSpec, this.responseSpec, groupID.toString(),
|
||||||
|
staffId.longValue());
|
||||||
|
assertEquals("Verify assigned staff id is the same as id sent", assignStaffToCenterResponseMap.get("staffId"), staffId);
|
||||||
|
CenterDomain centerWithStaffAssigned = CenterHelper.retrieveByID(groupID, requestSpec, responseSpec);
|
||||||
|
Assert.assertNotNull(centerWithStaffAssigned);
|
||||||
|
Assert.assertTrue(centerWithStaffAssigned.getId() == groupID);
|
||||||
|
Assert.assertTrue(centerWithStaffAssigned.getStaffId() == staffId);
|
||||||
|
|
||||||
|
HashMap unassignStaffToCenterResponseMap = (HashMap) CenterHelper.unassignStaff(this.requestSpec, this.responseSpec, groupID.toString(),
|
||||||
|
staffId.longValue());
|
||||||
|
assertEquals("Verify staffId is null after unassigning ", unassignStaffToCenterResponseMap.get("staffId"), null);
|
||||||
|
CenterDomain centerWithStaffUnssigned = CenterHelper.retrieveByID(groupID, requestSpec, responseSpec);
|
||||||
|
Assert.assertNotNull(centerWithStaffUnssigned);
|
||||||
|
Assert.assertTrue(centerWithStaffUnssigned.getId() == groupID);
|
||||||
|
Assert.assertTrue(centerWithStaffUnssigned.getStaffId() == null);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
+64
-17
@@ -8,25 +8,27 @@ package org.mifosplatform.integrationtests.common;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
|
||||||
|
import org.mifosplatform.infrastructure.core.service.DateUtils;
|
||||||
|
|
||||||
import com.google.gson.Gson;
|
import com.google.gson.Gson;
|
||||||
|
|
||||||
public class CenterDomain implements Comparable<CenterDomain> {
|
public class CenterDomain implements Comparable<CenterDomain> {
|
||||||
|
|
||||||
public static class Builder {
|
public static class Builder {
|
||||||
|
|
||||||
private int id;
|
private Integer id;
|
||||||
private HashMap status;
|
private HashMap status;
|
||||||
private boolean active;
|
private boolean active;
|
||||||
private String name;
|
private String name;
|
||||||
private String externalId;
|
private String externalId;
|
||||||
private int staffId;
|
private Integer staffId;
|
||||||
private int officeId;
|
private Integer officeId;
|
||||||
private String officeName;
|
private String officeName;
|
||||||
private String hierarchy;
|
private String hierarchy;
|
||||||
private ArrayList<HashMap> groupMembers;
|
private ArrayList<HashMap> groupMembers;
|
||||||
|
|
||||||
private Builder(final int id, final int statusid, final String statuscode, final String statusvalue, final boolean active,
|
private Builder(final Integer id, final Integer statusid, final String statuscode, final String statusvalue, final boolean active,
|
||||||
final String name, final String externalId, final int staffId, final int officeID, final String officeName,
|
final String name, final String externalId, final Integer staffId, final int officeID, final String officeName,
|
||||||
final String hierarchy, final ArrayList<HashMap> groupMembers) {
|
final String hierarchy, final ArrayList<HashMap> groupMembers) {
|
||||||
this.id = id;
|
this.id = id;
|
||||||
this.status = new HashMap();
|
this.status = new HashMap();
|
||||||
@@ -48,25 +50,26 @@ public class CenterDomain implements Comparable<CenterDomain> {
|
|||||||
(String) this.status.get("value"), this.active, this.name, this.externalId, this.staffId, this.officeId,
|
(String) this.status.get("value"), this.active, this.name, this.externalId, this.staffId, this.officeId,
|
||||||
this.officeName, this.hierarchy, groupMembers);
|
this.officeName, this.hierarchy, groupMembers);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private int id;
|
private Integer id;
|
||||||
private HashMap status;
|
private HashMap status;
|
||||||
private boolean active;
|
private boolean active;
|
||||||
private String name;
|
private String name;
|
||||||
private String externalId;
|
private String externalId;
|
||||||
private int staffId;
|
private Integer staffId;
|
||||||
private int officeId;
|
private Integer officeId;
|
||||||
private String officeName;
|
private String officeName;
|
||||||
private String hierarchy;
|
private String hierarchy;
|
||||||
private ArrayList<HashMap> groupMembers;
|
private ArrayList<HashMap> groupMembers;
|
||||||
|
|
||||||
CenterDomain() {
|
CenterDomain() {
|
||||||
super();
|
/* super(); */
|
||||||
}
|
}
|
||||||
|
|
||||||
private CenterDomain(final int id, final int statusid, final String statuscode, final String statusvalue, final boolean active,
|
private CenterDomain(final Integer id, final Integer statusid, final String statuscode, final String statusvalue, final boolean active,
|
||||||
final String name, final String externalId, final int staffId, final int officeID, final String officeName,
|
final String name, final String externalId, final Integer staffId, final Integer officeID, final String officeName,
|
||||||
final String hierarchy, final ArrayList<HashMap> groupMembers) {
|
final String hierarchy, final ArrayList<HashMap> groupMembers) {
|
||||||
this.id = id;
|
this.id = id;
|
||||||
this.status = new HashMap();
|
this.status = new HashMap();
|
||||||
@@ -91,22 +94,66 @@ public class CenterDomain implements Comparable<CenterDomain> {
|
|||||||
return new Gson().fromJson(jsonData, CurrencyDomain.class);
|
return new Gson().fromJson(jsonData, CurrencyDomain.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Builder create(final int id, final int statusid, final String statuscode, final String statusvalue, final boolean active,
|
public static Builder create(final Integer id, final Integer statusid, final String statuscode, final String statusvalue,
|
||||||
final String name, final String externalId, final int staffId, final int officeID, final String officeName,
|
final boolean active, final String name, final String externalId, final Integer staffId, final Integer officeID,
|
||||||
final String hierarchy, final ArrayList<HashMap> groupMembers) {
|
final String officeName, final String hierarchy, final ArrayList<HashMap> groupMembers) {
|
||||||
return new Builder(id, statusid, statuscode, statusvalue, active, name, externalId, staffId, officeID, officeName, hierarchy,
|
return new Builder(id, statusid, statuscode, statusvalue, active, name, externalId, staffId, officeID, officeName, hierarchy,
|
||||||
groupMembers);
|
groupMembers);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings({ "rawtypes", "unchecked" })
|
||||||
|
public static String jsonRequestToCreateCenter(Integer id, Integer statusId, String statusCode, String statusValue, Boolean active,
|
||||||
|
String activationDate, String submittedDate, String name, String externalId, Integer staffId, Integer officeID,
|
||||||
|
String officeName, String hierarchy, final int[] groupMembers) {
|
||||||
|
// String ids = String.valueOf(id);
|
||||||
|
final HashMap map = new HashMap<>();
|
||||||
|
if (id != null) map.put("id", id);
|
||||||
|
if (statusId != null) map.put("statusId", statusId);
|
||||||
|
if (statusCode != null) map.put("statusCode", statusCode);
|
||||||
|
if (statusValue != null) map.put("statusValue", statusValue);
|
||||||
|
map.put("officeId", "1");
|
||||||
|
map.put("name", randomNameGenerator("Center_Name_", 5));
|
||||||
|
map.put("externalId", randomIDGenerator("ID_", 7));
|
||||||
|
map.put("dateFormat", "dd MMMM yyyy");
|
||||||
|
map.put("locale", "en");
|
||||||
|
if (staffId != null) {
|
||||||
|
map.put("staffId", String.valueOf(staffId));
|
||||||
|
}
|
||||||
|
if (active) {
|
||||||
|
map.put("active", "true");
|
||||||
|
map.put("locale", "en");
|
||||||
|
map.put("dateFormat", "dd MMM yyyy");
|
||||||
|
map.put("activationDate", activationDate);
|
||||||
|
} else {
|
||||||
|
map.put("active", "false");
|
||||||
|
if (submittedDate == null)
|
||||||
|
map.put("submittedOnDate", DateUtils.getDateOfTenant());
|
||||||
|
else
|
||||||
|
map.put("submittedOnDate", submittedDate);
|
||||||
|
}
|
||||||
|
if (externalId != null) map.put("externalId", externalId);
|
||||||
|
if (groupMembers != null) map.put("groupMembers", groupMembers);
|
||||||
|
System.out.println(map);
|
||||||
|
return new Gson().toJson(map);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String randomNameGenerator(final String prefix, final int lenOfRandomSuffix) {
|
||||||
|
return Utils.randomStringGenerator(prefix, lenOfRandomSuffix);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static String randomIDGenerator(final String prefix, final int lenOfRandomSuffix) {
|
||||||
|
return Utils.randomStringGenerator(prefix, lenOfRandomSuffix, "ABCDEFGHIJKLMNOPQRSTUVWXYZ");
|
||||||
|
}
|
||||||
|
|
||||||
public String getExternalId() {
|
public String getExternalId() {
|
||||||
return this.externalId;
|
return this.externalId;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getStaffId() {
|
public Integer getStaffId() {
|
||||||
return this.staffId;
|
return this.staffId;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getId() {
|
public Integer getId() {
|
||||||
return this.id;
|
return this.id;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -122,7 +169,7 @@ public class CenterDomain implements Comparable<CenterDomain> {
|
|||||||
return this.name;
|
return this.name;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getOfficeId() {
|
public Integer getOfficeId() {
|
||||||
return this.officeId;
|
return this.officeId;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+144
-2
@@ -6,8 +6,9 @@
|
|||||||
package org.mifosplatform.integrationtests.common;
|
package org.mifosplatform.integrationtests.common;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import static org.junit.Assert.assertEquals;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import com.google.common.reflect.TypeToken;
|
import com.google.common.reflect.TypeToken;
|
||||||
import com.google.gson.Gson;
|
import com.google.gson.Gson;
|
||||||
import com.jayway.restassured.specification.RequestSpecification;
|
import com.jayway.restassured.specification.RequestSpecification;
|
||||||
@@ -18,6 +19,9 @@ public class CenterHelper {
|
|||||||
|
|
||||||
private static final String CENTERS_URL = "/mifosng-provider/api/v1/centers";
|
private static final String CENTERS_URL = "/mifosng-provider/api/v1/centers";
|
||||||
|
|
||||||
|
public static final String CREATED_DATE = "29 December 2014";
|
||||||
|
private static final String CREATE_CENTER_URL = "/mifosng-provider/api/v1/centers?" + Utils.TENANT_IDENTIFIER;
|
||||||
|
|
||||||
public static CenterDomain retrieveByID(int id, final RequestSpecification requestSpec, final ResponseSpecification responseSpec) {
|
public static CenterDomain retrieveByID(int id, final RequestSpecification requestSpec, final ResponseSpecification responseSpec) {
|
||||||
final String GET_CENTER_BY_ID_URL = CENTERS_URL + "/" + id + "?associations=groupMembers&" + Utils.TENANT_IDENTIFIER;
|
final String GET_CENTER_BY_ID_URL = CENTERS_URL + "/" + id + "?associations=groupMembers&" + Utils.TENANT_IDENTIFIER;
|
||||||
System.out.println("------------------------ RETRIEVING CENTER AT " + id + "-------------------------");
|
System.out.println("------------------------ RETRIEVING CENTER AT " + id + "-------------------------");
|
||||||
@@ -73,7 +77,7 @@ public class CenterHelper {
|
|||||||
hm.put("dateFormat", "dd MMM yyyy");
|
hm.put("dateFormat", "dd MMM yyyy");
|
||||||
hm.put("activationDate", activationDate);
|
hm.put("activationDate", activationDate);
|
||||||
}
|
}
|
||||||
|
|
||||||
System.out.println("------------------------CREATING CENTER-------------------------");
|
System.out.println("------------------------CREATING CENTER-------------------------");
|
||||||
return Utils.performServerPost(requestSpec, responseSpec, CREATE_CENTER_URL, new Gson().toJson(hm), "resourceId");
|
return Utils.performServerPost(requestSpec, responseSpec, CREATE_CENTER_URL, new Gson().toJson(hm), "resourceId");
|
||||||
}
|
}
|
||||||
@@ -110,4 +114,142 @@ public class CenterHelper {
|
|||||||
Utils.performServerDelete(requestSpec, responseSpec, DELETE_CENTER_URL, "");
|
Utils.performServerDelete(requestSpec, responseSpec, DELETE_CENTER_URL, "");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static Integer createCenter(final RequestSpecification requestSpec, final ResponseSpecification responseSpec,
|
||||||
|
@SuppressWarnings("unused") final boolean active) {
|
||||||
|
System.out.println("---------------------------------CREATING A CENTER---------------------------------------------");
|
||||||
|
return createCenter(requestSpec, responseSpec, "CREATED_DATE");
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Integer createCenter(final RequestSpecification requestSpec, final ResponseSpecification responseSpec,
|
||||||
|
final String activationDate) {
|
||||||
|
System.out.println("---------------------------------CREATING A CENTER---------------------------------------------");
|
||||||
|
return Utils.performServerPost(requestSpec, responseSpec, CREATE_CENTER_URL, getTestCenterAsJSON(true, activationDate), "groupId");
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Integer createCenter(final RequestSpecification requestSpec, final ResponseSpecification responseSpec) {
|
||||||
|
System.out.println("---------------------------------CREATING A CENTER---------------------------------------------");
|
||||||
|
return Utils.performServerPost(requestSpec, responseSpec, CREATE_CENTER_URL, getTestCenterAsJSON(true, CenterHelper.CREATED_DATE),
|
||||||
|
"groupId");
|
||||||
|
}
|
||||||
|
|
||||||
|
public static int createCenterWithStaffId(final RequestSpecification requestSpec, final ResponseSpecification responseSpec,
|
||||||
|
final Integer staffId) {
|
||||||
|
System.out.println("---------------------------------CREATING A CENTER---------------------------------------------");
|
||||||
|
return Utils.performServerPost(requestSpec, responseSpec, CREATE_CENTER_URL,
|
||||||
|
getTestCenterWithStaffAsJSON(true, CenterHelper.CREATED_DATE, staffId), "groupId");
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void verifyCenterCreatedOnServer(final RequestSpecification requestSpec, final ResponseSpecification responseSpec,
|
||||||
|
final Integer generatedCenterID) {
|
||||||
|
System.out.println("------------------------------CHECK CENTER DETAILS------------------------------------\n");
|
||||||
|
final String CENTER_URL = "/mifosng-provider/api/v1/centers/" + generatedCenterID + "?" + Utils.TENANT_IDENTIFIER;
|
||||||
|
final Integer responseCenterID = Utils.performServerGet(requestSpec, responseSpec, CENTER_URL, "id");
|
||||||
|
assertEquals("ERROR IN CREATING THE CENTER", generatedCenterID, responseCenterID);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void verifyCenterActivatedOnServer(final RequestSpecification requestSpec, final ResponseSpecification responseSpec,
|
||||||
|
final Integer generatedCenterID, final boolean generatedCenterStatus) {
|
||||||
|
System.out.println("------------------------------CHECK CENTER STATUS------------------------------------\n");
|
||||||
|
final String CENTER_URL = "/mifosng-provider/api/v1/centers/" + generatedCenterID + "?" + Utils.TENANT_IDENTIFIER;
|
||||||
|
final Boolean responseCenterStatus = Utils.performServerGet(requestSpec, responseSpec, CENTER_URL, "active");
|
||||||
|
assertEquals("ERROR IN ACTIVATING THE CENTER", generatedCenterStatus, responseCenterStatus);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Integer activateCenter(final RequestSpecification requestSpec, final ResponseSpecification responseSpec,
|
||||||
|
final String centerId) {
|
||||||
|
final String CENTER_ASSOCIATE_URL = "/mifosng-provider/api/v1/centers/" + centerId + "?command=activate&" + Utils.TENANT_IDENTIFIER;
|
||||||
|
System.out.println("---------------------------------ACTIVATE A CENTER---------------------------------------------");
|
||||||
|
return Utils.performServerPost(requestSpec, responseSpec, CENTER_ASSOCIATE_URL, activateCenterAsJSON(""), "groupId");
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String getTestCenterWithStaffAsJSON(final boolean active, final String activationDate, final Integer staffId) {
|
||||||
|
|
||||||
|
Integer id = null;
|
||||||
|
Integer statusid = null;
|
||||||
|
String statuscode = null;
|
||||||
|
String statusvalue = null;
|
||||||
|
String name = null;
|
||||||
|
String externalId = null;
|
||||||
|
Integer officeID = null;
|
||||||
|
String officeName = null;
|
||||||
|
String hierarchy = null;
|
||||||
|
int[] groupMembers = null;
|
||||||
|
String submittedDate = null;
|
||||||
|
|
||||||
|
return CenterDomain.jsonRequestToCreateCenter(id, statusid, statuscode, statusvalue, active, activationDate,submittedDate,name,
|
||||||
|
externalId, staffId, officeID, officeName, hierarchy, groupMembers);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String getTestCenterAsJSON(final boolean active, final String activationDate) {
|
||||||
|
|
||||||
|
Integer id = null;
|
||||||
|
Integer statusid = null;
|
||||||
|
String statuscode = null;
|
||||||
|
String statusvalue = null;
|
||||||
|
String name = null;
|
||||||
|
String externalId = null;
|
||||||
|
Integer officeID = null;
|
||||||
|
String officeName = null;
|
||||||
|
Integer staffId = null;
|
||||||
|
String hierarchy = null;
|
||||||
|
final int[] groupMembers = null;
|
||||||
|
String submittedDate = null;
|
||||||
|
|
||||||
|
return CenterDomain.jsonRequestToCreateCenter(id, statusid, statuscode, statusvalue, active, activationDate,submittedDate,name,
|
||||||
|
externalId, staffId, officeID, officeName, hierarchy, groupMembers);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String assignStaffAsJSON(final Long staffId) {
|
||||||
|
final HashMap<String, Object> map = new HashMap<>();
|
||||||
|
map.put("staffId", staffId);
|
||||||
|
System.out.println("map : " + map);
|
||||||
|
return new Gson().toJson(map);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String unassignStaffAsJSON(final Long staffId) {
|
||||||
|
final HashMap<String, Object> map = new HashMap<>();
|
||||||
|
map.put("staffId", staffId);
|
||||||
|
System.out.println("map : " + map);
|
||||||
|
return new Gson().toJson(map);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String activateCenterAsJSON(final String activationDate) {
|
||||||
|
final HashMap<String, String> map = new HashMap<>();
|
||||||
|
map.put("dateFormat", "dd MMMM yyyy");
|
||||||
|
map.put("locale", "en");
|
||||||
|
if (StringUtils.isNotEmpty(activationDate)) {
|
||||||
|
map.put("activationDate", activationDate);
|
||||||
|
} else {
|
||||||
|
map.put("activationDate", "CREATED_DATE");
|
||||||
|
System.out.println("defaulting to fixed date: CREATED_DATE");
|
||||||
|
}
|
||||||
|
System.out.println("map : " + map);
|
||||||
|
return new Gson().toJson(map);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String randomNameGenerator(final String prefix, final int lenOfRandomSuffix) {
|
||||||
|
return Utils.randomStringGenerator(prefix, lenOfRandomSuffix);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static String randomIDGenerator(final String prefix, final int lenOfRandomSuffix) {
|
||||||
|
return Utils.randomStringGenerator(prefix, lenOfRandomSuffix, "ABCDEFGHIJKLMNOPQRSTUVWXYZ");
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Object assignStaff(final RequestSpecification requestSpec, final ResponseSpecification responseSpec,
|
||||||
|
final String groupId, final Long staffId) {
|
||||||
|
final String GROUP_ASSIGN_STAFF_URL = "/mifosng-provider/api/v1/groups/" + groupId + "?" + Utils.TENANT_IDENTIFIER
|
||||||
|
+ "&command=assignStaff";
|
||||||
|
System.out.println("---------------------------------Assign Staff---------------------------------------------");
|
||||||
|
return Utils.performServerPost(requestSpec, responseSpec, GROUP_ASSIGN_STAFF_URL, assignStaffAsJSON(staffId), "changes");
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Object unassignStaff(final RequestSpecification requestSpec, final ResponseSpecification responseSpec,
|
||||||
|
final String groupId, final Long staffId) {
|
||||||
|
final String GROUP_ASSIGN_STAFF_URL = "/mifosng-provider/api/v1/groups/" + groupId + "?" + Utils.TENANT_IDENTIFIER
|
||||||
|
+ "&command=unassignStaff";
|
||||||
|
System.out.println("---------------------------------Unassign Staff---------------------------------------------");
|
||||||
|
return Utils.performServerPost(requestSpec, responseSpec, GROUP_ASSIGN_STAFF_URL, unassignStaffAsJSON(staffId), "changes");
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ import java.util.List;
|
|||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
|
import javax.persistence.CascadeType;
|
||||||
import javax.persistence.Column;
|
import javax.persistence.Column;
|
||||||
import javax.persistence.Entity;
|
import javax.persistence.Entity;
|
||||||
import javax.persistence.FetchType;
|
import javax.persistence.FetchType;
|
||||||
@@ -118,6 +119,9 @@ public final class Group extends AbstractPersistable<Long> {
|
|||||||
@JoinColumn(name = "submittedon_userid", nullable = true)
|
@JoinColumn(name = "submittedon_userid", nullable = true)
|
||||||
private AppUser submittedBy;
|
private AppUser submittedBy;
|
||||||
|
|
||||||
|
@OneToMany(cascade = CascadeType.ALL, mappedBy = "center", orphanRemoval = true)
|
||||||
|
private Set<StaffAssignmentHistory> staffHistory;
|
||||||
|
|
||||||
// JPA default constructor for entity
|
// JPA default constructor for entity
|
||||||
protected Group() {
|
protected Group() {
|
||||||
this.name = null;
|
this.name = null;
|
||||||
@@ -174,6 +178,7 @@ public final class Group extends AbstractPersistable<Long> {
|
|||||||
|
|
||||||
this.submittedOnDate = submittedOnDate.toDate();
|
this.submittedOnDate = submittedOnDate.toDate();
|
||||||
this.submittedBy = currentUser;
|
this.submittedBy = currentUser;
|
||||||
|
this.staffHistory = null;
|
||||||
|
|
||||||
associateClients(clientMembers);
|
associateClients(clientMembers);
|
||||||
|
|
||||||
@@ -372,10 +377,18 @@ public final class Group extends AbstractPersistable<Long> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void updateStaff(final Staff staff) {
|
public void updateStaff(final Staff staff) {
|
||||||
|
if (this.isCenter() && this.isActive()) {
|
||||||
|
LocalDate updatedDate = DateUtils.getLocalDateOfTenant();
|
||||||
|
reassignStaff(staff, updatedDate);
|
||||||
|
}
|
||||||
this.staff = staff;
|
this.staff = staff;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void unassignStaff() {
|
public void unassignStaff() {
|
||||||
|
if (this.isCenter() && this.isActive()) {
|
||||||
|
LocalDate dateOfStaffUnassigned = DateUtils.getLocalDateOfTenant();
|
||||||
|
removeStaff(dateOfStaffUnassigned);
|
||||||
|
}
|
||||||
this.staff = null;
|
this.staff = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -620,4 +633,43 @@ public final class Group extends AbstractPersistable<Long> {
|
|||||||
public Set<Client> getClientMembers() {
|
public Set<Client> getClientMembers() {
|
||||||
return this.clientMembers;
|
return this.clientMembers;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// StaffAssignmentHistory[during center creation]
|
||||||
|
public void caputreStaffHistoryDuringCenterCreation(final Staff newStaff, final LocalDate assignmentDate) {
|
||||||
|
if (this.isCenter() && this.isActive() && staff != null) {
|
||||||
|
this.staff = newStaff;
|
||||||
|
final StaffAssignmentHistory staffAssignmentHistory = StaffAssignmentHistory.createNew(this, this.staff, assignmentDate);
|
||||||
|
if (staffAssignmentHistory != null) {
|
||||||
|
staffHistory = new HashSet<>();
|
||||||
|
this.staffHistory.add(staffAssignmentHistory);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// StaffAssignmentHistory[assign staff]
|
||||||
|
public void reassignStaff(final Staff newStaff, final LocalDate assignmentDate) {
|
||||||
|
this.staff = newStaff;
|
||||||
|
final StaffAssignmentHistory staffAssignmentHistory = StaffAssignmentHistory.createNew(this, this.staff, assignmentDate);
|
||||||
|
this.staffHistory.add(staffAssignmentHistory);
|
||||||
|
}
|
||||||
|
|
||||||
|
// StaffAssignmentHistory[unassign staff]
|
||||||
|
public void removeStaff(final LocalDate unassignDate) {
|
||||||
|
final StaffAssignmentHistory latestHistoryRecord = findLatestIncompleteHistoryRecord();
|
||||||
|
if (latestHistoryRecord != null) {
|
||||||
|
latestHistoryRecord.updateEndDate(unassignDate);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private StaffAssignmentHistory findLatestIncompleteHistoryRecord() {
|
||||||
|
|
||||||
|
StaffAssignmentHistory latestRecordWithNoEndDate = null;
|
||||||
|
for (final StaffAssignmentHistory historyRecord : this.staffHistory) {
|
||||||
|
if (historyRecord.isCurrentRecord()) {
|
||||||
|
latestRecordWithNoEndDate = historyRecord;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return latestRecordWithNoEndDate;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
+80
@@ -0,0 +1,80 @@
|
|||||||
|
/**
|
||||||
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||||
|
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
|
||||||
|
* You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||||
|
*/
|
||||||
|
package org.mifosplatform.portfolio.group.domain;
|
||||||
|
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
|
import javax.persistence.Column;
|
||||||
|
import javax.persistence.Entity;
|
||||||
|
import javax.persistence.JoinColumn;
|
||||||
|
import javax.persistence.ManyToOne;
|
||||||
|
import javax.persistence.Table;
|
||||||
|
import javax.persistence.Temporal;
|
||||||
|
import javax.persistence.TemporalType;
|
||||||
|
import org.joda.time.LocalDate;
|
||||||
|
import org.mifosplatform.infrastructure.core.domain.AbstractAuditableCustom;
|
||||||
|
import org.mifosplatform.organisation.staff.domain.Staff;
|
||||||
|
import org.mifosplatform.useradministration.domain.AppUser;
|
||||||
|
|
||||||
|
@Entity
|
||||||
|
@Table(name = "m_staff_assignment_history")
|
||||||
|
public class StaffAssignmentHistory extends AbstractAuditableCustom<AppUser, Long> {
|
||||||
|
|
||||||
|
@ManyToOne
|
||||||
|
@JoinColumn(name = "centre_id", nullable = true)
|
||||||
|
private Group center;
|
||||||
|
|
||||||
|
@ManyToOne
|
||||||
|
@JoinColumn(name = "staff_id", nullable = true)
|
||||||
|
private Staff staff;
|
||||||
|
|
||||||
|
@Temporal(TemporalType.DATE)
|
||||||
|
@Column(name = "start_date")
|
||||||
|
private Date startDate;
|
||||||
|
|
||||||
|
@Temporal(TemporalType.DATE)
|
||||||
|
@Column(name = "end_date")
|
||||||
|
private Date endDate;
|
||||||
|
|
||||||
|
public static StaffAssignmentHistory createNew(final Group center, final Staff staff, final LocalDate startDate) {
|
||||||
|
return new StaffAssignmentHistory(center, staff, startDate.toDate(), null);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected StaffAssignmentHistory() {
|
||||||
|
//
|
||||||
|
}
|
||||||
|
|
||||||
|
private StaffAssignmentHistory(final Group center, final Staff staff, final Date startDate, final Date endDate) {
|
||||||
|
this.center = center;
|
||||||
|
this.staff = staff;
|
||||||
|
this.startDate = startDate;
|
||||||
|
this.endDate = endDate;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void updateStaff(final Staff staff) {
|
||||||
|
this.staff = staff;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void updateStartDate(final LocalDate startDate) {
|
||||||
|
this.startDate = startDate.toDate();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void updateEndDate(final LocalDate endDate) {
|
||||||
|
this.endDate = endDate.toDate();
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean matchesStartDateOf(final LocalDate matchingDate) {
|
||||||
|
return getStartDate().isEqual(matchingDate);
|
||||||
|
}
|
||||||
|
|
||||||
|
public LocalDate getStartDate() {
|
||||||
|
return new LocalDate(this.startDate);
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isCurrentRecord() {
|
||||||
|
return this.endDate == null;
|
||||||
|
}
|
||||||
|
}
|
||||||
+1
-5
@@ -189,7 +189,7 @@ public class GroupingTypesWritePlatformServiceJpaRepositoryImpl implements Group
|
|||||||
newGroup.generateHierarchy();
|
newGroup.generateHierarchy();
|
||||||
|
|
||||||
this.groupRepository.saveAndFlush(newGroup);
|
this.groupRepository.saveAndFlush(newGroup);
|
||||||
|
newGroup.caputreStaffHistoryDuringCenterCreation(staff, activationDate);
|
||||||
return new CommandProcessingResultBuilder() //
|
return new CommandProcessingResultBuilder() //
|
||||||
.withCommandId(command.commandId()) //
|
.withCommandId(command.commandId()) //
|
||||||
.withOfficeId(groupOffice.getId()) //
|
.withOfficeId(groupOffice.getId()) //
|
||||||
@@ -404,9 +404,7 @@ public class GroupingTypesWritePlatformServiceJpaRepositoryImpl implements Group
|
|||||||
final Map<String, Object> actualChanges = new LinkedHashMap<>(9);
|
final Map<String, Object> actualChanges = new LinkedHashMap<>(9);
|
||||||
|
|
||||||
this.fromApiJsonDeserializer.validateForUnassignStaff(command.json());
|
this.fromApiJsonDeserializer.validateForUnassignStaff(command.json());
|
||||||
|
|
||||||
final Group groupForUpdate = this.groupRepository.findOneWithNotFoundDetection(grouptId);
|
final Group groupForUpdate = this.groupRepository.findOneWithNotFoundDetection(grouptId);
|
||||||
|
|
||||||
final Staff presentStaff = groupForUpdate.getStaff();
|
final Staff presentStaff = groupForUpdate.getStaff();
|
||||||
Long presentStaffId = null;
|
Long presentStaffId = null;
|
||||||
if (presentStaff == null) { throw new GroupHasNoStaffException(grouptId); }
|
if (presentStaff == null) { throw new GroupHasNoStaffException(grouptId); }
|
||||||
@@ -442,7 +440,6 @@ public class GroupingTypesWritePlatformServiceJpaRepositoryImpl implements Group
|
|||||||
|
|
||||||
Staff staff = null;
|
Staff staff = null;
|
||||||
final Long staffId = command.longValueOfParameterNamed(GroupingTypesApiConstants.staffIdParamName);
|
final Long staffId = command.longValueOfParameterNamed(GroupingTypesApiConstants.staffIdParamName);
|
||||||
|
|
||||||
final boolean inheritStaffForClientAccounts = command
|
final boolean inheritStaffForClientAccounts = command
|
||||||
.booleanPrimitiveValueOfParameterNamed(GroupingTypesApiConstants.inheritStaffForClientAccounts);
|
.booleanPrimitiveValueOfParameterNamed(GroupingTypesApiConstants.inheritStaffForClientAccounts);
|
||||||
staff = this.staffRepository.findByOfficeHierarchyWithNotFoundDetection(staffId, groupForUpdate.getOffice().getHierarchy());
|
staff = this.staffRepository.findByOfficeHierarchyWithNotFoundDetection(staffId, groupForUpdate.getOffice().getHierarchy());
|
||||||
@@ -476,7 +473,6 @@ public class GroupingTypesWritePlatformServiceJpaRepositoryImpl implements Group
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
this.groupRepository.saveAndFlush(groupForUpdate);
|
this.groupRepository.saveAndFlush(groupForUpdate);
|
||||||
|
|
||||||
actualChanges.put(GroupingTypesApiConstants.staffIdParamName, staffId);
|
actualChanges.put(GroupingTypesApiConstants.staffIdParamName, staffId);
|
||||||
|
|||||||
Binary file not shown.
@@ -0,0 +1,17 @@
|
|||||||
|
label.detail.center_name=Centers
|
||||||
|
label.detail.staff_id=Staff Id
|
||||||
|
label.detail.staff_name=Staff Name
|
||||||
|
label.detail.from_date=From
|
||||||
|
label.detail.assigned_on=Assigned On
|
||||||
|
label.detail.assigned_by=Assigned By
|
||||||
|
label.detail.unassigned_on=Unassigned On
|
||||||
|
label.detail.unassigned_by=Unassigned By
|
||||||
|
label.detail.to=To
|
||||||
|
label.detail.
|
||||||
|
label.detail.
|
||||||
|
label.detail.
|
||||||
|
label.detail.
|
||||||
|
label.detail.
|
||||||
|
label.detail.
|
||||||
|
label.detail.
|
||||||
|
head=Staff Assignmet History
|
||||||
+22
@@ -0,0 +1,22 @@
|
|||||||
|
CREATE TABLE IF NOT EXISTS `m_staff_assignment_history` (
|
||||||
|
`id` bigint(20) NOT NULL AUTO_INCREMENT,
|
||||||
|
`centre_id` bigint(20) DEFAULT NULL,
|
||||||
|
`staff_id` bigint(20) NOT NULL,
|
||||||
|
`start_date` date NOT NULL,
|
||||||
|
`end_date` date DEFAULT 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`),
|
||||||
|
KEY `FK_m_staff_assignment_history_centre_id_m_group` (`centre_id`),
|
||||||
|
KEY `FK_m_staff_assignment_history_m_staff` (`staff_id`),
|
||||||
|
CONSTRAINT `FK_m_staff_assignment_history_centre_id_m_group` FOREIGN KEY (`centre_id`) REFERENCES `m_group` (`id`),
|
||||||
|
CONSTRAINT `FK_m_staff_assignment_history_m_staff` FOREIGN KEY (`staff_id`) REFERENCES `m_staff` (`id`)
|
||||||
|
)
|
||||||
|
INSERT INTO stretchy_parameter ( parameter_name, parameter_variable, parameter_label, parameter_displayType, parameter_FormatType, parameter_default, special, selectOne, selectAll, parameter_sql, parent_id) VALUES ('selectCenterId', 'centerId', 'Enter Center Id', 'text', 'string', 'n/a', NULL, NULL, NULL, NULL, NULL);
|
||||||
|
INSERT INTO stretchy_report ( report_name, report_type, report_subtype, report_category, report_sql, description, core_report, use_report) VALUES ( 'Staff Assignment History', 'Pentaho', NULL, NULL, NULL, NULL, 0, 1);
|
||||||
|
INSERT INTO stretchy_report_parameter ( report_id, parameter_id, report_parameter_name)
|
||||||
|
VALUES ((select sr.id from stretchy_report sr where sr.report_name='Staff Assignment History'),
|
||||||
|
(select sp.id from stretchy_parameter sp where sp.parameter_name='selectCenterId'),
|
||||||
|
'centerId');
|
||||||
Reference in New Issue
Block a user