Search in sources :

Example 1 with Pair

use of com.runwaysdk.Pair in project geoprism-registry by terraframe.

the class IntervalListType method getIntervals.

public List<Pair<Date, Date>> getIntervals() {
    List<Pair<Date, Date>> list = new LinkedList<Pair<Date, Date>>();
    JsonArray intervals = JsonParser.parseString(this.getIntervalJson()).getAsJsonArray();
    for (int i = 0; i < intervals.size(); i++) {
        JsonObject interval = intervals.get(i).getAsJsonObject();
        Date startDate = GeoRegistryUtil.parseDate(interval.get(START_DATE).getAsString());
        Date endDate = GeoRegistryUtil.parseDate(interval.get(END_DATE).getAsString());
        list.add(new Pair<Date, Date>(startDate, endDate));
    }
    list.sort(new Comparator<Pair<Date, Date>>() {

        @Override
        public int compare(Pair<Date, Date> o1, Pair<Date, Date> o2) {
            int compareTo = o1.getFirst().compareTo(o2.getFirst());
            if (compareTo == 0) {
                return o1.getSecond().compareTo(o2.getSecond());
            }
            return compareTo;
        }
    });
    return list;
}
Also used : JsonArray(com.google.gson.JsonArray) JsonObject(com.google.gson.JsonObject) LinkedList(java.util.LinkedList) Date(java.util.Date) Pair(com.runwaysdk.Pair)

Example 2 with Pair

use of com.runwaysdk.Pair in project geoprism-registry by terraframe.

the class VertexServerGeoObject method getDataRange.

public static Pair<Date, Date> getDataRange(ServerGeoObjectType type) {
    final String dbClassName = type.getMdVertex().getDBClassName();
    final Date startDate = new GraphQuery<Date>("SELECT MIN(exists_cot.startDate) FROM " + dbClassName).getSingleResult();
    final Date endDate = new GraphQuery<Date>("SELECT MAX(exists_cot.startDate) FROM " + dbClassName).getSingleResult();
    Date current = new Date();
    if (startDate != null && endDate != null) {
        if (endDate.before(current)) {
            return new Pair<Date, Date>(startDate, current);
        }
        return new Pair<Date, Date>(startDate, endDate);
    }
    return null;
}
Also used : MultiLineString(com.vividsolutions.jts.geom.MultiLineString) LineString(com.vividsolutions.jts.geom.LineString) Date(java.util.Date) LocalDate(java.time.LocalDate) Pair(com.runwaysdk.Pair)

Example 3 with Pair

use of com.runwaysdk.Pair in project geoprism-registry by terraframe.

the class IntervalListType method formatVersionLabel.

@Override
protected JsonObject formatVersionLabel(LabeledVersion version) {
    Date versionDate = version.getForDate();
    List<Pair<Date, Date>> intervals = this.getIntervals();
    for (Pair<Date, Date> interval : intervals) {
        Date startDate = interval.getFirst();
        Date endDate = interval.getSecond();
        if (GeoRegistryUtil.isBetweenInclusive(versionDate, startDate, endDate)) {
            JsonObject range = new JsonObject();
            range.addProperty("startDate", GeoRegistryUtil.formatDate(startDate, false));
            range.addProperty("endDate", GeoRegistryUtil.formatDate(endDate, false));
            JsonObject object = new JsonObject();
            object.addProperty("type", "range");
            object.add("value", range);
            return object;
        }
    }
    throw new UnsupportedOperationException();
}
Also used : JsonObject(com.google.gson.JsonObject) Date(java.util.Date) Pair(com.runwaysdk.Pair)

Example 4 with Pair

use of com.runwaysdk.Pair 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)

Example 5 with Pair

use of com.runwaysdk.Pair in project geoprism-registry by terraframe.

the class AccountServiceControllerTest method createUser.

private JSONObject createUser(String userName, String roleNames) {
    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, "Some Firstname");
    jsonUser.put(GeoprismUserDTO.LASTNAME, "Some Lastame");
    jsonUser.put(GeoprismUserDTO.USERNAME, userName);
    jsonUser.put(GeoprismUserDTO.EMAIL, userName);
    jsonUser.put(GeoprismUserDTO.PASSWORD, "123456");
    response = (RestResponse) controller.apply(clientRequest, jsonUser.toString(), "[" + roleNames + "]");
    userPair = (Pair) response.getAttribute("user");
    jsonUser = (JSONObject) userPair.getFirst();
    return jsonUser;
}
Also used : JSONObject(org.json.JSONObject) RestResponse(com.runwaysdk.mvc.RestResponse) JSONArray(org.json.JSONArray) Pair(com.runwaysdk.Pair) GeoprismUserDTO(net.geoprism.GeoprismUserDTO)

Aggregations

Pair (com.runwaysdk.Pair)7 JSONArray (org.json.JSONArray)4 RestResponse (com.runwaysdk.mvc.RestResponse)3 Date (java.util.Date)3 HashSet (java.util.HashSet)3 JsonObject (com.google.gson.JsonObject)2 GeoprismUserDTO (net.geoprism.GeoprismUserDTO)2 JSONObject (org.json.JSONObject)2 Test (org.junit.Test)2 JsonArray (com.google.gson.JsonArray)1 LineString (com.vividsolutions.jts.geom.LineString)1 MultiLineString (com.vividsolutions.jts.geom.MultiLineString)1 LocalDate (java.time.LocalDate)1 LinkedList (java.util.LinkedList)1