Search in sources :

Example 11 with ModelInfo

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

the class ModelIdToModelContentConverter method getWorkspaceForModel.

private ModelWorkspaceReader getWorkspaceForModel(final ModelId modelId) {
    Collection<ModelInfo> allModels = getModelWithAllDependencies(modelId);
    DependencyManager dm = new DependencyManager(new HashSet<>(allModels));
    allModels = dm.getSorted();
    ModelWorkspaceReader workspaceReader = IModelWorkspace.newReader();
    for (ModelInfo model : allModels) {
        FileContent modelContent = repositoryFactory.getRepositoryByModel(model.getId()).getFileContent(model.getId(), Optional.of(model.getFileName())).get();
        workspaceReader.addFile(new ByteArrayInputStream(modelContent.getContent()), model.getType());
    }
    return workspaceReader;
}
Also used : FileContent(org.eclipse.vorto.repository.core.FileContent) ModelInfo(org.eclipse.vorto.repository.core.ModelInfo) ModelWorkspaceReader(org.eclipse.vorto.utilities.reader.ModelWorkspaceReader) ByteArrayInputStream(java.io.ByteArrayInputStream) DependencyManager(org.eclipse.vorto.repository.core.impl.utils.DependencyManager)

Example 12 with ModelInfo

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

the class ModelInfoRetrieverTask method compute.

@Override
protected List<ModelInfo> compute() {
    RequestContextHolder.setRequestAttributes(requestAttributes, true);
    SecurityContextHolder.setContext(securityContext);
    ModelInfo modelInfo = factory.getRepositoryByModelWithoutSessionHelper(rootID).getById(rootID);
    if (Objects.nonNull(modelInfo)) {
        modelInfos.add(modelInfo);
        if (!modelInfo.getReferences().isEmpty()) {
            modelInfos.addAll(processChildren(modelInfo));
        }
    }
    return modelInfos;
}
Also used : ModelInfo(org.eclipse.vorto.repository.core.ModelInfo)

Example 13 with ModelInfo

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

the class MixedSearchTest method testSearchAllModelsWithWildCard.

@Test
public void testSearchAllModelsWithWildCard() {
    assertEquals(4, testInfrastructure.getSearchService().search("*").size());
    ModelInfo model = testInfrastructure.getSearchService().search("*").stream().filter(m -> m.getId().getName().equals("ColorLight")).findAny().get();
    assertEquals(1, model.getReferences().size());
}
Also used : ModelInfo(org.eclipse.vorto.repository.core.ModelInfo) Test(org.junit.Test)

Example 14 with ModelInfo

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

the class DefaultWorkflowService method doAction.

@Override
public ModelInfo doAction(ModelId model, IUserContext user, String actionName) throws WorkflowException {
    ModelInfo modelInfo = getModelRepository(user).getById(model);
    final Optional<IState> state = SIMPLE_WORKFLOW.getState(modelInfo.getState());
    final Optional<IAction> action = state.get().getAction(actionName);
    if (action.isPresent() && isValidInput(modelInfo, action.get(), user) && passesConditions(action.get().getConditions(), modelInfo, user)) {
        // test
        IAction actionTest = action.get();
        final IState newState = action.get().getTo();
        modelInfo.setState(newState.getName());
        ModelInfo updatedInfo = getModelRepository(user).updateMeta(modelInfo);
        Map<String, Object> ctx = new HashMap<>();
        action.get().getFunctions().stream().forEach(a -> executeFunction(a, modelInfo, user, ctx));
        return updatedInfo;
    } else {
        throw new WorkflowException(modelInfo, "The given action is invalid.");
    }
}
Also used : IState(org.eclipse.vorto.repository.workflow.model.IState) ModelInfo(org.eclipse.vorto.repository.core.ModelInfo) IAction(org.eclipse.vorto.repository.workflow.model.IAction) HashMap(java.util.HashMap) WorkflowException(org.eclipse.vorto.repository.workflow.WorkflowException)

Example 15 with ModelInfo

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

the class BulkApproveFunction 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.InReview.getName().equals(referenceModel.getState())) {
            try {
                workflowService.doAction(referenceId, user, SimpleWorkflowModel.ACTION_APPROVE.getName());
            } catch (WorkflowException e) {
                logger.error("Problem executing release for model " + referenceId + "during bulk approve 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)

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