Search in sources :

Example 11 with ModelId

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

the class AttachmentController method deleteLink.

@DeleteMapping("/{modelId:.+}/links")
@PreAuthorize("hasAuthority('sysadmin') or " + "hasPermission(T(org.eclipse.vorto.model.ModelId).fromPrettyFormat(#modelId)," + "T(org.eclipse.vorto.repository.core.PolicyEntry.Permission).MODIFY)")
public ResponseEntity<Void> deleteLink(@ApiParam(value = "The ID of the vorto model in namespace.name:version format, e.g. com.mycompany:MagneticSensor:1.0.0", required = true) @PathVariable String modelId, @ApiParam(value = "The URL to be deleted", required = true) @RequestBody ModelLink url) {
    ModelId modelID = ModelId.fromPrettyFormat(modelId);
    getModelRepository(modelID).deleteLink(modelID, url);
    return new ResponseEntity<>(HttpStatus.OK);
}
Also used : ResponseEntity(org.springframework.http.ResponseEntity) ModelId(org.eclipse.vorto.model.ModelId) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Example 12 with ModelId

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

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

Example 13 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 14 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)

Example 15 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)

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