Search in sources :

Example 46 with ProgrammingErrorException

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

the class Transition method validate.

public void validate(TransitionEvent event, VertexServerGeoObject source, VertexServerGeoObject target) {
    ServerGeoObjectType beforeType = ServerGeoObjectType.get(event.getBeforeTypeCode());
    ServerGeoObjectType afterType = ServerGeoObjectType.get(event.getAfterTypeCode());
    List<ServerGeoObjectType> beforeSubtypes = beforeType.getSubtypes();
    List<ServerGeoObjectType> afterSubtypes = afterType.getSubtypes();
    if (!(beforeSubtypes.contains(source.getType()) || beforeType.getCode().equals(source.getType().getCode()))) {
        // This should be prevented by the front-end
        throw new ProgrammingErrorException("Source type must be a subtype of (" + beforeType.getCode() + ")");
    }
    if (!(afterSubtypes.contains(target.getType()) || afterType.getCode().equals(target.getType().getCode()))) {
        // This should be prevented by the front-end
        throw new ProgrammingErrorException("Target type must be a subtype of (" + afterType.getCode() + ")");
    }
}
Also used : ServerGeoObjectType(net.geoprism.registry.model.ServerGeoObjectType) ProgrammingErrorException(com.runwaysdk.dataaccess.ProgrammingErrorException)

Example 47 with ProgrammingErrorException

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

the class TransitionEvent method apply.

@Transaction
public static JsonObject apply(JsonObject json) {
    try {
        String beforeTypeCode = json.get(TransitionEvent.BEFORETYPECODE).getAsString();
        String afterTypeCode = json.get(TransitionEvent.AFTERTYPECODE).getAsString();
        ServerGeoObjectType beforeType = ServerGeoObjectType.get(beforeTypeCode);
        ServerGeoObjectType afterType = ServerGeoObjectType.get(afterTypeCode);
        ServiceFactory.getGeoObjectPermissionService().enforceCanWrite(beforeType.getOrganization().getCode(), beforeType);
        // ServiceFactory.getGeoObjectPermissionService().enforceCanWrite(afterType.getOrganization().getCode(),
        // afterType);
        DateFormat format = new SimpleDateFormat(GeoObjectImportConfiguration.DATE_FORMAT);
        format.setTimeZone(GeoRegistryUtil.SYSTEM_TIMEZONE);
        LocalizedValue description = LocalizedValue.fromJSON(json.get(TransitionEvent.DESCRIPTION).getAsJsonObject());
        TransitionEvent event = json.has(OID) ? TransitionEvent.get(json.get(OID).getAsString()) : new TransitionEvent();
        LocalizedValueConverter.populate(event, TransitionEvent.DESCRIPTION, description);
        event.setEventDate(format.parse(json.get(TransitionEvent.EVENTDATE).getAsString()));
        event.setBeforeTypeCode(beforeTypeCode);
        event.setAfterTypeCode(afterTypeCode);
        event.setBeforeTypeOrgCode(beforeType.getOrganization().getCode());
        event.setAfterTypeOrgCode(afterType.getOrganization().getCode());
        event.apply();
        JsonArray transitions = json.get("transitions").getAsJsonArray();
        List<String> appliedTrans = new ArrayList<String>();
        for (int i = 0; i < transitions.size(); i++) {
            JsonObject object = transitions.get(i).getAsJsonObject();
            Transition trans = Transition.apply(event, i, object);
            appliedTrans.add(trans.getOid());
        }
        for (Transition trans : event.getTransitions()) {
            if (!appliedTrans.contains(trans.getOid())) {
                trans.delete();
            }
        }
        return event.toJSON(false);
    } catch (ParseException e) {
        throw new ProgrammingErrorException(e);
    }
}
Also used : ServerGeoObjectType(net.geoprism.registry.model.ServerGeoObjectType) ArrayList(java.util.ArrayList) JsonObject(com.google.gson.JsonObject) ProgrammingErrorException(com.runwaysdk.dataaccess.ProgrammingErrorException) JsonArray(com.google.gson.JsonArray) LocalizedValue(org.commongeoregistry.adapter.dataaccess.LocalizedValue) SimpleDateFormat(java.text.SimpleDateFormat) DateFormat(java.text.DateFormat) ParseException(java.text.ParseException) SimpleDateFormat(java.text.SimpleDateFormat) Transaction(com.runwaysdk.dataaccess.transaction.Transaction)

Example 48 with ProgrammingErrorException

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

the class TransitionEvent method addPageWhereCriteria.

public static void addPageWhereCriteria(StringBuilder statement, Map<String, Object> parameters, String attrConditions) {
    List<String> whereConditions = new ArrayList<String>();
    // Add permissions criteria
    if (Session.getCurrentSession() != null) {
        String beforeCondition = GeoObjectTypeRestrictionUtil.buildTypeWritePermissionsFilter(TransitionEvent.BEFORETYPEORGCODE, TransitionEvent.BEFORETYPECODE);
        if (beforeCondition.length() > 0) {
            whereConditions.add(beforeCondition);
        }
        String afterCondition = GeoObjectTypeRestrictionUtil.buildTypeReadPermissionsFilter(TransitionEvent.AFTERTYPEORGCODE, TransitionEvent.AFTERTYPECODE);
        if (afterCondition.length() > 0) {
            whereConditions.add(afterCondition);
        }
    }
    // Filter based on attributes
    if (attrConditions != null && attrConditions.length() > 0) {
        List<String> lAttrConditions = new ArrayList<String>();
        JsonArray jaAttrConditions = JsonParser.parseString(attrConditions).getAsJsonArray();
        for (int i = 0; i < jaAttrConditions.size(); ++i) {
            JsonObject attrCondition = jaAttrConditions.get(i).getAsJsonObject();
            String attr = attrCondition.get("attribute").getAsString();
            MdVertexDAO eventMd = (MdVertexDAO) MdVertexDAO.getMdVertexDAO(TransitionEvent.CLASS);
            MdAttributeDAOIF mdAttr = eventMd.definesAttribute(attr);
            if (attr.equals(TransitionEvent.EVENTDATE)) {
                DateFormat format = new SimpleDateFormat("yyyy-MM-dd");
                format.setTimeZone(GeoRegistryUtil.SYSTEM_TIMEZONE);
                List<String> dateConditions = new ArrayList<String>();
                try {
                    if (attrCondition.has("startDate") && !attrCondition.get("startDate").isJsonNull() && attrCondition.get("startDate").getAsString().length() > 0) {
                        Date startDate = format.parse(attrCondition.get("startDate").getAsString());
                        dateConditions.add(mdAttr.getColumnName() + ">=:startDate" + i);
                        parameters.put("startDate" + i, startDate);
                    }
                    if (attrCondition.has("endDate") && !attrCondition.get("endDate").isJsonNull() && attrCondition.get("endDate").getAsString().length() > 0) {
                        Date endDate = format.parse(attrCondition.get("endDate").getAsString());
                        dateConditions.add(mdAttr.getColumnName() + "<=:endDate" + i);
                        parameters.put("endDate" + i, endDate);
                    }
                } catch (ParseException e) {
                    throw new ProgrammingErrorException(e);
                }
                if (dateConditions.size() > 0) {
                    lAttrConditions.add("(" + StringUtils.join(dateConditions, " AND ") + ")");
                }
            } else if (attrCondition.has("value") && !attrCondition.get("value").isJsonNull() && attrCondition.get("value").getAsString().length() > 0) {
                String value = attrCondition.get("value").getAsString();
                lAttrConditions.add(mdAttr.getColumnName() + "=:val" + i);
                parameters.put("val" + i, value);
            }
        }
        if (lAttrConditions.size() > 0) {
            whereConditions.add(StringUtils.join(lAttrConditions, " AND "));
        }
    }
    if (whereConditions.size() > 0) {
        statement.append(" WHERE " + StringUtils.join(whereConditions, " AND "));
    }
}
Also used : ArrayList(java.util.ArrayList) JsonObject(com.google.gson.JsonObject) Date(java.util.Date) ProgrammingErrorException(com.runwaysdk.dataaccess.ProgrammingErrorException) JsonArray(com.google.gson.JsonArray) MdAttributeDAOIF(com.runwaysdk.dataaccess.MdAttributeDAOIF) SimpleDateFormat(java.text.SimpleDateFormat) DateFormat(java.text.DateFormat) MdVertexDAO(com.runwaysdk.dataaccess.metadata.graph.MdVertexDAO) ParseException(java.text.ParseException) SimpleDateFormat(java.text.SimpleDateFormat)

Example 49 with ProgrammingErrorException

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

the class RegistryJsonTimeFormatter method read.

@Override
public Date read(JsonReader in) throws IOException {
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
    sdf.setTimeZone(GeoRegistryUtil.SYSTEM_TIMEZONE);
    try {
        return sdf.parse(in.nextString());
    } catch (ParseException | IOException e) {
        throw new ProgrammingErrorException(e);
    }
}
Also used : ParseException(java.text.ParseException) IOException(java.io.IOException) SimpleDateFormat(java.text.SimpleDateFormat) ProgrammingErrorException(com.runwaysdk.dataaccess.ProgrammingErrorException)

Example 50 with ProgrammingErrorException

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

the class AttributeTypeConverter method build.

public AttributeType build(MdAttributeConcreteDAOIF mdAttribute) {
    Locale locale = Session.getCurrentLocale();
    String attributeName = mdAttribute.definesAttribute();
    LocalizedValue displayLabel = AttributeTypeConverter.convert(mdAttribute.getDisplayLabel(locale), mdAttribute.getDisplayLabels());
    LocalizedValue description = AttributeTypeConverter.convert(mdAttribute.getDescription(locale), mdAttribute.getDescriptions());
    boolean required = mdAttribute.isRequired();
    boolean unique = mdAttribute.isUnique();
    boolean isChangeOverTime = true;
    DefaultAttribute defaultAttr = DefaultAttribute.getByAttributeName(attributeName);
    if (defaultAttr != null) {
        isChangeOverTime = defaultAttr.isChangeOverTime();
    }
    if (mdAttribute instanceof MdAttributeBooleanDAOIF) {
        return AttributeType.factory(attributeName, displayLabel, description, AttributeBooleanType.TYPE, required, unique, isChangeOverTime);
    } else if (mdAttribute instanceof MdAttributeLocalDAOIF) {
        return AttributeType.factory(attributeName, displayLabel, description, AttributeLocalType.TYPE, required, unique, isChangeOverTime);
    } else if (mdAttribute instanceof MdAttributeCharacterDAOIF) {
        return AttributeType.factory(attributeName, displayLabel, description, AttributeCharacterType.TYPE, required, unique, isChangeOverTime);
    } else if (mdAttribute instanceof MdAttributeDateDAOIF || mdAttribute instanceof MdAttributeDateTimeDAOIF) {
        return AttributeType.factory(attributeName, displayLabel, description, AttributeDateType.TYPE, required, unique, isChangeOverTime);
    } else if (mdAttribute instanceof MdAttributeDecDAOIF) {
        MdAttributeDecDAOIF mdAttributeDec = (MdAttributeDecDAOIF) mdAttribute;
        AttributeFloatType attributeType = (AttributeFloatType) AttributeType.factory(attributeName, displayLabel, description, AttributeFloatType.TYPE, required, unique, isChangeOverTime);
        attributeType.setPrecision(Integer.parseInt(mdAttributeDec.getLength()));
        attributeType.setScale(Integer.parseInt(mdAttributeDec.getDecimal()));
        return attributeType;
    } else if (mdAttribute instanceof MdAttributeIntegerDAOIF || mdAttribute instanceof MdAttributeLongDAOIF) {
        return AttributeType.factory(attributeName, displayLabel, description, AttributeIntegerType.TYPE, required, unique, isChangeOverTime);
    } else if (mdAttribute instanceof MdAttributeClassificationDAOIF) {
        MdClassificationDAOIF mdClassification = ((MdAttributeClassificationDAOIF) mdAttribute).getMdClassificationDAOIF();
        AttributeClassificationType attributeType = (AttributeClassificationType) AttributeType.factory(attributeName, displayLabel, description, AttributeClassificationType.TYPE, required, unique, isChangeOverTime);
        attributeType.setClassificationType(mdClassification.getValue(MdClassificationInfo.TYPE_NAME));
        String rootOid = ((MdAttributeClassificationDAOIF) mdAttribute).getValue(MdAttributeClassificationInfo.ROOT);
        if (rootOid != null && rootOid.length() > 0) {
            ClassificationType type = new ClassificationType(mdClassification);
            Classification classification = Classification.getByOid(type, rootOid);
            attributeType.setRootTerm(classification.toTerm());
        }
        return attributeType;
    } else if (mdAttribute instanceof MdAttributeEnumerationDAOIF || mdAttribute instanceof MdAttributeTermDAOIF) {
        AttributeTermType attributeType = (AttributeTermType) AttributeType.factory(attributeName, displayLabel, description, AttributeTermType.TYPE, required, unique, isChangeOverTime);
        if (mdAttribute instanceof MdAttributeTermDAOIF) {
            List<RelationshipDAOIF> rels = ((MdAttributeTermDAOIF) mdAttribute).getAllAttributeRoots();
            if (rels.size() > 0) {
                RelationshipDAOIF rel = rels.get(0);
                BusinessDAO classy = (BusinessDAO) rel.getChild();
                TermConverter termBuilder = new TermConverter(classy.getKey());
                Term adapterTerm = termBuilder.build();
                attributeType.setRootTerm(adapterTerm);
            } else {
                throw new ProgrammingErrorException("Expected an attribute root on MdAttribute [" + mdAttribute.getKey() + "].");
            }
        } else {
            throw new ProgrammingErrorException("Enum attributes are not supported at this time.");
        }
        return attributeType;
    }
    throw new UnsupportedOperationException("Unsupported attribute type [" + mdAttribute.getClass().getSimpleName() + "]");
}
Also used : Locale(java.util.Locale) AttributeFloatType(org.commongeoregistry.adapter.metadata.AttributeFloatType) MdClassificationDAOIF(com.runwaysdk.dataaccess.MdClassificationDAOIF) RelationshipDAOIF(com.runwaysdk.dataaccess.RelationshipDAOIF) LocalizedValue(org.commongeoregistry.adapter.dataaccess.LocalizedValue) MdAttributeEnumerationDAOIF(com.runwaysdk.dataaccess.MdAttributeEnumerationDAOIF) MdAttributeLongDAOIF(com.runwaysdk.dataaccess.MdAttributeLongDAOIF) MdAttributeIntegerDAOIF(com.runwaysdk.dataaccess.MdAttributeIntegerDAOIF) Classification(net.geoprism.registry.model.Classification) MdAttributeTermDAOIF(com.runwaysdk.dataaccess.MdAttributeTermDAOIF) List(java.util.List) MdAttributeBooleanDAOIF(com.runwaysdk.dataaccess.MdAttributeBooleanDAOIF) BusinessDAO(com.runwaysdk.dataaccess.BusinessDAO) MdAttributeDateTimeDAOIF(com.runwaysdk.dataaccess.MdAttributeDateTimeDAOIF) Term(org.commongeoregistry.adapter.Term) AttributeClassificationType(org.commongeoregistry.adapter.metadata.AttributeClassificationType) AttributeClassificationType(org.commongeoregistry.adapter.metadata.AttributeClassificationType) ClassificationType(net.geoprism.registry.model.ClassificationType) ProgrammingErrorException(com.runwaysdk.dataaccess.ProgrammingErrorException) MdAttributeLocalDAOIF(com.runwaysdk.dataaccess.MdAttributeLocalDAOIF) MdAttributeDecDAOIF(com.runwaysdk.dataaccess.MdAttributeDecDAOIF) DefaultAttribute(org.commongeoregistry.adapter.constants.DefaultAttribute) MdAttributeClassificationDAOIF(com.runwaysdk.dataaccess.MdAttributeClassificationDAOIF) MdAttributeDateDAOIF(com.runwaysdk.dataaccess.MdAttributeDateDAOIF) AttributeTermType(org.commongeoregistry.adapter.metadata.AttributeTermType) MdAttributeCharacterDAOIF(com.runwaysdk.dataaccess.MdAttributeCharacterDAOIF)

Aggregations

ProgrammingErrorException (com.runwaysdk.dataaccess.ProgrammingErrorException)67 IOException (java.io.IOException)34 SimpleDateFormat (java.text.SimpleDateFormat)21 JsonObject (com.google.gson.JsonObject)18 File (java.io.File)16 ParseException (java.text.ParseException)16 InputStream (java.io.InputStream)13 ServerGeoObjectType (net.geoprism.registry.model.ServerGeoObjectType)13 MdAttributeConcreteDAOIF (com.runwaysdk.dataaccess.MdAttributeConcreteDAOIF)12 Transaction (com.runwaysdk.dataaccess.transaction.Transaction)12 MdBusinessDAOIF (com.runwaysdk.dataaccess.MdBusinessDAOIF)11 JSONException (org.json.JSONException)11 JsonArray (com.google.gson.JsonArray)10 List (java.util.List)10 MdBusinessDAO (com.runwaysdk.dataaccess.metadata.MdBusinessDAO)9 ArrayList (java.util.ArrayList)9 Date (java.util.Date)9 HashMap (java.util.HashMap)8 Collectors (java.util.stream.Collectors)8 ServerHierarchyType (net.geoprism.registry.model.ServerHierarchyType)8