use of org.eclipse.vorto.repository.api.ModelId in project vorto by eclipse.
the class ModelRepositoryController method getModelResource.
@ApiOperation(value = "Returns a model by its full qualified model ID")
@ApiResponses(value = { @ApiResponse(code = 400, message = "Wrong input"), @ApiResponse(code = 404, message = "Model not found") })
@RequestMapping(value = "/{namespace}/{name}/{version:.+}", method = RequestMethod.GET)
public ModelInfo getModelResource(@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) {
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("getModelResource: [" + modelId.toString() + "]");
ModelInfo resource = modelRepository.getById(modelId);
if (resource == null) {
throw new ModelNotFoundException("Model does not exist", null);
}
return ModelDtoFactory.createDto(resource);
}
use of org.eclipse.vorto.repository.api.ModelId in project vorto by eclipse.
the class ModelRepositoryController method getModelContentByModelAndMappingId.
@ApiOperation(value = "Returns the model content including target platform specific attributes for the given model- and mapping modelID")
@ApiResponses(value = { @ApiResponse(code = 400, message = "Wrong input"), @ApiResponse(code = 404, message = "Model not found") })
@RequestMapping(value = "/content/{modelId:.+}/mapping/{mappingId:.+}", method = RequestMethod.GET)
public AbstractModel getModelContentByModelAndMappingId(@ApiParam(value = "The model ID (prettyFormat)", required = true) @PathVariable final String modelId, @ApiParam(value = "The mapping Model ID (prettyFormat)", required = true) @PathVariable final String mappingId) {
ModelInfo vortoModelInfo = modelRepository.getById(ModelId.fromPrettyFormat(modelId));
ModelInfo mappingModelInfo = modelRepository.getById(ModelId.fromPrettyFormat(mappingId));
if (vortoModelInfo == null) {
throw new ModelNotFoundException("Could not find vorto model with ID: " + modelId);
} else if (mappingModelInfo == null) {
throw new ModelNotFoundException("Could not find mapping with ID: " + mappingId);
}
byte[] mappingContentZip = createZipWithAllDependencies(mappingModelInfo.getId(), ContentType.DSL);
IModelWorkspace workspace = IModelWorkspace.newReader().addZip(new ZipInputStream(new ByteArrayInputStream(mappingContentZip))).read();
MappingModel mappingModel = (MappingModel) workspace.get().stream().filter(p -> p instanceof MappingModel).findFirst().get();
byte[] modelContent = createZipWithAllDependencies(vortoModelInfo.getId(), ContentType.DSL);
workspace = IModelWorkspace.newReader().addZip(new ZipInputStream(new ByteArrayInputStream(modelContent))).read();
return ModelDtoFactory.createResource(workspace.get().stream().filter(p -> p.getName().equals(vortoModelInfo.getId().getName())).findFirst().get(), Optional.of(mappingModel));
}
use of org.eclipse.vorto.repository.api.ModelId in project vorto by eclipse.
the class ModelRepositoryController method addModelToZip.
private void addModelToZip(ZipOutputStream zipOutputStream, ModelId modelId, ContentType contentType) throws Exception {
byte[] modelContent = modelRepository.getModelContent(modelId, contentType).getContent();
ModelInfo modelResource = modelRepository.getById(modelId);
try {
ZipEntry zipEntry = new ZipEntry(getFileName(modelResource, contentType));
zipOutputStream.putNextEntry(zipEntry);
zipOutputStream.write(modelContent);
zipOutputStream.closeEntry();
} catch (Exception ex) {
// entry possible exists already, so skipping TODO: ugly hack!!
}
for (ModelId reference : modelResource.getReferences()) {
addModelToZip(zipOutputStream, reference, contentType);
}
}
use of org.eclipse.vorto.repository.api.ModelId in project vorto by eclipse.
the class RepositoryAdminTest method testBackupFilesWithImage.
@Test
public void testBackupFilesWithImage() throws Exception {
checkinModel("Color.type");
checkinModel("Colorlight.fbmodel");
checkinModel("Switcher.fbmodel");
checkinModel("HueLightStrips.infomodel");
this.modelRepository.addModelImage(new ModelId("HueLightStrips", "com.mycompany", "1.0.0"), IOUtils.toByteArray(new ClassPathResource("sample_models/sample.png").getInputStream()));
byte[] backedUpContent = repositoryManager.backup();
assertNotNull(backedUpContent);
assertTrue(new String(backedUpContent).contains(".png"));
}
use of org.eclipse.vorto.repository.api.ModelId in project vorto by eclipse.
the class ModelRepositoryTest method testOverrideImage.
@Test
public void testOverrideImage() 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");
byte[] modelContent = IOUtils.toByteArray(new ClassPathResource("sample_models/sample.png").getInputStream());
this.modelRepository.addModelImage(modelId, modelContent);
this.modelRepository.addModelImage(modelId, modelContent);
}
Aggregations