Search in sources :

Example 51 with ModelId

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

the class ModelIdTest method testValidModelId.

@Test
public void testValidModelId() {
    String modelId = "com.bosch:Test:1.0.0";
    assertEquals(new ModelId("Test", "com.bosch", "1.0.0"), ModelId.fromPrettyFormat(modelId));
}
Also used : ModelId(org.eclipse.vorto.model.ModelId) Test(org.junit.Test)

Example 52 with ModelId

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

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

the class DefaultPayloadMappingService method saveSpecification.

@Override
public void saveSpecification(IMappingSpecification specification, IUserContext user) {
    MappingSpecificationSerializer.create(specification).iterator().forEachRemaining(serializer -> {
        final ModelId createdModelId = serializer.getModelId();
        String serializedMapping = serializer.serialize();
        LOGGER.trace(String.format("Saving mapping: %s", serializedMapping));
        this.modelRepositoryFactory.getRepositoryByModel(createdModelId).save(createdModelId, serializedMapping.getBytes(), createdModelId.getName() + ".mapping", user, false);
        try {
            workflowService.start(createdModelId, user);
        } catch (WorkflowException e) {
            throw new RuntimeException("Could not start workflow for mapping model", e);
        }
    });
}
Also used : WorkflowException(org.eclipse.vorto.repository.workflow.WorkflowException) ModelId(org.eclipse.vorto.model.ModelId)

Example 54 with ModelId

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

the class DefaultBulkOperationsService method revertToPrivate.

private void revertToPrivate(List<ModelId> accumulator) {
    for (ModelId modelId : accumulator) {
        IModelRepository repo = this.repositoryFactory.getRepositoryByModel(modelId);
        String tenantId = repo.getWorkspaceId();
        // changed back visibility property
        repo.updateVisibility(modelId, IModelRepository.VISIBILITY_PRIVATE);
        // remove added policy
        IModelPolicyManager policyManager = this.repositoryFactory.getPolicyManager(tenantId, getAuthenticationToken());
        Collection<PolicyEntry> policies = policyManager.getPolicyEntries(modelId);
        for (PolicyEntry policy : policies) {
            if (policy.getPrincipalId().equals(IModelPolicyManager.ANONYMOUS_ACCESS_POLICY)) {
                policyManager.removePolicyEntry(modelId, policy);
                break;
            }
        }
    }
}
Also used : ModelId(org.eclipse.vorto.model.ModelId)

Example 55 with ModelId

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

the class DefaultBulkOperationsService method makeModelPublicRecursively.

private void makeModelPublicRecursively(ModelId modelId, List<ModelId> modelsMadePublicAcc) throws ExecutionException {
    if (hasPrivateNamespace(modelId)) {
        throw new ModelNamespaceNotOfficialException(modelId);
    }
    IModelRepository repository = repositoryFactory.getRepositoryByModel(modelId);
    ModelInfo modelInfo = repository.getById(modelId);
    if (!modelInfo.isReleased()) {
        throw new ModelNotReleasedException(modelId);
    }
    if (isPrivate(modelInfo)) {
        LOGGER.info("Changing visibility of model " + modelId.getPrettyFormat() + " to public.");
        // Add public visibility property
        repository.updateVisibility(modelId, IModelRepository.VISIBILITY_PUBLIC);
        // Add corresponding policy to model
        IModelPolicyManager policyMgr = this.repositoryFactory.getPolicyManager(repository.getWorkspaceId(), getAuthenticationToken());
        policyMgr.addPolicyEntry(modelId, PolicyEntry.of(IModelPolicyManager.ANONYMOUS_ACCESS_POLICY, PrincipalType.User, Permission.READ));
        modelsMadePublicAcc.add(modelId);
        // Make references public
        for (ModelId referencedModelId : modelInfo.getReferences()) {
            makeModelPublicRecursively(referencedModelId, modelsMadePublicAcc);
        }
    }
}
Also used : ModelNamespaceNotOfficialException(org.eclipse.vorto.repository.model.ModelNamespaceNotOfficialException) ModelNotReleasedException(org.eclipse.vorto.repository.model.ModelNotReleasedException) 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