use of org.eclipse.vorto.repository.api.ModelId in project vorto by eclipse.
the class ModelRepositoryController method getModelImage.
@ApiOperation(value = "Returns the image of a vorto model")
@ApiResponses(value = { @ApiResponse(code = 400, message = "Wrong input"), @ApiResponse(code = 404, message = "Model not found") })
@RequestMapping(value = "/image/{namespace}/{name}/{version:.+}", method = RequestMethod.GET)
public void getModelImage(@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 = "Response", required = true) 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);
byte[] modelImage = modelRepository.getModelImage(modelId);
response.setHeader(CONTENT_DISPOSITION, ATTACHMENT_FILENAME + modelId.getName() + ".png");
response.setContentType(APPLICATION_OCTET_STREAM);
try {
IOUtils.copy(new ByteArrayInputStream(modelImage), response.getOutputStream());
response.flushBuffer();
} catch (IOException e) {
throw new RuntimeException("Error copying file.", e);
}
}
use of org.eclipse.vorto.repository.api.ModelId in project vorto by eclipse.
the class ModelRepositoryController method getModelContent.
@ApiOperation(value = "Returns the model content")
@ApiResponses(value = { @ApiResponse(code = 400, message = "Wrong input"), @ApiResponse(code = 404, message = "Model not found") })
@RequestMapping(value = "/content/{namespace}/{name}/{version:.+}", method = RequestMethod.GET)
public AbstractModel getModelContent(@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) {
byte[] modelContent = createZipWithAllDependencies(new ModelId(name, namespace, version), ContentType.DSL);
IModelWorkspace workspace = IModelWorkspace.newReader().addZip(new ZipInputStream(new ByteArrayInputStream(modelContent))).read();
return ModelDtoFactory.createResource(workspace.get().stream().filter(p -> p.getName().equals(name)).findFirst().get(), Optional.empty());
}
use of org.eclipse.vorto.repository.api.ModelId in project vorto by eclipse.
the class ModelRepositoryController method getMappingResources.
@ApiOperation(value = "Getting all mapping resources")
@RequestMapping(value = "/mapping/zip/{namespace}/{name}/{version:.+}/{targetPlatform}", method = RequestMethod.GET)
public void getMappingResources(@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 = "The name of target platform, e.g. lwm2m", required = true) @PathVariable final String targetPlatform, 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);
List<ModelInfo> mappingResources = modelRepository.getMappingModelsForTargetPlatform(modelId, targetPlatform);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ZipOutputStream zos = new ZipOutputStream(baos);
final ContentType contentType = ContentType.DSL;
try {
for (ModelInfo mappingResource : mappingResources) {
addModelToZip(zos, mappingResource.getId(), contentType);
}
zos.close();
baos.close();
} catch (Exception ex) {
throw new RuntimeException(ex);
}
response.setHeader(CONTENT_DISPOSITION, ATTACHMENT_FILENAME + modelId.getNamespace() + "_" + modelId.getName() + "_" + modelId.getVersion() + ".zip");
response.setContentType(APPLICATION_OCTET_STREAM);
try {
IOUtils.copy(new ByteArrayInputStream(baos.toByteArray()), response.getOutputStream());
response.flushBuffer();
} catch (IOException e) {
throw new RuntimeException("Error copying file.", e);
}
}
use of org.eclipse.vorto.repository.api.ModelId in project vorto by eclipse.
the class DependencyManagerTest method create.
protected ModelInfo create(String name, ModelType type, ModelInfo... references) {
final ModelId id = new ModelId(name, "org.eclipse.vorto", "1.0.0");
ModelInfo resource = new ModelInfo(id, type);
resource.setReferences(Arrays.asList(references).stream().map(reference -> reference.getId()).collect(Collectors.toList()));
Arrays.asList(references).stream().forEach(it -> it.addReferencedBy(id));
return resource;
}
use of org.eclipse.vorto.repository.api.ModelId in project vorto by eclipse.
the class ModelRepositoryTest method testGetModelWithImage.
@Test
public void testGetModelWithImage() throws Exception {
final ModelId modelId = new ModelId("HueLightStrips", "com.mycompany", "1.0.0");
checkinModel("Color.type");
checkinModel("Colorlight.fbmodel");
checkinModel("Switcher.fbmodel");
checkinModel("HueLightStrips.infomodel");
this.modelRepository.addModelImage(modelId, IOUtils.toByteArray(new ClassPathResource("sample_models/sample.png").getInputStream()));
assertEquals(true, this.modelRepository.getById(modelId).isHasImage());
}
Aggregations