use of org.eclipse.vorto.repository.core.ModelInfo in project vorto by eclipse.
the class BulkReleaseFunction method execute.
@Override
public void execute(ModelInfo model, IUserContext user, Map<String, Object> context) {
for (ModelId referenceId : model.getReferences()) {
IModelRepository repository = repositoryFactory.getRepositoryByModel(referenceId);
ModelInfo referenceModel = repository.getById(referenceId);
if (ModelState.Draft.getName().equals(referenceModel.getState())) {
try {
workflowService.doAction(referenceId, user, SimpleWorkflowModel.ACTION_RELEASE.getName());
} catch (WorkflowException e) {
logger.error("Problem executing release for model " + referenceId + "during bulk release function", e);
}
}
}
}
use of org.eclipse.vorto.repository.core.ModelInfo in project vorto by eclipse.
the class DefaultPayloadMappingService method getModelWithAllDependencies.
private List<ModelInfo> getModelWithAllDependencies(ModelId modelId) {
List<ModelInfo> modelInfos = new ArrayList<>();
ModelInfo modelResource = this.modelRepositoryFactory.getRepositoryByModel(modelId).getById(modelId);
modelInfos.add(modelResource);
for (ModelId reference : modelResource.getReferences()) {
modelInfos.addAll(getModelWithAllDependencies(reference));
}
return modelInfos;
}
use of org.eclipse.vorto.repository.core.ModelInfo in project vorto by eclipse.
the class AbstractModelImporter method postValidate.
/**
* Checks if the uploaded models already exist in the repository.
*
* @param reports reports from the specific importer implementation
*/
protected void postValidate(List<ValidationReport> reports, Context context) {
reports.forEach(report -> {
if (report.getModel() != null) {
try {
IModelRepository modelRepository = modelRepoFactory.getRepositoryByModel(report.getModel().getId());
ModelInfo m = modelRepository.getById(report.getModel().getId());
if (m != null) {
if (m.isReleased()) {
report.setMessage(ValidationReport.ERROR_MODEL_ALREADY_RELEASED);
report.setValid(false);
} else {
if (isAdmin(context.getUser()) || m.getAuthor().equals(context.getUser().getUsername())) {
report.setMessage(ValidationReport.WARNING_MODEL_ALREADY_EXISTS);
report.setValid(true);
} else {
report.setMessage(ValidationReport.ERROR_MODEL_ALREADY_EXISTS);
report.setValid(false);
}
}
}
} catch (Exception e) {
logger.error(String.format("Error while validating the model %s", report.getModel().getId()), e);
report.setMessage(new StatusMessage(String.format("Internal error while trying to import model [%s]", report.getModel().getId()), MessageSeverity.WARNING));
report.setValid(false);
}
}
});
}
use of org.eclipse.vorto.repository.core.ModelInfo in project vorto by eclipse.
the class ModelSequencer method execute.
@Override
public boolean execute(Property inputProperty, Node fileNode, Context context) throws Exception {
final Node folderNode = fileNode.getParent();
Binary binaryValue = inputProperty.getBinary();
CheckArg.isNotNull(binaryValue, "binary");
IModelParser parser = ModelParserFactory.instance().getParser(fileNode.getPath());
ModelInfo modelResource = parser.parse(binaryValue.getStream());
fileNode.setProperty("vorto:description", modelResource.getDescription() != null ? modelResource.getDescription() : "");
fileNode.setProperty("vorto:type", modelResource.getType().name());
fileNode.setProperty("vorto:displayname", modelResource.getDisplayName());
fileNode.setProperty("vorto:version", modelResource.getId().getVersion());
fileNode.setProperty("vorto:namespace", modelResource.getId().getNamespace());
fileNode.setProperty("vorto:name", modelResource.getId().getName());
if (modelResource.getType() == ModelType.Mapping) {
MappingModel mappingModel = (MappingModel) ((ModelResource) modelResource).getModel();
fileNode.setProperty("vorto:targetplatform", mappingModel.getTargetPlatform());
}
folderNode.addMixin("mix:referenceable");
folderNode.addMixin("vorto:meta");
folderNode.setProperty("vorto:namespace", modelResource.getId().getNamespace());
folderNode.setProperty("vorto:type", modelResource.getType().name());
folderNode.setProperty("vorto:name", modelResource.getId().getName());
if (folderNode.hasProperty("vorto:references")) {
// first remove any previous references of the node.
folderNode.getProperty("vorto:references").remove();
folderNode.getSession().save();
}
Optional<Value[]> referencesAsValues = getReferencesAsValues(folderNode, modelResource.getReferences());
if (referencesAsValues.isPresent()) {
folderNode.setProperty("vorto:references", referencesAsValues.get());
}
return true;
}
use of org.eclipse.vorto.repository.core.ModelInfo in project vorto by eclipse.
the class DefaultResolver method doResolve.
@Override
protected ModelId doResolve(String tenantId, ModelInfo mappingModelResource, ResolveQuery query) {
ModelFileContent content = getRepositoryFactory().getRepository(tenantId).getModelContent(mappingModelResource.getId(), false);
MappingModel mappingModel = (MappingModel) content.getModel();
Optional<MappingRule> objectRule = mappingModel.getRules().stream().filter(rule -> rule.getTarget() instanceof StereoTypeTarget && ((StereoTypeTarget) rule.getTarget()).getName().equals(query.getStereoType())).findFirst();
if (objectRule.isPresent()) {
Optional<Attribute> objectIdAttribute = ((StereoTypeTarget) objectRule.get().getTarget()).getAttributes().stream().filter(attribute -> attribute.getName().equals(query.getAttributeId())).findFirst();
if (objectIdAttribute.isPresent() && objectIdAttribute.get().getValue().equals(query.getAttributeValue())) {
return ModelId.fromReference(mappingModel.getReferences().get(0).getImportedNamespace(), mappingModel.getReferences().get(0).getVersion());
}
}
return null;
}
Aggregations