use of com.runwaysdk.query.Condition in project geoprism-registry by terraframe.
the class MasterListVersion method buildQueryConditionsFromFilter.
private Map<MdAttributeConcreteDAOIF, Condition> buildQueryConditionsFromFilter(String filterJson, String ignoreAttribute, ComponentQuery query, MdBusinessDAOIF mdBusiness) {
Map<MdAttributeConcreteDAOIF, Condition> conditionMap = new HashMap<MdAttributeConcreteDAOIF, Condition>();
if (filterJson != null && filterJson.length() > 0) {
DateFormat filterFormat = new SimpleDateFormat(GeoObjectImportConfiguration.DATE_FORMAT);
filterFormat.setTimeZone(GeoRegistryUtil.SYSTEM_TIMEZONE);
JsonArray filters = JsonParser.parseString(filterJson).getAsJsonArray();
for (int i = 0; i < filters.size(); i++) {
JsonObject filter = filters.get(i).getAsJsonObject();
String attribute = filter.get("attribute").getAsString();
if (ignoreAttribute == null || !attribute.equals(ignoreAttribute)) {
MdAttributeConcreteDAOIF mdAttr = mdBusiness.definesAttribute(attribute);
BasicCondition condition = null;
if (mdAttr instanceof MdAttributeMomentDAOIF) {
JsonObject jObject = filter.get("value").getAsJsonObject();
try {
if (jObject.has("start") && !jObject.get("start").isJsonNull()) {
String date = jObject.get("start").getAsString();
if (date.length() > 0) {
condition = query.aDateTime(attribute).GE(filterFormat.parse(date));
}
}
if (jObject.has("end") && !jObject.get("end").isJsonNull()) {
String date = jObject.get("end").getAsString();
if (date.length() > 0) {
condition = query.aDateTime(attribute).LE(filterFormat.parse(date));
}
}
} catch (ParseException e) {
throw new ProgrammingErrorException(e);
}
} else if (mdAttr instanceof MdAttributeBooleanDAOIF) {
String value = filter.get("value").getAsString();
Boolean bVal = Boolean.valueOf(value);
condition = ((AttributeBoolean) query.get(attribute)).EQ(bVal);
} else {
String value = filter.get("value").getAsString();
condition = query.get(attribute).EQ(value);
}
if (condition != null) {
if (conditionMap.containsKey(mdAttr)) {
conditionMap.put(mdAttr, conditionMap.get(mdAttr).OR(condition));
} else {
conditionMap.put(mdAttr, condition);
}
}
}
}
}
return conditionMap;
}
use of com.runwaysdk.query.Condition in project geoprism-registry by terraframe.
the class ETLService method filterHistoryQueryBasedOnPermissions.
public void filterHistoryQueryBasedOnPermissions(ImportHistoryQuery ihq) {
List<String> raOrgs = new ArrayList<String>();
List<String> rmGeoObjects = new ArrayList<String>();
Condition cond = null;
SingleActorDAOIF actor = Session.getCurrentSession().getUser();
for (RoleDAOIF role : actor.authorizedRoles()) {
String roleName = role.getRoleName();
if (RegistryRole.Type.isOrgRole(roleName) && !RegistryRole.Type.isRootOrgRole(roleName)) {
if (RegistryRole.Type.isRA_Role(roleName)) {
String roleOrgCode = RegistryRole.Type.parseOrgCode(roleName);
raOrgs.add(roleOrgCode);
} else if (RegistryRole.Type.isRM_Role(roleName)) {
rmGeoObjects.add(roleName);
}
}
}
if (!new RolePermissionService().isSRA() && raOrgs.size() == 0 && rmGeoObjects.size() == 0) {
throw new ProgrammingErrorException("This endpoint must be invoked by an RA or RM");
}
for (String orgCode : raOrgs) {
Organization org = Organization.getByCode(orgCode);
Condition loopCond = ihq.getOrganization().EQ(org);
if (cond == null) {
cond = loopCond;
} else {
cond = cond.OR(loopCond);
}
}
for (String roleName : rmGeoObjects) {
String roleOrgCode = RegistryRole.Type.parseOrgCode(roleName);
Organization org = Organization.getByCode(roleOrgCode);
String gotCode = RegistryRole.Type.parseGotCode(roleName);
Condition loopCond = ihq.getGeoObjectTypeCode().EQ(gotCode).AND(ihq.getOrganization().EQ(org));
if (cond == null) {
cond = loopCond;
} else {
cond = cond.OR(loopCond);
}
// If they have permission to an abstract parent type, then they also have
// permission to all its children.
Optional<ServerGeoObjectType> op = ServiceFactory.getMetadataCache().getGeoObjectType(gotCode);
if (op.isPresent() && op.get().getIsAbstract()) {
List<ServerGeoObjectType> subTypes = op.get().getSubtypes();
for (ServerGeoObjectType subType : subTypes) {
Condition superCond = ihq.getGeoObjectTypeCode().EQ(subType.getCode()).AND(ihq.getOrganization().EQ(subType.getOrganization()));
cond = cond.OR(superCond);
}
}
}
if (cond != null) {
ihq.AND(cond);
}
}
use of com.runwaysdk.query.Condition in project geoprism-registry by terraframe.
the class ChangeRequestService method filterQueryBasedOnPermissions.
public void filterQueryBasedOnPermissions(ChangeRequestQuery crq) {
List<String> raOrgs = new ArrayList<String>();
List<String> goRoles = new ArrayList<String>();
Condition cond = null;
SingleActorDAOIF actor = Session.getCurrentSession().getUser();
for (RoleDAOIF role : actor.authorizedRoles()) {
String roleName = role.getRoleName();
if (RegistryRole.Type.isOrgRole(roleName) && !RegistryRole.Type.isRootOrgRole(roleName)) {
if (RegistryRole.Type.isRA_Role(roleName)) {
String roleOrgCode = RegistryRole.Type.parseOrgCode(roleName);
raOrgs.add(roleOrgCode);
} else if (RegistryRole.Type.isRM_Role(roleName) || RegistryRole.Type.isRC_Role(roleName) || RegistryRole.Type.isAC_Role(roleName)) {
goRoles.add(roleName);
}
}
}
for (String orgCode : raOrgs) {
Organization org = Organization.getByCode(orgCode);
Condition loopCond = crq.getOrganizationCode().EQ(org.getCode());
if (cond == null) {
cond = loopCond;
} else {
cond = cond.OR(loopCond);
}
}
for (String roleName : goRoles) {
String roleOrgCode = RegistryRole.Type.parseOrgCode(roleName);
Organization org = Organization.getByCode(roleOrgCode);
String gotCode = RegistryRole.Type.parseGotCode(roleName);
Condition loopCond = crq.getGeoObjectTypeCode().EQ(gotCode).AND(crq.getOrganizationCode().EQ(org.getCode()));
if (cond == null) {
cond = loopCond;
} else {
cond = cond.OR(loopCond);
}
// If they have permission to an abstract parent type, then they also have
// permission to all its children.
Optional<ServerGeoObjectType> op = ServiceFactory.getMetadataCache().getGeoObjectType(gotCode);
if (op.isPresent() && op.get().getIsAbstract()) {
List<ServerGeoObjectType> subTypes = op.get().getSubtypes();
for (ServerGeoObjectType subType : subTypes) {
Condition superCond = crq.getGeoObjectTypeCode().EQ(subType.getCode()).AND(crq.getOrganizationCode().EQ(subType.getOrganization().getCode()));
cond = cond.OR(superCond);
}
}
}
if (cond != null) {
crq.AND(cond);
}
}
Aggregations