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;
}
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;
}
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();
}
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());
// }
}
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;
}
Aggregations