Search in sources :

Example 1 with ModelId

use of org.eclipse.vorto.model.ModelId in project vorto by eclipse.

the class ModelRepository method doGetLinksInSession.

private Set<ModelLink> doGetLinksInSession(ModelId modelID, Session session) throws RepositoryException {
    ObjectMapper objectMapper = ObjectMapperFactory.getInstance();
    Node fileNode = getFileNode(modelID, session);
    if (fileNode.hasProperty(VORTO_LINKS)) {
        return getVortoLinksPropertyValues(fileNode.getProperty(VORTO_LINKS)).stream().map(value -> deserializeLinkDto(objectMapper, value)).collect(Collectors.toSet());
    }
    return Collections.emptySet();
}
Also used : DependencyManager(org.eclipse.vorto.repository.core.impl.utils.DependencyManager) java.util(java.util) EventType(org.eclipse.vorto.repository.core.events.EventType) javax.jcr.query(javax.jcr.query) AppEvent(org.eclipse.vorto.repository.core.events.AppEvent) Function(java.util.function.Function) ModelLink(org.eclipse.vorto.repository.web.api.v1.dto.ModelLink) Model(org.eclipse.vorto.core.api.model.model.Model) Logger(org.apache.log4j.Logger) Lists(com.google.common.collect.Lists) ObjectMapperFactory(org.eclipse.vorto.plugin.generator.adapter.ObjectMapperFactory) ByteArrayInputStream(java.io.ByteArrayInputStream) IModelWorkspace(org.eclipse.vorto.utilities.reader.IModelWorkspace) ApplicationEventPublisher(org.springframework.context.ApplicationEventPublisher) org.eclipse.vorto.repository.core(org.eclipse.vorto.repository.core) ModelState(org.eclipse.vorto.repository.workflow.ModelState) ModelParserFactory(org.eclipse.vorto.repository.core.impl.parser.ModelParserFactory) Attachment(org.eclipse.vorto.repository.core.Attachment) PrivilegeService(org.eclipse.vorto.repository.services.PrivilegeService) ApplicationEventPublisherAware(org.springframework.context.ApplicationEventPublisherAware) ModelSearchUtil(org.eclipse.vorto.repository.core.impl.utils.ModelSearchUtil) ModelIdHelper(org.eclipse.vorto.repository.core.impl.utils.ModelIdHelper) ModelReferencesHelper(org.eclipse.vorto.repository.core.impl.utils.ModelReferencesHelper) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) NotAuthorizedException(org.eclipse.vorto.repository.web.core.exceptions.NotAuthorizedException) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) IOException(java.io.IOException) ModelId(org.eclipse.vorto.model.ModelId) ValidationException(org.eclipse.vorto.repository.core.impl.validation.ValidationException) Namespace(org.eclipse.vorto.repository.domain.Namespace) Collectors(java.util.stream.Collectors) ModelType(org.eclipse.vorto.model.ModelType) NamespaceService(org.eclipse.vorto.repository.services.NamespaceService) IOUtils(org.apache.commons.io.IOUtils) ChangeSet(org.eclipse.vorto.model.refactor.ChangeSet) RefactoringTask(org.eclipse.vorto.model.refactor.RefactoringTask) AttachmentValidator(org.eclipse.vorto.repository.core.impl.validation.AttachmentValidator) ModelWorkspaceReader(org.eclipse.vorto.utilities.reader.ModelWorkspaceReader) NewNamespacesNotSupersetException(org.eclipse.vorto.repository.tenant.NewNamespacesNotSupersetException) ModelUtils(org.eclipse.vorto.repository.utils.ModelUtils) IModelParser(org.eclipse.vorto.repository.core.impl.parser.IModelParser) javax.jcr(javax.jcr) InputStream(java.io.InputStream) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 2 with ModelId

use of org.eclipse.vorto.model.ModelId in project vorto by eclipse.

the class NamespaceRequestCache method namespace.

/**
 * Resolves a cached {@link Namespace} by name if applicable.<br/>
 * This will also attempt to resolve a "virtual" namespace string, consisting in the real
 * namespace appended with an arbitrary number of {@literal .[sub-namespace]} strings to the
 * root namespace.<br/>
 * The latter is useful when invoking e.g. {@link NamespaceService#getByName(String)} with
 * {@link ModelId#getNamespace()} since the latter does not trim out the "virtual" sub-namespaces.
 * <br/>
 * For instance, when given {@literal com.bosch.iot.suite.example.octopussuiteedition}:
 * <ol>
 *   <li>
 *     Attempts to resolve {@literal com.bosch.iot.suite.example.octopussuiteedition} and get
 *     its workspace ID, which fails
 *   </li>
 *   <li>
 *     Attempts to resolve {@literal com.bosch.iot.suite.example} and get its workspace ID, which
 *     fails again
 *   </li>
 *   <li>
 *     Attempts to resolve {@literal com.bosch.iot.suite} and get its workspace ID, which
 *     succeeds
 *   </li>
 * </ol>
 * Note: virtual namespaces are cached within the scope of a request. <br/>
 *
 * @param name
 * @return
 */
public Optional<Namespace> namespace(String name) {
    // boilerplate null/empty checks
    if (Objects.isNull(name) || name.trim().isEmpty()) {
        return Optional.empty();
    }
    // lazy population
    populateIfEmpty();
    // lookup into virtual namespace map first
    if (virtualNamespaces.containsKey(name)) {
        Namespace result = virtualNamespaces.get(name);
        LOGGER.debug(String.format("Resolved virtual namespace [%s] to [%s]", name, result.getName()));
        return Optional.of(result);
    }
    // resolving by name equality
    Optional<Namespace> result = this.namespaces.stream().filter(n -> n.getName().equals(name)).findAny();
    if (result.isPresent()) {
        LOGGER.debug(String.format("Resolved namespace [%s]", name));
        return result;
    } else {
        return resolveVirtualNamespaceRecursively(name, name);
    }
}
Also used : Predicate(java.util.function.Predicate) Collection(java.util.Collection) RequestScope(org.springframework.web.context.annotation.RequestScope) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Autowired(org.springframework.beans.factory.annotation.Autowired) Collectors(java.util.stream.Collectors) ModelId(org.eclipse.vorto.model.ModelId) Namespace(org.eclipse.vorto.repository.domain.Namespace) NAMESPACE_SEPARATOR(org.eclipse.vorto.repository.services.NamespaceService.NAMESPACE_SEPARATOR) NamespaceService(org.eclipse.vorto.repository.services.NamespaceService) Objects(java.util.Objects) Logger(org.apache.log4j.Logger) NamespaceRepository(org.eclipse.vorto.repository.repositories.NamespaceRepository) Service(org.springframework.stereotype.Service) Map(java.util.Map) Optional(java.util.Optional) Collections(java.util.Collections) PRIVATE_NAMESPACE_PREFIX(org.eclipse.vorto.repository.services.NamespaceService.PRIVATE_NAMESPACE_PREFIX) Namespace(org.eclipse.vorto.repository.domain.Namespace)

Example 3 with ModelId

use of org.eclipse.vorto.model.ModelId 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)

Example 4 with ModelId

use of org.eclipse.vorto.model.ModelId in project vorto by eclipse.

the class BulkUploadHelper method trytoCreateModelFromCorruptFile.

// TODO: try to guess the modelinfo based on the content of the file, instead of the filename
private ModelInfo trytoCreateModelFromCorruptFile(String fileName) {
    try {
        final String modelName = fileName.substring(0, fileName.lastIndexOf("."));
        final ModelType type = ModelType.fromFileName(fileName);
        return new ModelInfo(new ModelId(modelName, "unknown", "unknown"), type);
    } catch (Throwable t) {
        return null;
    }
}
Also used : ModelType(org.eclipse.vorto.model.ModelType) ModelId(org.eclipse.vorto.model.ModelId)

Example 5 with ModelId

use of org.eclipse.vorto.model.ModelId in project vorto by eclipse.

the class MetadataIntegrityDiagnostic method checkModelType.

private Optional<Diagnostic> checkModelType(final Node node) {
    ModelId modelId = null;
    try {
        modelId = NodeDiagnosticUtils.getModelId(node.getPath()).orElseThrow(() -> new NodeDiagnosticException("Cannot get modelId of node"));
        ModelType fileModelType = ModelType.create(node.getName());
        ModelType nodeModelType = ModelType.valueOf(node.getProperty("vorto:type").getString());
        if (!fileModelType.equals(nodeModelType)) {
            String message = new StringBuilder("The model type should be '").append(fileModelType.name()).append("' but is '").append(nodeModelType.name()).append("'").toString();
            return Optional.of(new Diagnostic(modelId, message));
        }
        return Optional.empty();
    } catch (RepositoryException e) {
        return Optional.of(new Diagnostic(modelId, "Got exception while checking node 'vorto:type' : " + e.getMessage()));
    }
}
Also used : ModelType(org.eclipse.vorto.core.api.model.model.ModelType) Diagnostic(org.eclipse.vorto.repository.core.Diagnostic) NodeDiagnostic(org.eclipse.vorto.repository.core.impl.RepositoryDiagnostics.NodeDiagnostic) RepositoryException(javax.jcr.RepositoryException) ModelId(org.eclipse.vorto.model.ModelId)

Aggregations

ModelId (org.eclipse.vorto.model.ModelId)124 Test (org.junit.Test)48 ModelInfo (org.eclipse.vorto.repository.core.ModelInfo)29 IOException (java.io.IOException)28 ClassPathResource (org.springframework.core.io.ClassPathResource)25 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)19 ByteArrayInputStream (java.io.ByteArrayInputStream)14 ResponseEntity (org.springframework.http.ResponseEntity)14 IModelRepository (org.eclipse.vorto.repository.core.IModelRepository)13 ModelType (org.eclipse.vorto.model.ModelType)12 IUserContext (org.eclipse.vorto.repository.core.IUserContext)12 Autowired (org.springframework.beans.factory.annotation.Autowired)12 GetMapping (org.springframework.web.bind.annotation.GetMapping)11 Optional (java.util.Optional)10 List (java.util.List)9 IOUtils (org.apache.commons.io.IOUtils)9 ValidationException (org.eclipse.vorto.repository.core.impl.validation.ValidationException)9 ModelLink (org.eclipse.vorto.repository.web.api.v1.dto.ModelLink)9 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)8 ApiOperation (io.swagger.annotations.ApiOperation)8