Search in sources :

Example 6 with Condition

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;
}
Also used : Condition(com.runwaysdk.query.Condition) BasicCondition(com.runwaysdk.query.BasicCondition) MdAttributeBooleanDAOIF(com.runwaysdk.dataaccess.MdAttributeBooleanDAOIF) HashMap(java.util.HashMap) JsonObject(com.google.gson.JsonObject) MdAttributeMultiLineString(com.runwaysdk.system.gis.metadata.MdAttributeMultiLineString) MdAttributeLineString(com.runwaysdk.system.gis.metadata.MdAttributeLineString) MdAttributeMomentDAOIF(com.runwaysdk.dataaccess.MdAttributeMomentDAOIF) MdAttributePoint(com.runwaysdk.system.gis.metadata.MdAttributePoint) MdAttributeMultiPoint(com.runwaysdk.system.gis.metadata.MdAttributeMultiPoint) ProgrammingErrorException(com.runwaysdk.dataaccess.ProgrammingErrorException) JsonArray(com.google.gson.JsonArray) SimpleDateFormat(java.text.SimpleDateFormat) DateFormat(java.text.DateFormat) MdAttributeBoolean(com.runwaysdk.system.metadata.MdAttributeBoolean) AttributeBoolean(com.runwaysdk.query.AttributeBoolean) ParseException(java.text.ParseException) MdAttributeBoolean(com.runwaysdk.system.metadata.MdAttributeBoolean) AttributeBoolean(com.runwaysdk.query.AttributeBoolean) SimpleDateFormat(java.text.SimpleDateFormat) BasicCondition(com.runwaysdk.query.BasicCondition) MdAttributeConcreteDAOIF(com.runwaysdk.dataaccess.MdAttributeConcreteDAOIF)

Example 7 with Condition

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);
    }
}
Also used : Condition(com.runwaysdk.query.Condition) RolePermissionService(net.geoprism.registry.permission.RolePermissionService) Organization(net.geoprism.registry.Organization) ServerGeoObjectType(net.geoprism.registry.model.ServerGeoObjectType) ArrayList(java.util.ArrayList) SingleActorDAOIF(com.runwaysdk.business.rbac.SingleActorDAOIF) RoleDAOIF(com.runwaysdk.business.rbac.RoleDAOIF) ProgrammingErrorException(com.runwaysdk.dataaccess.ProgrammingErrorException)

Example 8 with Condition

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);
    }
}
Also used : Condition(com.runwaysdk.query.Condition) Organization(net.geoprism.registry.Organization) ServerGeoObjectType(net.geoprism.registry.model.ServerGeoObjectType) ArrayList(java.util.ArrayList) SingleActorDAOIF(com.runwaysdk.business.rbac.SingleActorDAOIF) RoleDAOIF(com.runwaysdk.business.rbac.RoleDAOIF)

Aggregations

Condition (com.runwaysdk.query.Condition)8 MdAttributeConcreteDAOIF (com.runwaysdk.dataaccess.MdAttributeConcreteDAOIF)5 BasicCondition (com.runwaysdk.query.BasicCondition)5 JsonObject (com.google.gson.JsonObject)4 ProgrammingErrorException (com.runwaysdk.dataaccess.ProgrammingErrorException)4 QueryFactory (com.runwaysdk.query.QueryFactory)4 JsonArray (com.google.gson.JsonArray)3 BusinessQuery (com.runwaysdk.business.BusinessQuery)3 RoleDAOIF (com.runwaysdk.business.rbac.RoleDAOIF)3 MdBusinessDAOIF (com.runwaysdk.dataaccess.MdBusinessDAOIF)3 DateFormat (java.text.DateFormat)3 SimpleDateFormat (java.text.SimpleDateFormat)3 SingleActorDAOIF (com.runwaysdk.business.rbac.SingleActorDAOIF)2 MdAttributeBooleanDAOIF (com.runwaysdk.dataaccess.MdAttributeBooleanDAOIF)2 MdAttributeMomentDAOIF (com.runwaysdk.dataaccess.MdAttributeMomentDAOIF)2 ValueObject (com.runwaysdk.dataaccess.ValueObject)2 AttributeBoolean (com.runwaysdk.query.AttributeBoolean)2 ValueQuery (com.runwaysdk.query.ValueQuery)2 MdAttributeLineString (com.runwaysdk.system.gis.metadata.MdAttributeLineString)2 MdAttributeMultiLineString (com.runwaysdk.system.gis.metadata.MdAttributeMultiLineString)2