use of org.eclipse.vorto.repository.api.ModelInfo 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;
}
use of org.eclipse.vorto.repository.api.ModelInfo in project vorto by eclipse.
the class JcrModelRepository method getById.
@Override
public ModelInfo getById(ModelId modelId) {
try {
ModelIdHelper modelIdHelper = new ModelIdHelper(modelId);
Node folderNode = session.getNode(modelIdHelper.getFullPath());
Node modelFileNode = folderNode.getNodes("*.type | *.fbmodel | *.infomodel | *.mapping").nextNode();
ModelInfo modelResource = createModelResource(modelFileNode);
if (modelResource.getType() == ModelType.InformationModel) {
NodeIterator imageNodeIterator = folderNode.getNodes("img.png*");
if (imageNodeIterator.hasNext()) {
modelResource.setHasImage(true);
}
}
return modelResource;
} catch (PathNotFoundException e) {
return null;
} catch (RepositoryException e) {
throw new RuntimeException("Retrieving Content of Resource: Problem accessing repository", e);
}
}
use of org.eclipse.vorto.repository.api.ModelInfo in project vorto by eclipse.
the class JcrModelRepository method removeModel.
@Override
public void removeModel(ModelId modelId) {
try {
ModelInfo modelResource = this.getById(modelId);
if (!modelResource.getReferencedBy().isEmpty()) {
throw new ModelReferentialIntegrityException("Cannot remove model because it is referenced by other model(s)", modelResource.getReferencedBy());
}
ModelIdHelper modelIdHelper = new ModelIdHelper(modelId);
Item item = session.getItem(modelIdHelper.getFullPath());
item.remove();
session.save();
} catch (RepositoryException e) {
throw new FatalModelRepositoryException("Problem occured removing the model", e);
}
}
use of org.eclipse.vorto.repository.api.ModelInfo in project vorto by eclipse.
the class JcrModelRepository method checkin.
@Override
public ModelInfo checkin(String handleId, String author) {
StorageItem uploadedItem = this.uploadStorage.get(handleId);
if (uploadedItem == null) {
throw new IllegalArgumentException("No model found for handleId '" + handleId + "'");
}
final ModelInfo resource = ModelParserFactory.getParser(handleId).parse(new ByteArrayInputStream((byte[]) uploadedItem.getValue()));
try {
Node folderNode = createNodeForModelId(resource.getId());
Node fileNode = folderNode.getNodes("*.type | *.fbmodel | *.infomodel | *.mapping").hasNext() ? folderNode.getNodes("*.type | *.fbmodel | *.infomodel | *.mapping").nextNode() : null;
if (fileNode == null) {
fileNode = folderNode.addNode(resource.getId().getName() + resource.getType().getExtension(), "nt:file");
fileNode.addMixin("vorto:meta");
fileNode.addMixin("mix:referenceable");
fileNode.setProperty("vorto:author", author);
Node contentNode = fileNode.addNode("jcr:content", "nt:resource");
Binary binary = session.getValueFactory().createBinary(new ByteArrayInputStream((byte[]) uploadedItem.getValue()));
contentNode.setProperty("jcr:data", binary);
} else {
Node contentNode = fileNode.getNode("jcr:content");
Binary binary = session.getValueFactory().createBinary(new ByteArrayInputStream((byte[]) uploadedItem.getValue()));
contentNode.setProperty("jcr:data", binary);
}
session.save();
logger.info("Checkin successful");
this.uploadStorage.remove(handleId);
// Email Notification
notifyWatchers(resource, author);
} catch (Exception e) {
logger.error("Error checking in model", e);
throw new FatalModelRepositoryException("Problem checking in uploaded model" + resource.getId(), e);
}
return resource;
}
use of org.eclipse.vorto.repository.api.ModelInfo in project vorto by eclipse.
the class AbstractModelParser method parse.
@Override
public ModelInfo parse(InputStream is) {
XtextResourceSet resourceSet = getInjector().getInstance(XtextResourceSet.class);
resourceSet.addLoadOption(XtextResource.OPTION_RESOLVE_ALL, Boolean.TRUE);
Resource resource = resourceSet.createResource(URI.createURI("dummy:/" + fileName));
try {
resource.load(is, resourceSet.getLoadOptions());
} catch (IOException e) {
throw new ValidationException(e.getMessage(), null);
}
List<org.eclipse.emf.ecore.resource.Resource.Diagnostic> grammarErrors = getGrammarErrors(resource.getErrors());
if (!grammarErrors.isEmpty()) {
ModelInfo invalidModelResource = new ModelInfo(parseModelIdFromFileName(), ModelType.fromFileName(fileName));
throw new ValidationException(grammarErrors.get(0).getMessage(), invalidModelResource);
}
return new ModelEMFResource((Model) resource.getContents().get(0));
}
Aggregations