use of org.eclipse.vorto.repository.api.ModelId in project vorto by eclipse.
the class BackupController method deleteModelResource.
@RequestMapping(value = "/{namespace}/{name}/{version:.+}", method = RequestMethod.DELETE)
@PreAuthorize("hasRole('ROLE_ADMIN') or hasPermission(new org.eclipse.vorto.repository.api.ModelId(#name,#namespace,#version),'model:delete')")
public void deleteModelResource(@PathVariable final String namespace, @PathVariable final String name, @PathVariable final String version) {
Objects.requireNonNull(namespace, "namespace must not be null");
Objects.requireNonNull(name, "name must not be null");
Objects.requireNonNull(version, "version must not be null");
repositoryService.removeModel(new ModelId(name, namespace, version));
}
use of org.eclipse.vorto.repository.api.ModelId in project vorto by eclipse.
the class CommentController method getCommentsforModelId.
@ApiOperation(value = "Returns comments for a specific Model Resource")
@ApiResponses(value = { @ApiResponse(code = 404, message = "Not found"), @ApiResponse(code = 200, message = "OK") })
@RequestMapping(method = RequestMethod.GET, value = "/comments/model/{namespace}/{name}/{version:.+}", produces = "application/json")
public List<Comment> getCommentsforModelId(@ApiParam(value = "namespace", required = true) @PathVariable String namespace, @ApiParam(value = "name", required = true) @PathVariable String name, @ApiParam(value = "version", required = true) @PathVariable String version) {
final ModelId modelId = new ModelId(name, namespace, version);
List<Comment> comments = commentService.getCommentsforModelId(modelId);
return comments;
}
use of org.eclipse.vorto.repository.api.ModelId in project vorto by eclipse.
the class ModelDtoFactory method createResource.
public static Infomodel createResource(InformationModel model, Optional<MappingModel> mappingModel) {
Infomodel infoResource = new Infomodel(new ModelId(model.getName(), model.getNamespace(), model.getVersion()), ModelType.InformationModel);
for (FunctionblockProperty property : model.getProperties()) {
infoResource.getFunctionblocks().add(createProperty(property, mappingModel));
}
infoResource.setDescription(model.getDescription());
infoResource.setDisplayName(model.getDisplayname());
infoResource.setReferences(model.getReferences().stream().map(reference -> createModelId(reference)).collect(Collectors.toList()));
if (mappingModel.isPresent()) {
MappingModel _mappingModel = mappingModel.get();
infoResource.setTargetPlatformKey(_mappingModel.getTargetPlatform());
for (MappingRule rule : getInfoModelRule(_mappingModel.getRules())) {
if (rule.getTarget() instanceof StereoTypeTarget) {
StereoTypeTarget target = (StereoTypeTarget) rule.getTarget();
infoResource.addStereotype(Stereotype.create(target.getName(), convertAttributesToMap(target.getAttributes())));
} else if (rule.getTarget() instanceof ReferenceTarget) {
ReferenceTarget target = (ReferenceTarget) rule.getTarget();
infoResource.setMappingReference(createModelId(target.getMappingModel()));
}
}
}
return infoResource;
}
use of org.eclipse.vorto.repository.api.ModelId in project vorto by eclipse.
the class ModelDtoFactory method createResource.
public static EntityModel createResource(Entity model, Optional<MappingModel> mappingModel) {
EntityModel resource = new EntityModel(new ModelId(model.getName(), model.getNamespace(), model.getVersion()), ModelType.Datatype);
resource.setDescription(model.getDescription());
resource.setDisplayName(model.getDisplayname());
resource.setReferences(model.getReferences().stream().map(reference -> createModelId(reference)).collect(Collectors.toList()));
resource.setProperties(model.getProperties().stream().map(p -> createProperty(p, mappingModel)).collect(Collectors.toList()));
if (mappingModel.isPresent()) {
resource.setTargetPlatformKey(mappingModel.get().getTargetPlatform());
for (MappingRule rule : getEntityRule(mappingModel.get().getRules())) {
StereoTypeTarget target = (StereoTypeTarget) rule.getTarget();
resource.addStereotype(Stereotype.create(target.getName(), convertAttributesToMap(target.getAttributes())));
}
}
return resource;
}
use of org.eclipse.vorto.repository.api.ModelId in project vorto by eclipse.
the class ModelRepositoryController method downloadModelById.
@ApiOperation(value = "Downloads the model content in a specific output format")
@ApiResponses(value = { @ApiResponse(code = 400, message = "Wrong input"), @ApiResponse(code = 404, message = "Model not found") })
@RequestMapping(value = "/file/{namespace}/{name}/{version:.+}", method = RequestMethod.GET)
public void downloadModelById(@ApiParam(value = "The namespace of vorto model, e.g. com.mycompany", required = true) @PathVariable final String namespace, @ApiParam(value = "The name of vorto model, e.g. NewInfomodel", required = true) @PathVariable final String name, @ApiParam(value = "The version of vorto model, e.g. 1.0.0", required = true) @PathVariable final String version, @ApiParam(value = "Choose output file format, e.g. DSL", required = true) @RequestParam(value = "output", required = false) final ContentType outputType, @ApiParam(value = "Set true if dependencies shall be included", required = false) @RequestParam(value = "includeDependencies", required = false) final boolean includeDependencies, final HttpServletResponse response) {
Objects.requireNonNull(namespace, "namespace must not be null");
Objects.requireNonNull(name, "name must not be null");
Objects.requireNonNull(version, "version must not be null");
final ModelId modelId = new ModelId(name, namespace, version);
logger.info("downloadModelById: [" + modelId.toString() + "]");
final ContentType contentType = outputType;
if (includeDependencies) {
byte[] zipContent = createZipWithAllDependencies(modelId, contentType);
response.setHeader(CONTENT_DISPOSITION, ATTACHMENT_FILENAME + modelId.getNamespace() + "_" + modelId.getName() + "_" + modelId.getVersion() + ".zip");
response.setContentType(APPLICATION_OCTET_STREAM);
try {
IOUtils.copy(new ByteArrayInputStream(zipContent), response.getOutputStream());
response.flushBuffer();
} catch (IOException e) {
throw new RuntimeException("Error copying file.", e);
}
} else {
createSingleModelContent(modelId, contentType, response);
}
}
Aggregations