Search in sources :

Example 6 with ModelNotFoundException

use of org.eclipse.vorto.repository.core.ModelNotFoundException in project vorto by eclipse.

the class DefaultCommentService method createComment.

public void createComment(Comment comment) throws DoesNotExistException {
    final ModelId id = ModelId.fromPrettyFormat(comment.getModelId());
    Optional<String> workspaceId = namespaceService.resolveWorkspaceIdForNamespace(id.getNamespace());
    if (!workspaceId.isPresent()) {
        throw new DoesNotExistException(String.format("Namespace [%s] does not exist.", id.getNamespace()));
    }
    IModelRepository modelRepo = modelRepositoryFactory.getRepository(workspaceId.get());
    if (modelRepo.exists(id)) {
        comment.setAuthor(comment.getAuthor());
        comment.setModelId(id.getPrettyFormat());
        comment.setDate(new Date());
        commentRepository.save(comment);
        notifyAllCommentAuthors(comment, modelRepo.getById(id));
    } else {
        throw new ModelNotFoundException("Model not found", new PathNotFoundException());
    }
}
Also used : IModelRepository(org.eclipse.vorto.repository.core.IModelRepository) DoesNotExistException(org.eclipse.vorto.repository.services.exceptions.DoesNotExistException) ModelNotFoundException(org.eclipse.vorto.repository.core.ModelNotFoundException) PathNotFoundException(javax.jcr.PathNotFoundException) ModelId(org.eclipse.vorto.model.ModelId) Date(java.util.Date)

Example 7 with ModelNotFoundException

use of org.eclipse.vorto.repository.core.ModelNotFoundException in project vorto by eclipse.

the class ModelIdToModelContentConverter method convert.

@Override
public ModelContent convert(ModelId modelId, Optional<String> platformKey) {
    modelId = repositoryFactory.getRepositoryByNamespace(modelId.getNamespace()).getLatestModelVersionIfLatestTagIsSet(modelId);
    if (!repositoryFactory.getRepositoryByModel(modelId).exists(modelId)) {
        throw new ModelNotFoundException(String.format("Model [%s] does not exist", modelId.getPrettyFormat()), null);
    }
    ModelWorkspaceReader workspaceReader = getWorkspaceForModel(modelId);
    ModelContent result = new ModelContent();
    result.setRoot(modelId);
    if (platformKey.isPresent()) {
        final List<ModelInfo> mappingResources = repositoryFactory.getRepositoryByModel(modelId).getMappingModelsForTargetPlatform(modelId, platformKey.get(), Optional.empty());
        if (!mappingResources.isEmpty()) {
            // adding to workspace reader in order to resolve cross linking between mapping models correctly
            mappingResources.forEach(mapping -> workspaceReader.addFile(new ByteArrayInputStream(repositoryFactory.getRepositoryByModel(mapping.getId()).getFileContent(mapping.getId(), Optional.empty()).get().getContent()), org.eclipse.vorto.model.ModelType.Mapping));
            final IModelWorkspace workspace = workspaceReader.read();
            workspace.get().forEach(model -> {
                Optional<MappingModel> mappingModel = getMappingModelForModel(mappingResources, model);
                if (mappingModel.isPresent()) {
                    AbstractModel createdModel = ModelDtoFactory.createResource(flattenHierarchy(model), mappingModel);
                    createdModel.setTargetPlatformKey(platformKey.get());
                    result.getModels().put(new ModelId(model.getName(), model.getNamespace(), model.getVersion()), createdModel);
                } else {
                    result.getModels().put(new ModelId(model.getName(), model.getNamespace(), model.getVersion()), ModelDtoFactory.createResource(flattenHierarchy(model), Optional.empty()));
                }
            });
        } else {
            final IModelWorkspace workspace = workspaceReader.read();
            workspace.get().forEach(model -> {
                AbstractModel createdModel = ModelDtoFactory.createResource(flattenHierarchy(model), Optional.empty());
                createdModel.setTargetPlatformKey(platformKey.get());
                result.getModels().put(new ModelId(model.getName(), model.getNamespace(), model.getVersion()), createdModel);
            });
        }
    } else {
        final IModelWorkspace workspace = workspaceReader.read();
        workspace.get().forEach(model -> {
            AbstractModel createdModel = ModelDtoFactory.createResource(flattenHierarchy(model), Optional.empty());
            result.getModels().put(new ModelId(model.getName(), model.getNamespace(), model.getVersion()), createdModel);
        });
    }
    return result;
}
Also used : ModelInfo(org.eclipse.vorto.repository.core.ModelInfo) ModelWorkspaceReader(org.eclipse.vorto.utilities.reader.ModelWorkspaceReader) ByteArrayInputStream(java.io.ByteArrayInputStream) ModelContent(org.eclipse.vorto.model.ModelContent) AbstractModel(org.eclipse.vorto.model.AbstractModel) ModelNotFoundException(org.eclipse.vorto.repository.core.ModelNotFoundException) IModelWorkspace(org.eclipse.vorto.utilities.reader.IModelWorkspace) ModelId(org.eclipse.vorto.model.ModelId)

Aggregations

ModelId (org.eclipse.vorto.model.ModelId)7 ModelNotFoundException (org.eclipse.vorto.repository.core.ModelNotFoundException)7 ModelInfo (org.eclipse.vorto.repository.core.ModelInfo)5 ModelContent (org.eclipse.vorto.model.ModelContent)3 IModelRepository (org.eclipse.vorto.repository.core.IModelRepository)3 ByteArrayInputStream (java.io.ByteArrayInputStream)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 List (java.util.List)2 Map (java.util.Map)2 Optional (java.util.Optional)2 ModelIdToModelContentConverter (org.eclipse.vorto.repository.conversion.ModelIdToModelContentConverter)2 IModelRepositoryFactory (org.eclipse.vorto.repository.core.IModelRepositoryFactory)2 IUserContext (org.eclipse.vorto.repository.core.IUserContext)2 IModelWorkspace (org.eclipse.vorto.utilities.reader.IModelWorkspace)2 ModelWorkspaceReader (org.eclipse.vorto.utilities.reader.ModelWorkspaceReader)2 Autowired (org.springframework.beans.factory.annotation.Autowired)2 Service (org.springframework.stereotype.Service)2 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1