Search in sources :

Example 1 with ModelReferencesHelper

use of org.eclipse.vorto.repository.core.impl.utils.ModelReferencesHelper in project vorto by eclipse.

the class ModelSequencer method execute.

@Override
public boolean execute(Property inputProperty, Node outputNode, Context context) throws Exception {
    Binary binaryValue = inputProperty.getBinary();
    CheckArg.isNotNull(binaryValue, "binary");
    ModelInfo modelResource = ModelParserFactory.getParser(outputNode.getPath()).parse(binaryValue.getStream());
    outputNode.setProperty("vorto:description", modelResource.getDescription() != null ? modelResource.getDescription() : "");
    outputNode.setProperty("vorto:type", modelResource.getType().name());
    outputNode.setProperty("vorto:displayname", modelResource.getDisplayName());
    outputNode.setProperty("vorto:version", modelResource.getId().getVersion());
    outputNode.setProperty("vorto:namespace", modelResource.getId().getNamespace());
    outputNode.setProperty("vorto:name", modelResource.getId().getName());
    ModelReferencesHelper referencesHelper = new ModelReferencesHelper(modelResource.getReferences());
    if (referencesHelper.hasReferences()) {
        List<Value> references = new ArrayList<Value>();
        for (ModelId modelId : referencesHelper.getReferences()) {
            ModelIdHelper modelIdHelper = new ModelIdHelper(modelId);
            Node referencedFolder = outputNode.getSession().getNode(modelIdHelper.getFullPath());
            Node reference = referencedFolder.getNodes().nextNode();
            references.add(context.valueFactory().createValue(reference));
        }
        outputNode.setProperty("vorto:references", references.toArray(new Value[references.size()]));
    }
    return true;
}
Also used : ModelInfo(org.eclipse.vorto.repository.api.ModelInfo) ModelIdHelper(org.eclipse.vorto.repository.core.impl.utils.ModelIdHelper) ModelReferencesHelper(org.eclipse.vorto.repository.core.impl.utils.ModelReferencesHelper) Node(javax.jcr.Node) Value(javax.jcr.Value) ArrayList(java.util.ArrayList) Binary(javax.jcr.Binary) ModelId(org.eclipse.vorto.repository.api.ModelId)

Example 2 with ModelReferencesHelper

use of org.eclipse.vorto.repository.core.impl.utils.ModelReferencesHelper in project vorto by eclipse.

the class JcrModelRepository method createModelResource.

private ModelInfo createModelResource(Node node) throws RepositoryException {
    ModelInfo resource = createMinimalModelInfo(node);
    if (node.hasProperty("vorto:references")) {
        Value[] referenceValues = null;
        try {
            referenceValues = node.getProperty("vorto:references").getValues();
        } catch (Exception ex) {
            referenceValues = new Value[] { node.getProperty("vorto:references").getValue() };
        }
        if (referenceValues != null) {
            ModelReferencesHelper referenceHelper = new ModelReferencesHelper();
            for (Value referValue : referenceValues) {
                String nodeUuid = referValue.getString();
                Node referencedNode = session.getNodeByIdentifier(nodeUuid);
                referenceHelper.addModelReference(ModelIdHelper.fromPath(referencedNode.getParent().getPath()).getPrettyFormat());
            }
            resource.setReferences(referenceHelper.getReferences());
        }
    }
    PropertyIterator propIter = node.getReferences();
    while (propIter.hasNext()) {
        Property prop = propIter.nextProperty();
        Node referencedByFileNode = prop.getParent();
        final ModelId referencedById = ModelIdHelper.fromPath(referencedByFileNode.getParent().getPath());
        resource.getReferencedBy().add(referencedById);
        if (referencedByFileNode.getName().endsWith(ModelType.Mapping.getExtension())) {
            ModelEMFResource emfResource = getEMFResource(referencedById);
            resource.addPlatformMapping(emfResource.getTargetPlatform(), referencedById);
        }
    }
    return resource;
}
Also used : ModelInfo(org.eclipse.vorto.repository.api.ModelInfo) ModelReferencesHelper(org.eclipse.vorto.repository.core.impl.utils.ModelReferencesHelper) Node(javax.jcr.Node) Value(javax.jcr.Value) PropertyIterator(javax.jcr.PropertyIterator) Property(javax.jcr.Property) ModelReferentialIntegrityException(org.eclipse.vorto.repository.core.ModelReferentialIntegrityException) ModelNotFoundException(org.eclipse.vorto.repository.api.exception.ModelNotFoundException) FatalModelRepositoryException(org.eclipse.vorto.repository.core.FatalModelRepositoryException) PathNotFoundException(javax.jcr.PathNotFoundException) RepositoryException(javax.jcr.RepositoryException) IOException(java.io.IOException) ValidationException(org.eclipse.vorto.repository.core.impl.validation.ValidationException) ModelId(org.eclipse.vorto.repository.api.ModelId)

Aggregations

Node (javax.jcr.Node)2 Value (javax.jcr.Value)2 ModelId (org.eclipse.vorto.repository.api.ModelId)2 ModelInfo (org.eclipse.vorto.repository.api.ModelInfo)2 ModelReferencesHelper (org.eclipse.vorto.repository.core.impl.utils.ModelReferencesHelper)2 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 Binary (javax.jcr.Binary)1 PathNotFoundException (javax.jcr.PathNotFoundException)1 Property (javax.jcr.Property)1 PropertyIterator (javax.jcr.PropertyIterator)1 RepositoryException (javax.jcr.RepositoryException)1 ModelNotFoundException (org.eclipse.vorto.repository.api.exception.ModelNotFoundException)1 FatalModelRepositoryException (org.eclipse.vorto.repository.core.FatalModelRepositoryException)1 ModelReferentialIntegrityException (org.eclipse.vorto.repository.core.ModelReferentialIntegrityException)1 ModelIdHelper (org.eclipse.vorto.repository.core.impl.utils.ModelIdHelper)1 ValidationException (org.eclipse.vorto.repository.core.impl.validation.ValidationException)1