use of com.runwaysdk.mvc.RestResponse in project geoprism-registry by terraframe.
the class UndirectedGraphController method removeChild.
@Endpoint(url = "remove-target", method = ServletMethod.POST, error = ErrorSerialization.JSON)
public ResponseIF removeChild(ClientRequestIF request, @RequestParamter(name = "sourceCode", required = true) String sourceCode, @RequestParamter(name = "sourceTypeCode", required = true) String sourceTypeCode, @RequestParamter(name = "targetCode", required = true) String targetCode, @RequestParamter(name = "targetTypeCode", required = true) String targetTypeCode, @RequestParamter(name = "undirectedRelationshipCode", required = true) String undirectedRelationshipCode, @RequestParamter(name = "startDate", required = true) String startDateStr, @RequestParamter(name = "endDate", required = true) String endDateStr) {
Date startDate = GeoRegistryUtil.parseDate(startDateStr, true);
Date endDate = GeoRegistryUtil.parseDate(endDateStr, true);
this.service.removeChild(request.getSessionId(), sourceCode, sourceTypeCode, targetCode, targetTypeCode, undirectedRelationshipCode, startDate, endDate);
return new RestResponse();
}
use of com.runwaysdk.mvc.RestResponse in project geoprism-registry by terraframe.
the class AccountServiceControllerTest method newInstanceRolesEmptyOrgNull.
/**
* Test returning all possible roles that can be assigned to a person by
* passing in an empty string for the organizations.
*/
@Test
public void newInstanceRolesEmptyOrgNull() {
RestResponse response = (RestResponse) controller.newInstance(clientRequest, null);
createUserWithRoles(response);
}
use of com.runwaysdk.mvc.RestResponse in project geoprism-registry by terraframe.
the class RegistryAccountController method newInstance.
/**
* Returns all roles associated with the given {@link OrganizationDTO} codes.
* If no codes are provided then return all roles defined in the registry.
*
* @param request
* @param organizationCodes
* comma separated list of {@link OrganizationDTO} codes.
* @return
* @throws JSONException
*/
@Endpoint(method = ServletMethod.POST, error = ErrorSerialization.JSON)
public ResponseIF newInstance(ClientRequestIF request, @RequestParamter(name = "organizationCodes") String organizationCodes) throws JSONException {
String[] orgCodeArray = null;
if (organizationCodes != null) {
JSONArray arr = new JSONArray(organizationCodes);
orgCodeArray = new String[arr.length()];
for (int i = 0; i < arr.length(); i++) {
orgCodeArray[i] = arr.getString(i);
}
} else {
orgCodeArray = new String[0];
}
GeoprismUserDTO user = UserInviteDTO.newUserInst(request);
RegistryRole[] registryRoles = this.accountService.getRolesForOrganization(request.getSessionId(), orgCodeArray);
JsonArray rolesJSONArray = this.createRoleMap(registryRoles);
RestResponse response = new RestResponse();
response.set("user", user);
response.set("roles", new JSONArray(rolesJSONArray.toString()));
return response;
}
use of com.runwaysdk.mvc.RestResponse in project geoprism-registry by terraframe.
the class RegistryController method removeChild.
/**
* Removes a relationship between @parentUid and @childUid.
*
* @pre Both the parent and child have already been persisted / applied
* @post A relationship will not exist between @parent and @child
*
* @returns
*/
@Endpoint(method = ServletMethod.POST, error = ErrorSerialization.JSON, url = RegistryUrls.GEO_OBJECT_REMOVE_CHILD)
public ResponseIF removeChild(ClientRequestIF request, @RequestParamter(name = RegistryUrls.GEO_OBJECT_ADD_CHILD_PARAM_PARENTCODE, required = true) String parentCode, @RequestParamter(name = RegistryUrls.GEO_OBJECT_ADD_CHILD_PARAM_PARENT_TYPE_CODE, required = true) String parentTypeCode, @RequestParamter(name = RegistryUrls.GEO_OBJECT_ADD_CHILD_PARAM_CHILDCODE, required = true) String childCode, @RequestParamter(name = RegistryUrls.GEO_OBJECT_ADD_CHILD_PARAM_CHILD_TYPE_CODE, required = true) String childTypeCode, @RequestParamter(name = RegistryUrls.GEO_OBJECT_ADD_CHILD_PARAM_HIERARCHY_CODE, required = true) String hierarchyRef, @RequestParamter(name = RegistryUrls.GEO_OBJECT_ADD_CHILD_PARAM_START_DATE) String startDateString, @RequestParamter(name = RegistryUrls.GEO_OBJECT_ADD_CHILD_PARAM_END_DATE) String endDateString) {
Date startDate = (startDateString != null && startDateString.length() > 0) ? GeoRegistryUtil.parseDate(startDateString, true) : null;
Date endDate = (endDateString != null && endDateString.length() > 0) ? GeoRegistryUtil.parseDate(endDateString, true) : null;
ServiceFactory.getGeoObjectService().removeChild(request.getSessionId(), parentCode, parentTypeCode, childCode, childTypeCode, hierarchyRef, startDate, endDate);
return new RestResponse();
}
use of com.runwaysdk.mvc.RestResponse in project geoprism-registry by terraframe.
the class AccountServiceControllerTest method createAndApplyUserWithOrgRoles.
/**
* Test returning possible roles that can be assigned to a person for a given
* organization.
*/
@Test
@SuppressWarnings("rawtypes")
public void createAndApplyUserWithOrgRoles() {
// New Instance
RestResponse response = (RestResponse) controller.newInstance(clientRequest, "[" + moiOrg.getCode() + "]");
Pair userPair = (Pair) response.getAttribute("user");
GeoprismUserDTO user = (GeoprismUserDTO) userPair.getFirst();
Pair rolesPair = (Pair) response.getAttribute("roles");
JSONArray roleJSONArray = (JSONArray) rolesPair.getFirst();
JSONObject jsonUser = new JSONObject();
jsonUser.put(GeoprismUserDTO.FIRSTNAME, "John");
jsonUser.put(GeoprismUserDTO.LASTNAME, "Doe");
jsonUser.put(GeoprismUserDTO.USERNAME, "jdoe6");
jsonUser.put(GeoprismUserDTO.EMAIL, "john6@doe.com");
jsonUser.put(GeoprismUserDTO.PASSWORD, "123456");
// user.setFirstName("John");
// user.setLastName("Doe");
// user.setUsername("jdoe6");
// user.setEmail("john6doe.com");
// user.setPassword("123456");
String rmDistrictRole = RegistryRole.Type.getRM_RoleName(moiOrg.getCode(), district.getCode());
String rmVillageRole = RegistryRole.Type.getRM_RoleName(moiOrg.getCode(), village.getCode());
// Apply
response = (RestResponse) controller.apply(clientRequest, jsonUser.toString(), "[" + rmDistrictRole + "," + rmVillageRole + "]");
userPair = (Pair) response.getAttribute("user");
jsonUser = (JSONObject) userPair.getFirst();
// try
// {
Pair rolePair = (Pair) response.getAttribute("roles");
roleJSONArray = (JSONArray) rolePair.getFirst();
Assert.assertEquals(8, roleJSONArray.length());
Set<String> rolesFoundSet = new HashSet<String>();
rolesFoundSet.add(RegistryRole.Type.getRM_RoleName(moiOrg.getCode(), district.getCode()));
rolesFoundSet.add(RegistryRole.Type.getRM_RoleName(moiOrg.getCode(), village.getCode()));
this.assertReturnedRoles(roleJSONArray, rolesFoundSet, true);
rolesFoundSet.add(RegistryRole.Type.getRA_RoleName(moiOrg.getCode()));
rolesFoundSet.add(RegistryRole.Type.getRM_RoleName(moiOrg.getCode(), district.getCode()));
rolesFoundSet.add(RegistryRole.Type.getRC_RoleName(moiOrg.getCode(), district.getCode()));
rolesFoundSet.add(RegistryRole.Type.getAC_RoleName(moiOrg.getCode(), district.getCode()));
rolesFoundSet.add(RegistryRole.Type.getRM_RoleName(moiOrg.getCode(), village.getCode()));
rolesFoundSet.add(RegistryRole.Type.getRC_RoleName(moiOrg.getCode(), village.getCode()));
rolesFoundSet.add(RegistryRole.Type.getAC_RoleName(moiOrg.getCode(), village.getCode()));
this.assertReturnedRoles(roleJSONArray, rolesFoundSet, false);
// Edit
response = (RestResponse) controller.edit(clientRequest, jsonUser.getString("oid"));
userPair = (Pair) response.getAttribute("user");
jsonUser = (JSONObject) userPair.getFirst();
rolesPair = (Pair) response.getAttribute("roles");
roleJSONArray = (JSONArray) rolesPair.getFirst();
Assert.assertEquals(8, roleJSONArray.length());
rolesFoundSet.add(RegistryRole.Type.getRM_RoleName(moiOrg.getCode(), district.getCode()));
rolesFoundSet.add(RegistryRole.Type.getRM_RoleName(moiOrg.getCode(), village.getCode()));
this.assertReturnedRoles(roleJSONArray, rolesFoundSet, true);
rolesFoundSet.add(RegistryRole.Type.getRA_RoleName(moiOrg.getCode()));
rolesFoundSet.add(RegistryRole.Type.getRM_RoleName(moiOrg.getCode(), district.getCode()));
rolesFoundSet.add(RegistryRole.Type.getRC_RoleName(moiOrg.getCode(), district.getCode()));
rolesFoundSet.add(RegistryRole.Type.getAC_RoleName(moiOrg.getCode(), district.getCode()));
rolesFoundSet.add(RegistryRole.Type.getRM_RoleName(moiOrg.getCode(), village.getCode()));
rolesFoundSet.add(RegistryRole.Type.getRC_RoleName(moiOrg.getCode(), village.getCode()));
rolesFoundSet.add(RegistryRole.Type.getAC_RoleName(moiOrg.getCode(), village.getCode()));
this.assertReturnedRoles(roleJSONArray, rolesFoundSet, false);
// Apply to change and roles
// user.put(GeoprismUserDTO.LASTNAME, "Dwayne");
user.setLastName("Dwayne");
String rcVillageRole = RegistryRole.Type.getRC_RoleName(moiOrg.getCode(), village.getCode());
response = (RestResponse) controller.apply(clientRequest, jsonUser.toString(), "[" + rmDistrictRole + "," + rcVillageRole + "]");
userPair = (Pair) response.getAttribute("user");
jsonUser = (JSONObject) userPair.getFirst();
Assert.assertEquals("Dwayne", user.getLastName());
rolePair = (Pair) response.getAttribute("roles");
roleJSONArray = (JSONArray) rolePair.getFirst();
Assert.assertEquals(8, roleJSONArray.length());
rolesFoundSet.add(RegistryRole.Type.getRM_RoleName(moiOrg.getCode(), district.getCode()));
rolesFoundSet.add(RegistryRole.Type.getRC_RoleName(moiOrg.getCode(), village.getCode()));
this.assertReturnedRoles(roleJSONArray, rolesFoundSet, true);
rolesFoundSet = new HashSet<String>();
rolesFoundSet.add(RegistryRole.Type.getRA_RoleName(moiOrg.getCode()));
rolesFoundSet.add(RegistryRole.Type.getRM_RoleName(moiOrg.getCode(), district.getCode()));
rolesFoundSet.add(RegistryRole.Type.getRC_RoleName(moiOrg.getCode(), district.getCode()));
rolesFoundSet.add(RegistryRole.Type.getAC_RoleName(moiOrg.getCode(), district.getCode()));
rolesFoundSet.add(RegistryRole.Type.getRM_RoleName(moiOrg.getCode(), village.getCode()));
rolesFoundSet.add(RegistryRole.Type.getRC_RoleName(moiOrg.getCode(), village.getCode()));
rolesFoundSet.add(RegistryRole.Type.getAC_RoleName(moiOrg.getCode(), village.getCode()));
this.assertReturnedRoles(roleJSONArray, rolesFoundSet, false);
// }
// finally
// {
// controller.remove(clientRequest, user.getOid());
// }
}
Aggregations