Search in sources :

Example 1 with MdVertexDAO

use of com.runwaysdk.dataaccess.metadata.graph.MdVertexDAO in project geoprism-registry by terraframe.

the class BusinessType method apply.

@Transaction
public static BusinessType apply(JsonObject object) {
    String code = object.get(BusinessType.CODE).getAsString();
    String organizationCode = object.get(BusinessType.ORGANIZATION).getAsString();
    Organization organization = Organization.getByCode(organizationCode);
    ServiceFactory.getGeoObjectTypePermissionService().enforceCanCreate(organization.getCode(), false);
    if (!MasterList.isValidName(code)) {
        throw new InvalidMasterListCodeException("The geo object type code has an invalid character");
    }
    if (code.length() > 64) {
        // Setting the typename on the MdBusiness creates this limitation.
        CodeLengthException ex = new CodeLengthException();
        ex.setLength(64);
        throw ex;
    }
    // assignSRAPermissions(mdVertex, mdBusiness);
    // assignAll_RA_Permissions(mdVertex, mdBusiness, organizationCode);
    LocalizedValue localizedValue = LocalizedValue.fromJSON(object.get(DISPLAYLABEL).getAsJsonObject());
    BusinessType businessType = (object.has(OID) && !object.get(OID).isJsonNull()) ? BusinessType.get(object.get(OID).getAsString()) : new BusinessType();
    businessType.setCode(code);
    businessType.setOrganization(organization);
    LocalizedValueConverter.populate(businessType.getDisplayLabel(), localizedValue);
    boolean isNew = businessType.isNew();
    if (isNew) {
        MdVertexDAO mdVertex = MdVertexDAO.newInstance();
        mdVertex.setValue(MdGeoVertexInfo.PACKAGE, RegistryConstants.BUSINESS_PACKAGE);
        mdVertex.setValue(MdGeoVertexInfo.NAME, code);
        mdVertex.setValue(MdGeoVertexInfo.ENABLE_CHANGE_OVER_TIME, MdAttributeBooleanInfo.FALSE);
        mdVertex.setValue(MdGeoVertexInfo.GENERATE_SOURCE, MdAttributeBooleanInfo.FALSE);
        LocalizedValueConverter.populate(mdVertex, MdVertexInfo.DISPLAY_LABEL, localizedValue);
        mdVertex.apply();
        // TODO CREATE the edge between this class and GeoVertex??
        MdVertexDAOIF mdGeoVertexDAO = MdVertexDAO.getMdVertexDAO(GeoVertex.CLASS);
        MdAttributeGraphReferenceDAO mdGeoObject = MdAttributeGraphReferenceDAO.newInstance();
        mdGeoObject.setValue(MdAttributeGraphReferenceInfo.REFERENCE_MD_VERTEX, mdGeoVertexDAO.getOid());
        mdGeoObject.setValue(MdAttributeGraphReferenceInfo.DEFINING_MD_CLASS, mdVertex.getOid());
        mdGeoObject.setValue(MdAttributeGraphReferenceInfo.NAME, GEO_OBJECT);
        mdGeoObject.setStructValue(MdAttributeGraphReferenceInfo.DESCRIPTION, MdAttributeLocalInfo.DEFAULT_LOCALE, "Geo Object");
        mdGeoObject.apply();
        // DefaultAttribute.CODE
        MdAttributeCharacterDAO vertexCodeMdAttr = MdAttributeCharacterDAO.newInstance();
        vertexCodeMdAttr.setValue(MdAttributeConcreteInfo.NAME, DefaultAttribute.CODE.getName());
        vertexCodeMdAttr.setStructValue(MdAttributeConcreteInfo.DISPLAY_LABEL, MdAttributeLocalInfo.DEFAULT_LOCALE, DefaultAttribute.CODE.getDefaultLocalizedName());
        vertexCodeMdAttr.setStructValue(MdAttributeConcreteInfo.DESCRIPTION, MdAttributeLocalInfo.DEFAULT_LOCALE, DefaultAttribute.CODE.getDefaultDescription());
        vertexCodeMdAttr.setValue(MdAttributeCharacterInfo.SIZE, MdAttributeCharacterInfo.MAX_CHARACTER_SIZE);
        vertexCodeMdAttr.setValue(MdAttributeConcreteInfo.DEFINING_MD_CLASS, mdVertex.getOid());
        vertexCodeMdAttr.setValue(MdAttributeConcreteInfo.REQUIRED, MdAttributeBooleanInfo.TRUE);
        vertexCodeMdAttr.addItem(MdAttributeConcreteInfo.INDEX_TYPE, IndexTypes.UNIQUE_INDEX.getOid());
        vertexCodeMdAttr.apply();
        businessType.setMdVertexId(mdVertex.getOid());
        // Assign permissions
        Roles role = Roles.findRoleByName(RegistryConstants.REGISTRY_SUPER_ADMIN_ROLE);
        RoleDAO roleDAO = (RoleDAO) BusinessFacade.getEntityDAO(role);
        roleDAO.grantPermission(Operation.CREATE, mdVertex.getOid());
        roleDAO.grantPermission(Operation.DELETE, mdVertex.getOid());
        roleDAO.grantPermission(Operation.WRITE, mdVertex.getOid());
        roleDAO.grantPermission(Operation.WRITE_ALL, mdVertex.getOid());
    }
    businessType.apply();
    return businessType;
}
Also used : MdVertexDAOIF(com.runwaysdk.dataaccess.MdVertexDAOIF) MdAttributeGraphReferenceDAO(com.runwaysdk.dataaccess.metadata.MdAttributeGraphReferenceDAO) Roles(com.runwaysdk.system.Roles) MdAttributeCharacterDAO(com.runwaysdk.dataaccess.metadata.MdAttributeCharacterDAO) LocalizedValue(org.commongeoregistry.adapter.dataaccess.LocalizedValue) RoleDAO(com.runwaysdk.business.rbac.RoleDAO) MdVertexDAO(com.runwaysdk.dataaccess.metadata.graph.MdVertexDAO) Transaction(com.runwaysdk.dataaccess.transaction.Transaction)

Example 2 with MdVertexDAO

use of com.runwaysdk.dataaccess.metadata.graph.MdVertexDAO 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 3 with MdVertexDAO

use of com.runwaysdk.dataaccess.metadata.graph.MdVertexDAO in project geoprism-registry by terraframe.

the class ServerGeoObjectType method createMdAttributeFromAttributeType.

/**
 * Creates an {@link MdAttributeConcrete} for the given {@link MdBusiness}
 * from the given {@link AttributeType}
 *
 * @pre assumes no attribute has been defined on the type with the given name.
 * @param geoObjectType
 *          TODO
 * @param mdBusiness
 *          Type to receive attribute definition
 * @param attributeType
 *          newly defined attribute
 *
 * @return {@link AttributeType}
 */
@Transaction
public MdAttributeConcrete createMdAttributeFromAttributeType(AttributeType attributeType) {
    MdAttributeConcrete mdAttribute = ServerGeoObjectType.createMdAttributeFromAttributeType(this.mdBusiness, attributeType);
    ListType.createMdAttribute(this, attributeType);
    ((MdVertexDAO) this.mdVertex).copyAttribute(MdAttributeDAO.get(mdAttribute.getOid()));
    return mdAttribute;
}
Also used : MdVertexDAO(com.runwaysdk.dataaccess.metadata.graph.MdVertexDAO) MdAttributeConcrete(com.runwaysdk.system.metadata.MdAttributeConcrete) Transaction(com.runwaysdk.dataaccess.transaction.Transaction)

Example 4 with MdVertexDAO

use of com.runwaysdk.dataaccess.metadata.graph.MdVertexDAO in project geoprism-registry by terraframe.

the class SearchService method createSearchTable.

@Transaction
public void createSearchTable() {
    String suffix = this.getSuffix();
    String typeName = VERTEX_PREFIX + suffix;
    MdVertexDAO mdVertex = MdVertexDAO.newInstance();
    mdVertex.setValue(MdVertexInfo.PACKAGE, PACKAGE);
    mdVertex.setValue(MdVertexInfo.NAME, typeName);
    mdVertex.setValue(MdVertexInfo.GENERATE_SOURCE, MdAttributeBooleanInfo.FALSE);
    mdVertex.apply();
    MdAttributeTextDAO label = MdAttributeTextDAO.newInstance();
    label.setValue(MdAttributeTextInfo.NAME, LABEL);
    label.setValue(MdAttributeTextInfo.DEFINING_MD_CLASS, mdVertex.getOid());
    label.apply();
    MdAttributeTextDAO code = MdAttributeTextDAO.newInstance();
    code.setValue(MdAttributeTextInfo.NAME, CODE);
    code.setValue(MdAttributeTextInfo.DEFINING_MD_CLASS, mdVertex.getOid());
    code.setValue(MdAttributeTextInfo.INDEX_TYPE, IndexTypes.NON_UNIQUE_INDEX.getOid());
    code.apply();
    MdAttributeTextDAO vertexType = MdAttributeTextDAO.newInstance();
    vertexType.setValue(MdAttributeTextInfo.NAME, VERTEX_TYPE);
    vertexType.setValue(MdAttributeTextInfo.DEFINING_MD_CLASS, mdVertex.getOid());
    vertexType.setValue(MdAttributeTextInfo.INDEX_TYPE, IndexTypes.NON_UNIQUE_INDEX.getOid());
    vertexType.apply();
    MdAttributeDateDAO startDate = MdAttributeDateDAO.newInstance();
    startDate.setValue(MdAttributeTextInfo.NAME, START_DATE);
    startDate.setValue(MdAttributeTextInfo.DEFINING_MD_CLASS, mdVertex.getOid());
    startDate.setValue(MdAttributeTextInfo.INDEX_TYPE, IndexTypes.NON_UNIQUE_INDEX.getOid());
    startDate.apply();
    MdAttributeDateDAO endDate = MdAttributeDateDAO.newInstance();
    endDate.setValue(MdAttributeTextInfo.NAME, END_DATE);
    endDate.setValue(MdAttributeTextInfo.DEFINING_MD_CLASS, mdVertex.getOid());
    endDate.setValue(MdAttributeTextInfo.INDEX_TYPE, IndexTypes.NON_UNIQUE_INDEX.getOid());
    endDate.apply();
    MdEdgeDAO mdEdge = MdEdgeDAO.newInstance();
    mdEdge.setValue(MdVertexInfo.PACKAGE, PACKAGE);
    mdEdge.setValue(MdVertexInfo.NAME, EDGE_PREFIX + suffix);
    mdEdge.setValue(MdEdgeInfo.PARENT_MD_VERTEX, mdVertex.getOid());
    mdEdge.setValue(MdEdgeInfo.CHILD_MD_VERTEX, MdVertexDAO.getMdVertexDAO(GeoVertex.CLASS).getOid());
    mdEdge.apply();
    GraphDBService service = GraphDBService.getInstance();
    GraphRequest dml = service.getGraphDBRequest();
    GraphRequest ddl = service.getDDLGraphDBRequest();
    String attributeName = label.getValue(MdAttributeTextInfo.NAME);
    String className = mdVertex.getDBClassName();
    String indexName = className + "." + attributeName;
    String statement = "CREATE INDEX " + indexName + " ON " + className + "(" + attributeName + ") FULLTEXT ENGINE LUCENE";
    GraphDDLCommandAction action = service.ddlCommand(dml, ddl, statement, new HashMap<String, Object>());
    action.execute();
    this.assignAllPermissions(Roles.findRoleByName(RegistryConstants.REGISTRY_SUPER_ADMIN_ROLE), mdVertex, mdEdge);
    this.assignAllPermissions(Roles.findRoleByName(RegistryConstants.REGISTRY_ADMIN_ROLE), mdVertex, mdEdge);
    this.assignAllPermissions(Roles.findRoleByName(RegistryConstants.REGISTRY_MAINTAINER_ROLE), mdVertex, mdEdge);
}
Also used : MdAttributeTextDAO(com.runwaysdk.dataaccess.metadata.MdAttributeTextDAO) GraphRequest(com.runwaysdk.dataaccess.graph.GraphRequest) MdAttributeDateDAO(com.runwaysdk.dataaccess.metadata.MdAttributeDateDAO) MdEdgeDAO(com.runwaysdk.dataaccess.metadata.graph.MdEdgeDAO) GraphDDLCommandAction(com.runwaysdk.dataaccess.graph.GraphDDLCommandAction) MdVertexDAO(com.runwaysdk.dataaccess.metadata.graph.MdVertexDAO) VertexObject(com.runwaysdk.business.graph.VertexObject) VertexServerGeoObject(net.geoprism.registry.model.graph.VertexServerGeoObject) GraphDBService(com.runwaysdk.dataaccess.graph.GraphDBService) Transaction(com.runwaysdk.dataaccess.transaction.Transaction)

Aggregations

MdVertexDAO (com.runwaysdk.dataaccess.metadata.graph.MdVertexDAO)4 Transaction (com.runwaysdk.dataaccess.transaction.Transaction)3 JsonArray (com.google.gson.JsonArray)1 JsonObject (com.google.gson.JsonObject)1 VertexObject (com.runwaysdk.business.graph.VertexObject)1 RoleDAO (com.runwaysdk.business.rbac.RoleDAO)1 MdAttributeDAOIF (com.runwaysdk.dataaccess.MdAttributeDAOIF)1 MdVertexDAOIF (com.runwaysdk.dataaccess.MdVertexDAOIF)1 ProgrammingErrorException (com.runwaysdk.dataaccess.ProgrammingErrorException)1 GraphDBService (com.runwaysdk.dataaccess.graph.GraphDBService)1 GraphDDLCommandAction (com.runwaysdk.dataaccess.graph.GraphDDLCommandAction)1 GraphRequest (com.runwaysdk.dataaccess.graph.GraphRequest)1 MdAttributeCharacterDAO (com.runwaysdk.dataaccess.metadata.MdAttributeCharacterDAO)1 MdAttributeDateDAO (com.runwaysdk.dataaccess.metadata.MdAttributeDateDAO)1 MdAttributeGraphReferenceDAO (com.runwaysdk.dataaccess.metadata.MdAttributeGraphReferenceDAO)1 MdAttributeTextDAO (com.runwaysdk.dataaccess.metadata.MdAttributeTextDAO)1 MdEdgeDAO (com.runwaysdk.dataaccess.metadata.graph.MdEdgeDAO)1 Roles (com.runwaysdk.system.Roles)1 MdAttributeConcrete (com.runwaysdk.system.metadata.MdAttributeConcrete)1 DateFormat (java.text.DateFormat)1