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);
}
}
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;
}
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;
}
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());
}
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();
}
Aggregations