Search in sources :

Example 11 with ModelInfo

use of org.eclipse.vorto.repository.api.ModelInfo in project vorto by eclipse.

the class JcrModelRepository method upload.

@Override
public UploadModelResult upload(byte[] content, String fileName, String callerId) {
    try {
        ModelInfo resource = ModelParserFactory.getParser(fileName).parse(new ByteArrayInputStream(content));
        List<ValidationException> validationExceptions = new ArrayList<ValidationException>();
        for (IModelValidator validator : validators) {
            try {
                validator.validate(resource, InvocationContext.create(callerId));
            } catch (ValidationException validationException) {
                validationExceptions.add(validationException);
            }
        }
        if (validationExceptions.size() <= 0) {
            return UploadModelResult.valid(createUploadHandle(content, resource.getType()), resource);
        } else {
            return UploadModelResultFactory.create(validationExceptions.toArray(new ValidationException[validationExceptions.size()]));
        }
    } catch (ValidationException e) {
        return UploadModelResultFactory.invalid(e);
    }
}
Also used : ModelInfo(org.eclipse.vorto.repository.api.ModelInfo) ValidationException(org.eclipse.vorto.repository.core.impl.validation.ValidationException) ByteArrayInputStream(java.io.ByteArrayInputStream) ArrayList(java.util.ArrayList) IModelValidator(org.eclipse.vorto.repository.core.impl.validation.IModelValidator)

Example 12 with ModelInfo

use of org.eclipse.vorto.repository.api.ModelInfo in project vorto by eclipse.

the class JcrModelRepository method createMinimalModelInfo.

private ModelInfo createMinimalModelInfo(Node node) throws RepositoryException {
    ModelInfo resource = new ModelInfo(ModelIdHelper.fromPath(node.getParent().getPath()), ModelType.valueOf(node.getProperty("vorto:type").getString()));
    resource.setDescription(node.getProperty("vorto:description").getString());
    resource.setDisplayName(node.getProperty("vorto:displayname").getString());
    resource.setCreationDate(node.getProperty("jcr:created").getDate().getTime());
    if (node.hasProperty("vorto:author")) {
        resource.setAuthor(node.getProperty("vorto:author").getString());
    }
    NodeIterator imageNodeIterator = node.getParent().getNodes("img.png*");
    if (imageNodeIterator.hasNext()) {
        resource.setHasImage(true);
    }
    return resource;
}
Also used : NodeIterator(javax.jcr.NodeIterator) ModelInfo(org.eclipse.vorto.repository.api.ModelInfo)

Example 13 with ModelInfo

use of org.eclipse.vorto.repository.api.ModelInfo 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 14 with ModelInfo

use of org.eclipse.vorto.repository.api.ModelInfo in project vorto by eclipse.

the class ModelRepositoryClientTest method testGetModelInfoById.

@Test
public void testGetModelInfoById() throws Exception {
    ModelInfo xdkModel = modelRepo.getById(ModelId.fromPrettyFormat("com.bosch.devices.XDK:1.0.0")).get();
    assertNotNull(xdkModel);
    assertEquals(ModelId.fromPrettyFormat("com.bosch.devices.XDK:1.0.0"), xdkModel.getId());
}
Also used : ModelInfo(org.eclipse.vorto.repository.api.ModelInfo) Test(org.junit.Test)

Example 15 with ModelInfo

use of org.eclipse.vorto.repository.api.ModelInfo in project vorto by eclipse.

the class DefaultModelBackupService method removeAll.

private void removeAll() throws Exception {
    Set<String> rootNodes = new HashSet<>();
    for (ModelInfo resource : this.modelRepository.search("*")) {
        int namespaceIdx = resource.getId().getNamespace().indexOf(".");
        if (namespaceIdx != -1) {
            final String org = resource.getId().getNamespace().substring(0, namespaceIdx);
            rootNodes.add(org);
        } else {
            rootNodes.add(resource.getId().getNamespace());
        }
    }
    for (String rootNode : rootNodes) {
        try {
            Item item = session.getItem("/" + rootNode);
            item.remove();
        } catch (PathNotFoundException ex) {
        }
    }
    this.session.save();
}
Also used : Item(javax.jcr.Item) ModelInfo(org.eclipse.vorto.repository.api.ModelInfo) PathNotFoundException(javax.jcr.PathNotFoundException) HashSet(java.util.HashSet)

Aggregations

ModelInfo (org.eclipse.vorto.repository.api.ModelInfo)35 Test (org.junit.Test)12 ModelId (org.eclipse.vorto.repository.api.ModelId)11 IOException (java.io.IOException)9 ModelNotFoundException (org.eclipse.vorto.repository.api.exception.ModelNotFoundException)9 ByteArrayInputStream (java.io.ByteArrayInputStream)7 AbstractIntegrationTest (org.eclipse.vorto.repository.AbstractIntegrationTest)6 FatalModelRepositoryException (org.eclipse.vorto.repository.core.FatalModelRepositoryException)6 ValidationException (org.eclipse.vorto.repository.core.impl.validation.ValidationException)6 ArrayList (java.util.ArrayList)5 Node (javax.jcr.Node)5 PathNotFoundException (javax.jcr.PathNotFoundException)5 RepositoryException (javax.jcr.RepositoryException)5 ApiOperation (io.swagger.annotations.ApiOperation)4 UnsupportedEncodingException (java.io.UnsupportedEncodingException)4 ZipEntry (java.util.zip.ZipEntry)4 UploadTooLargeException (org.eclipse.vorto.repository.web.core.exceptions.UploadTooLargeException)4 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)4 ApiResponses (io.swagger.annotations.ApiResponses)3 ByteArrayOutputStream (java.io.ByteArrayOutputStream)3