use of org.eclipse.vorto.repository.core.ModelInfo in project vorto by eclipse.
the class ModelRepositoryController method getUserModels.
// ##################### Downloads ################################
@GetMapping(value = { "/mine/download" })
public void getUserModels(Principal principal, final HttpServletResponse response) {
List<ModelId> userModels = Lists.newArrayList();
User user = accountService.getUser(principal.getName());
Collection<Namespace> namespaces = null;
try {
namespaces = userNamespaceRoleService.getNamespaces(user, user);
} catch (OperationForbiddenException | DoesNotExistException e) {
LOGGER.error(e.getMessage(), e);
}
for (Namespace namespace : namespaces) {
IModelRepository modelRepo = getModelRepository(namespace.getWorkspaceId());
List<ModelInfo> modelInfos = modelRepo.search(String.format("author:%s", user.getUsername()));
List<ModelId> modelIds = modelInfos.stream().map(modelInfo -> modelInfo.getId()).collect(Collectors.toList());
userModels.addAll(modelIds);
}
LOGGER.info("Exporting information models for user - results: " + userModels.size());
sendAsZipFile(response, user.getUsername() + "-models.zip", getModelsAndDependencies(userModels));
}
use of org.eclipse.vorto.repository.core.ModelInfo in project vorto by eclipse.
the class ModelRepositoryController method downloadMappingsForPlatform.
@ApiOperation(value = "Getting all mapping resources for the given model")
@PreAuthorize("isAuthenticated() or hasPermission(T(org.eclipse.vorto.model.ModelId).fromPrettyFormat(#modelId), 'model:get')")
@GetMapping("/{modelId:.+}/download/mappings/{targetPlatform}")
public ResponseEntity<Boolean> downloadMappingsForPlatform(@ApiParam(value = "The model ID of vorto model, e.g. com.mycompany.Car:1.0.0", required = true) @PathVariable final String modelId, @ApiParam(value = "The name of target platform, e.g. lwm2m", required = true) @PathVariable final String targetPlatform, final HttpServletResponse response) {
Objects.requireNonNull(modelId, "model ID must not be null");
final ModelId modelID = ModelId.fromPrettyFormat(modelId);
try {
IModelRepository modelRepository = getModelRepository(modelID);
if (modelRepository.getById(modelID) == null) {
return new ResponseEntity<>(false, HttpStatus.NOT_FOUND);
}
List<ModelInfo> mappingResources = modelRepository.getMappingModelsForTargetPlatform(modelID, ControllerUtils.sanitize(targetPlatform), Optional.empty());
List<ModelId> mappingModelIds = mappingResources.stream().map(ModelInfo::getId).collect(Collectors.toList());
final String fileName = modelID.getNamespace() + "_" + modelID.getName() + "_" + modelID.getVersion() + ".zip";
sendAsZipFile(response, fileName, getModelsAndDependencies(mappingModelIds));
return new ResponseEntity<>(true, HttpStatus.OK);
} catch (FatalModelRepositoryException ex) {
return new ResponseEntity<>(false, HttpStatus.NOT_FOUND);
}
}
use of org.eclipse.vorto.repository.core.ModelInfo in project vorto by eclipse.
the class ModelRepositoryController method refactorModelId.
@PutMapping(value = "/refactorings/{oldId:.+}/{newId:.+}", produces = "application/json")
@PreAuthorize("hasAuthority('sysadmin') or " + "hasPermission(T(org.eclipse.vorto.model.ModelId).fromPrettyFormat(#oldId)," + "T(org.eclipse.vorto.repository.core.PolicyEntry.Permission).MODIFY)")
public ResponseEntity<ModelInfo> refactorModelId(@PathVariable String oldId, @PathVariable String newId) {
final ModelId oldModelId = ModelId.fromPrettyFormat(oldId);
final ModelId newModelId = ModelId.fromPrettyFormat(newId);
IUserContext userContext = UserContext.user(SecurityContextHolder.getContext().getAuthentication(), getWorkspaceId(oldId));
ModelInfo result = this.modelRepositoryFactory.getRepositoryByModel(oldModelId).rename(oldModelId, newModelId, userContext);
return new ResponseEntity<>(result, HttpStatus.OK);
}
use of org.eclipse.vorto.repository.core.ModelInfo in project vorto by eclipse.
the class ModelRepositoryController method createModel.
@ApiOperation(value = "Creates a model in the repository with the given model ID and model type.")
@PostMapping(value = "/{modelId:.+}/{modelType}", produces = "application/json")
public ResponseEntity<ModelInfo> createModel(@ApiParam(value = "modelId", required = true) @PathVariable String modelId, @ApiParam(value = "modelType", required = true) @PathVariable ModelType modelType, @RequestBody(required = false) List<ModelProperty> properties) throws WorkflowException {
final ModelId modelID = ModelId.fromPrettyFormat(modelId);
Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
IUserContext userContext = UserContext.user(authentication, getWorkspaceId(modelId));
IModelRepository modelRepo = getModelRepository(modelID);
if (modelRepo.exists(modelID)) {
throw new ModelAlreadyExistsException();
} else {
String modelTemplate = null;
if (modelType == ModelType.InformationModel && properties != null) {
modelTemplate = new InfomodelTemplate().createModelTemplate(modelID, properties);
} else {
modelTemplate = new ModelTemplate().createModelTemplate(modelID, modelType);
}
ModelInfo savedModel = modelRepo.save(modelID, modelTemplate.getBytes(), modelID.getName() + modelType.getExtension(), userContext);
this.workflowService.start(modelID, userContext);
return new ResponseEntity<>(savedModel, HttpStatus.CREATED);
}
}
use of org.eclipse.vorto.repository.core.ModelInfo in project vorto by eclipse.
the class ModelDtoFactory method createDto.
public static ModelInfo createDto(ModelInfo resource) {
ModelInfo dto = new ModelInfo(createDto(resource.getId()), ModelType.valueOf(resource.getType().name()));
copy(resource, dto);
return dto;
}
Aggregations