Search in sources :

Example 26 with ModelInfo

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);
    }
}
Also used : ModelInfo(org.eclipse.vorto.repository.api.ModelInfo) ContentType(org.eclipse.vorto.repository.core.IModelRepository.ContentType) ByteArrayInputStream(java.io.ByteArrayInputStream) ZipOutputStream(java.util.zip.ZipOutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) ModelId(org.eclipse.vorto.repository.api.ModelId) UploadTooLargeException(org.eclipse.vorto.repository.web.core.exceptions.UploadTooLargeException) IOException(java.io.IOException) ModelNotFoundException(org.eclipse.vorto.repository.api.exception.ModelNotFoundException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) ApiOperation(io.swagger.annotations.ApiOperation) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 27 with ModelInfo

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;
}
Also used : ModelInfo(org.eclipse.vorto.repository.api.ModelInfo) ModelId(org.eclipse.vorto.repository.api.ModelId)

Example 28 with ModelInfo

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());
}
Also used : ModelInfo(org.eclipse.vorto.repository.api.ModelInfo) Test(org.junit.Test)

Example 29 with ModelInfo

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());
}
Also used : ModelInfo(org.eclipse.vorto.repository.api.ModelInfo) Test(org.junit.Test)

Example 30 with ModelInfo

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());
}
Also used : ModelInfo(org.eclipse.vorto.repository.api.ModelInfo) Test(org.junit.Test)

Aggregations

ModelInfo (org.eclipse.vorto.repository.api.ModelInfo)35 Test (org.junit.Test)12 ModelId (org.eclipse.vorto.repository.api.ModelId)11 IOException (java.io.IOException)9 ModelNotFoundException (org.eclipse.vorto.repository.api.exception.ModelNotFoundException)9 ByteArrayInputStream (java.io.ByteArrayInputStream)7 AbstractIntegrationTest (org.eclipse.vorto.repository.AbstractIntegrationTest)6 FatalModelRepositoryException (org.eclipse.vorto.repository.core.FatalModelRepositoryException)6 ValidationException (org.eclipse.vorto.repository.core.impl.validation.ValidationException)6 ArrayList (java.util.ArrayList)5 Node (javax.jcr.Node)5 PathNotFoundException (javax.jcr.PathNotFoundException)5 RepositoryException (javax.jcr.RepositoryException)5 ApiOperation (io.swagger.annotations.ApiOperation)4 UnsupportedEncodingException (java.io.UnsupportedEncodingException)4 ZipEntry (java.util.zip.ZipEntry)4 UploadTooLargeException (org.eclipse.vorto.repository.web.core.exceptions.UploadTooLargeException)4 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)4 ApiResponses (io.swagger.annotations.ApiResponses)3 ByteArrayOutputStream (java.io.ByteArrayOutputStream)3