Search in sources :

Example 81 with ModelInfo

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

the class VisibilitySearchSimpleTest method beforeClass.

@BeforeClass
public static void beforeClass() throws Exception {
    testInfrastructure = new SearchTestInfrastructure();
    testInfrastructure.importModel(testInfrastructure.DATATYPE_MODEL);
    List<ModelInfo> model = testInfrastructure.getRepositoryFactory().getRepository(testInfrastructure.createUserContext("alex")).search("*");
    // this is arguably over-cautious, as the next statement would fail all tests anyway
    if (model.isEmpty()) {
        fail("Model is empty after importing.");
    }
    // "alex" user updates the only imported model's visibility to public
    ModelId updated = testInfrastructure.getRepositoryFactory().getRepository(testInfrastructure.createUserContext("alex")).updateVisibility(model.get(0).getId(), "Public");
    // importing another model as private
    testInfrastructure.importModel(testInfrastructure.INFORMATION_MODEL, testInfrastructure.createUserContext("alex", "playground"));
}
Also used : ModelInfo(org.eclipse.vorto.repository.core.ModelInfo) ModelId(org.eclipse.vorto.model.ModelId) BeforeClass(org.junit.BeforeClass)

Example 82 with ModelInfo

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

the class ModelPolicyManager method restorePolicyEntriesInternal.

/**
 * Restores the access policies. (https://github.com/eclipse/vorto/issues/2350)
 *
 * @param session
 * @throws RepositoryException
 */
private void restorePolicyEntriesInternal(Session session) {
    LOGGER.info("restorePolicyEntries");
    if (this.modelRepositoryFactory == null) {
        return;
    }
    IModelRepository repo = this.modelRepositoryFactory.getRepository(session.getWorkspace().getName());
    List<ModelInfo> modelList = repo.search("");
    Map<String, IWorkflowFunction[]> stateToFunctionsMap = createStateToFunctionsMap();
    for (ModelInfo model : modelList) {
        applyWorkflowFunctions(model, session, stateToFunctionsMap);
        setVisibility(model);
    }
}
Also used : IModelRepository(org.eclipse.vorto.repository.core.IModelRepository) ModelInfo(org.eclipse.vorto.repository.core.ModelInfo)

Example 83 with ModelInfo

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

the class ModelRepositoryEventListener method makeModelsAnonymous.

private void makeModelsAnonymous(AppEvent event) {
    String username = (String) event.getSubject();
    IUserContext technicalUserContext = PrivilegedUserContextProvider.systemAdminContext(USER_ADMIN);
    List<ModelInfo> result = searchService.search("userReference:" + username, technicalUserContext);
    result.forEach(model -> {
        IModelRepository repository = repositoryFactory.getRepositoryByModel(model.getId(), technicalUserContext);
        if (model.getAuthor() != null && model.getAuthor().equals(username)) {
            model.setAuthor(User.USER_ANONYMOUS);
        }
        Map<String, String> properties = new HashMap<>();
        properties.put(VORTO_AUTHOR, User.USER_ANONYMOUS);
        repository.updatePropertyInElevatedSession(model.getId(), properties, technicalUserContext);
    });
}
Also used : IModelRepository(org.eclipse.vorto.repository.core.IModelRepository) IUserContext(org.eclipse.vorto.repository.core.IUserContext) ModelInfo(org.eclipse.vorto.repository.core.ModelInfo) HashMap(java.util.HashMap)

Example 84 with ModelInfo

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

the class DefaultCommentService method notifyAllCommentAuthors.

private void notifyAllCommentAuthors(Comment comment, ModelInfo model) {
    Set<String> recipients = new HashSet<>();
    recipients.add(model.getAuthor());
    List<Comment> existingComments = this.commentRepository.findByModelId(comment.getModelId());
    for (Comment c : existingComments) {
        recipients.add(c.getAuthor());
    }
    recipients.stream().filter(recipient -> !User.USER_ANONYMOUS.equalsIgnoreCase(recipient)).forEach(recipient -> {
        User user = accountService.getUser(recipient);
        if (user != null) {
            notificationService.sendNotification(new CommentReplyMessage(user, model, comment.getContent()));
        }
    });
}
Also used : DoesNotExistException(org.eclipse.vorto.repository.services.exceptions.DoesNotExistException) Date(java.util.Date) ModelNotFoundException(org.eclipse.vorto.repository.core.ModelNotFoundException) Set(java.util.Set) Autowired(org.springframework.beans.factory.annotation.Autowired) ICommentService(org.eclipse.vorto.repository.comment.ICommentService) User(org.eclipse.vorto.repository.domain.User) ModelId(org.eclipse.vorto.model.ModelId) IModelRepository(org.eclipse.vorto.repository.core.IModelRepository) ModelInfo(org.eclipse.vorto.repository.core.ModelInfo) NamespaceService(org.eclipse.vorto.repository.services.NamespaceService) HashSet(java.util.HashSet) CommentReplyMessage(org.eclipse.vorto.repository.notification.message.CommentReplyMessage) List(java.util.List) PathNotFoundException(javax.jcr.PathNotFoundException) ModelRepositoryFactory(org.eclipse.vorto.repository.core.impl.ModelRepositoryFactory) Service(org.springframework.stereotype.Service) Optional(java.util.Optional) INotificationService(org.eclipse.vorto.repository.notification.INotificationService) DefaultUserAccountService(org.eclipse.vorto.repository.account.impl.DefaultUserAccountService) Comment(org.eclipse.vorto.repository.domain.Comment) IModelRepositoryFactory(org.eclipse.vorto.repository.core.IModelRepositoryFactory) Comment(org.eclipse.vorto.repository.domain.Comment) User(org.eclipse.vorto.repository.domain.User) CommentReplyMessage(org.eclipse.vorto.repository.notification.message.CommentReplyMessage) HashSet(java.util.HashSet)

Example 85 with ModelInfo

use of org.eclipse.vorto.repository.core.ModelInfo 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

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