Search in sources :

Example 6 with RestResponse

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();
}
Also used : RestResponse(com.runwaysdk.mvc.RestResponse) Date(java.util.Date) Endpoint(com.runwaysdk.mvc.Endpoint)

Example 7 with 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);
}
Also used : RestResponse(com.runwaysdk.mvc.RestResponse) Test(org.junit.Test)

Example 8 with RestResponse

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;
}
Also used : JsonArray(com.google.gson.JsonArray) RegistryRole(org.commongeoregistry.adapter.metadata.RegistryRole) RestResponse(com.runwaysdk.mvc.RestResponse) JSONArray(org.json.JSONArray) Endpoint(com.runwaysdk.mvc.Endpoint) GeoprismUserDTO(net.geoprism.GeoprismUserDTO) Endpoint(com.runwaysdk.mvc.Endpoint)

Example 9 with RestResponse

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();
}
Also used : RestResponse(com.runwaysdk.mvc.RestResponse) Date(java.util.Date) Endpoint(com.runwaysdk.mvc.Endpoint)

Example 10 with 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());
// }
}
Also used : JSONObject(org.json.JSONObject) RestResponse(com.runwaysdk.mvc.RestResponse) JSONArray(org.json.JSONArray) Pair(com.runwaysdk.Pair) GeoprismUserDTO(net.geoprism.GeoprismUserDTO) HashSet(java.util.HashSet) Test(org.junit.Test)

Aggregations

RestResponse (com.runwaysdk.mvc.RestResponse)13 Endpoint (com.runwaysdk.mvc.Endpoint)8 JSONArray (org.json.JSONArray)7 JSONObject (org.json.JSONObject)5 JsonArray (com.google.gson.JsonArray)4 Date (java.util.Date)4 RegistryRole (org.commongeoregistry.adapter.metadata.RegistryRole)4 Test (org.junit.Test)4 Pair (com.runwaysdk.Pair)3 GeoprismUserDTO (net.geoprism.GeoprismUserDTO)3 HashSet (java.util.HashSet)2 InputStream (java.io.InputStream)1