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);
}
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);
}
}
}
}
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;
}
}
}
}
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);
}
}
}
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;
}
Aggregations