Search in sources :

Example 6 with ModelInfo

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);
            }
        }
    }
}
Also used : IModelRepository(org.eclipse.vorto.repository.core.IModelRepository) ModelInfo(org.eclipse.vorto.repository.core.ModelInfo) WorkflowException(org.eclipse.vorto.repository.workflow.WorkflowException) ModelId(org.eclipse.vorto.model.ModelId)

Example 7 with ModelInfo

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;
}
Also used : ModelInfo(org.eclipse.vorto.repository.core.ModelInfo) ArrayList(java.util.ArrayList) ModelId(org.eclipse.vorto.model.ModelId)

Example 8 with ModelInfo

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);
            }
        }
    });
}
Also used : IModelRepository(org.eclipse.vorto.repository.core.IModelRepository) ModelInfo(org.eclipse.vorto.repository.core.ModelInfo) IOException(java.io.IOException) BulkUploadException(org.eclipse.vorto.repository.web.core.exceptions.BulkUploadException)

Example 9 with ModelInfo

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;
}
Also used : IModelParser(org.eclipse.vorto.repository.core.impl.parser.IModelParser) ModelInfo(org.eclipse.vorto.repository.core.ModelInfo) Node(javax.jcr.Node) Binary(javax.jcr.Binary) MappingModel(org.eclipse.vorto.core.api.model.mapping.MappingModel)

Example 10 with ModelInfo

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;
}
Also used : ModelFileContent(org.eclipse.vorto.repository.core.ModelFileContent) ResolveQuery(org.eclipse.vorto.repository.web.core.dto.ResolveQuery) Service(org.springframework.stereotype.Service) MappingModel(org.eclipse.vorto.core.api.model.mapping.MappingModel) Optional(java.util.Optional) MappingRule(org.eclipse.vorto.core.api.model.mapping.MappingRule) StereoTypeTarget(org.eclipse.vorto.core.api.model.mapping.StereoTypeTarget) ModelId(org.eclipse.vorto.model.ModelId) Attribute(org.eclipse.vorto.core.api.model.mapping.Attribute) ModelInfo(org.eclipse.vorto.repository.core.ModelInfo) ModelFileContent(org.eclipse.vorto.repository.core.ModelFileContent) Attribute(org.eclipse.vorto.core.api.model.mapping.Attribute) MappingRule(org.eclipse.vorto.core.api.model.mapping.MappingRule) StereoTypeTarget(org.eclipse.vorto.core.api.model.mapping.StereoTypeTarget) MappingModel(org.eclipse.vorto.core.api.model.mapping.MappingModel)

Aggregations

ModelInfo (org.eclipse.vorto.repository.core.ModelInfo)89 Test (org.junit.Test)33 IUserContext (org.eclipse.vorto.repository.core.IUserContext)32 ModelId (org.eclipse.vorto.model.ModelId)28 IModelRepository (org.eclipse.vorto.repository.core.IModelRepository)21 FileContent (org.eclipse.vorto.repository.core.FileContent)11 ClassPathResource (org.springframework.core.io.ClassPathResource)11 IOException (java.io.IOException)10 ByteArrayInputStream (java.io.ByteArrayInputStream)9 ArrayList (java.util.ArrayList)9 HashMap (java.util.HashMap)9 ModelNotFoundException (org.eclipse.vorto.repository.core.ModelNotFoundException)8 WorkflowException (org.eclipse.vorto.repository.workflow.WorkflowException)8 BeforeClass (org.junit.BeforeClass)7 ResponseEntity (org.springframework.http.ResponseEntity)7 List (java.util.List)6 Optional (java.util.Optional)6 ModelAlreadyExistsException (org.eclipse.vorto.repository.core.ModelAlreadyExistsException)6 NotAuthorizedException (org.eclipse.vorto.repository.web.core.exceptions.NotAuthorizedException)6 DependencyManager (org.eclipse.vorto.repository.core.impl.utils.DependencyManager)5