use of org.eclipse.vorto.repository.api.ModelInfo 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.ModelInfo 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.ModelInfo in project vorto by eclipse.
the class DependencyManagerTest method testDependentTypesWithFB.
@Test
public void testDependentTypesWithFB() {
ModelInfo subunit = create("Subunit", ModelType.Datatype);
ModelInfo unit = create("Unit", ModelType.Datatype, subunit);
ModelInfo temp = create("Temperature", ModelType.Datatype, unit);
ModelInfo fridge = create("Fridge", ModelType.Functionblock, temp);
dm.addResource(unit);
dm.addResource(subunit);
dm.addResource(temp);
dm.addResource(fridge);
assertEquals(subunit.getId(), dm.getSorted().get(0).getId());
assertEquals(unit.getId(), dm.getSorted().get(1).getId());
assertEquals(temp.getId(), dm.getSorted().get(2).getId());
assertEquals(fridge.getId(), dm.getSorted().get(3).getId());
}
use of org.eclipse.vorto.repository.api.ModelInfo in project vorto by eclipse.
the class DependencyManagerTest method testDependentTypesWithFB2.
@Test
public void testDependentTypesWithFB2() {
ModelInfo subunit = create("Subunit", ModelType.Datatype);
ModelInfo unit = create("Unit", ModelType.Datatype, subunit);
ModelInfo temp = create("Temperature", ModelType.Datatype, unit);
ModelInfo superFridge = create("SuperFridge", ModelType.Functionblock, temp);
ModelInfo fridge = create("Fridge", ModelType.Functionblock, superFridge);
dm.addResource(unit);
dm.addResource(subunit);
dm.addResource(temp);
dm.addResource(fridge);
dm.addResource(superFridge);
assertEquals(subunit.getId(), dm.getSorted().get(0).getId());
assertEquals(unit.getId(), dm.getSorted().get(1).getId());
assertEquals(temp.getId(), dm.getSorted().get(2).getId());
assertEquals(superFridge.getId(), dm.getSorted().get(3).getId());
assertEquals(fridge.getId(), dm.getSorted().get(4).getId());
}
use of org.eclipse.vorto.repository.api.ModelInfo in project vorto by eclipse.
the class DependencyManagerTest method testDependentDatatypes.
@Test
public void testDependentDatatypes() {
ModelInfo subunit = create("Subunit", ModelType.Datatype);
ModelInfo unit = create("Unit", ModelType.Datatype, subunit);
ModelInfo temp = create("Temperature", ModelType.Datatype, unit);
dm.addResource(subunit);
dm.addResource(unit);
dm.addResource(temp);
assertEquals(subunit.getId(), dm.getSorted().get(0).getId());
assertEquals(unit.getId(), dm.getSorted().get(1).getId());
assertEquals(temp.getId(), dm.getSorted().get(2).getId());
}
Aggregations