use of org.eclipse.vorto.model.ModelId in project vorto by eclipse.
the class ModelRepository method getMappingModelsForTargetPlatform.
@Override
public List<ModelInfo> getMappingModelsForTargetPlatform(ModelId modelId, String targetPlatform, Optional<String> version) {
LOGGER.info("Fetching mapping models for model ID " + modelId.getPrettyFormat() + " and key " + targetPlatform);
Set<ModelInfo> mappingResources = new HashSet<>();
ModelInfo modelResource = getBasicInfo(modelId);
if (modelResource != null) {
for (ModelInfo referenceeModelInfo : this.getModelsReferencing(modelId)) {
if (referenceeModelInfo.getType() != ModelType.Mapping || version.isPresent() && !referenceeModelInfo.getId().getVersion().equals(version.get())) {
continue;
}
if (referenceeModelInfo.getTargetPlatformKey() != null) {
if (targetPlatform.equalsIgnoreCase(referenceeModelInfo.getTargetPlatformKey())) {
mappingResources.add(referenceeModelInfo);
}
} else if (getEMFResource(referenceeModelInfo.getId()).matchesTargetPlatform(targetPlatform)) {
mappingResources.add(referenceeModelInfo);
}
}
for (ModelId referencedModelId : modelResource.getReferences()) {
mappingResources.addAll(this.repositoryFactory.getRepositoryByModel(referencedModelId).getMappingModelsForTargetPlatform(referencedModelId, targetPlatform, version));
}
}
return new ArrayList<>(mappingResources);
}
use of org.eclipse.vorto.model.ModelId in project vorto by eclipse.
the class AbstractModelParser method parse.
@Override
public ModelInfo parse(InputStream is) {
Injector injector = getInjector();
XtextResourceSet resourceSet = workspace.getResourceSet();
Resource resource = createResource(fileName, getContent(is), resourceSet).orElseThrow(() -> new ValidationException("Xtext is not able to create a resource for this model. Check if you are using the correct parser.", getModelInfoFromFilename()));
if (resource.getContents().size() <= 0) {
throw new ValidationException("Xtext is not able to create a model out of this file. Check if the file you are using is correct.", getModelInfoFromFilename());
}
Model model = (Model) resource.getContents().get(0);
// always load direct references to make the model complete
workspace.loadFromRepository(getReferences(model));
if (this.isValidationEnabled) {
/* Execute validators */
IResourceValidator validator = injector.getInstance(IResourceValidator.class);
List<Issue> issues = validator.validate(resource, CheckMode.ALL, CancelIndicator.NullImpl);
if (issues.size() > 0) {
List<ModelId> missingReferences = getMissingReferences(model, issues);
if (missingReferences.size() > 0) {
throw new CouldNotResolveReferenceException(getModelInfo(model).orElse(getModelInfoFromFilename()), missingReferences);
} else {
Set<ValidationIssue> validationIssues = convertIssues(issues);
throw new ValidationException(collate(validationIssues), validationIssues, getModelInfo(model).orElse(getModelInfoFromFilename()));
}
}
if (!resource.getErrors().isEmpty()) {
throw new ValidationException(resource.getErrors().get(0).getMessage(), getModelInfo(model).orElse(getModelInfoFromFilename()));
}
}
return new ModelResource((Model) resource.getContents().get(0));
}
use of org.eclipse.vorto.model.ModelId in project vorto by eclipse.
the class LocalModelWorkspace method loadFromRepository.
public void loadFromRepository(Collection<ModelId> modelIds) {
Collection<ModelId> allReferences = modelIds;
allReferences.removeAll(this.modelIds);
allReferences.forEach(refModelId -> {
try {
repoFactory.getRepositoryByModel(refModelId).getFileContent(refModelId, Optional.empty()).ifPresent(refFile -> {
createResource(refFile.getFileName(), refFile.getContent(), resourceSet);
});
} catch (ModelNotFoundException notFoundException) {
throw new ValidationException("Could not find reference " + refModelId.getPrettyFormat(), null);
}
});
// add references, so that they are not looked up again
this.modelIds.addAll(allReferences);
}
use of org.eclipse.vorto.model.ModelId in project vorto by eclipse.
the class ModelSequencerOld method execute.
@Override
public boolean execute(Property inputProperty, Node outputNode, Context context) throws Exception {
Binary binaryValue = inputProperty.getBinary();
CheckArg.isNotNull(binaryValue, "binary");
ModelInfo modelResource = null;
try {
IModelParser parser = ModelParserFactory.instance().getParser(outputNode.getPath());
modelResource = parser.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());
if (outputNode.hasProperty("vorto:references")) {
// first remove any previous references of the node.
outputNode.getProperty("vorto:references").remove();
outputNode.getSession().save();
}
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()]));
}
} catch (Throwable couldNotParse) {
outputNode.setProperty("vorto:description", "Erronous Model !!!!");
outputNode.setProperty("vorto:type", ModelType.create(outputNode.getPath()).name());
outputNode.setProperty("vorto:displayname", "");
outputNode.setProperty("vorto:version", "1.0.0");
outputNode.setProperty("vorto:namespace", "erronous");
outputNode.setProperty("vorto:name", outputNode.getName());
}
return true;
}
use of org.eclipse.vorto.model.ModelId in project vorto by eclipse.
the class ReferenceIntegrityDiagnostic method apply.
@Override
public Collection<Diagnostic> apply(Node node) {
Collection<Diagnostic> diagnostics = Lists.newArrayList();
try {
String nodeId = node.getIdentifier();
ModelId modelId = NodeDiagnosticUtils.getModelId(node.getPath()).orElseThrow(() -> new NodeDiagnosticException("Cannot generate modelId from supplied node with identifier '" + nodeId + "'"));
if (node.hasProperty(VORTO_REFERENCES)) {
for (Value value : node.getProperty(VORTO_REFERENCES).getValues()) {
try {
node.getSession().getNodeByIdentifier(value.getString());
} catch (ItemNotFoundException e) {
diagnostics.add(new Diagnostic(modelId, "The model has reference to node '" + value.getString() + "' but it cannot be found in the repository."));
}
}
}
PropertyIterator propIter = node.getReferences();
while (propIter.hasNext()) {
Property prop = propIter.nextProperty();
try {
Node referencedByFileNode = prop.getParent();
ModelIdHelper.fromPath(referencedByFileNode.getParent().getPath());
} catch (Exception e) {
diagnostics.add(new Diagnostic(modelId, "The model is being referenced by a stale node."));
}
}
} catch (RepositoryException e) {
throw new NodeDiagnosticException("Error in accessing some properties of node", e);
}
return diagnostics;
}
Aggregations