Search in sources :

Example 31 with ModelId

use of org.eclipse.vorto.repository.api.ModelId in project vorto by eclipse.

the class ModelRepositoryTest method testGetModelImage.

@Test
public void testGetModelImage() throws Exception {
    final ModelId modelId = new ModelId("HueLightStrips", "com.mycompany", "1.0.0");
    byte[] modelContent = IOUtils.toByteArray(new ClassPathResource("sample_models/sample.png").getInputStream());
    checkinModel("Color.type");
    checkinModel("Colorlight.fbmodel");
    checkinModel("Switcher.fbmodel");
    checkinModel("HueLightStrips.infomodel");
    this.modelRepository.addModelImage(modelId, modelContent);
    assertTrue(this.modelRepository.getModelImage(modelId).length > 0);
}
Also used : ModelId(org.eclipse.vorto.repository.api.ModelId) ClassPathResource(org.springframework.core.io.ClassPathResource) Test(org.junit.Test) AbstractIntegrationTest(org.eclipse.vorto.repository.AbstractIntegrationTest)

Example 32 with ModelId

use of org.eclipse.vorto.repository.api.ModelId in project vorto by eclipse.

the class BlueToothDeviceInfoProfileResolverTest method testResolveInfoModelByDeviceInfoProfileSerialNo.

@Test
public void testResolveInfoModelByDeviceInfoProfileSerialNo() {
    checkinModel("bluetooth/ColorLight.fbmodel");
    checkinModel("bluetooth/ColorLightIM.infomodel");
    checkinModel("bluetooth/ColorLight_bluetooth.mapping");
    DefaultResolver resolver = new DefaultResolver();
    resolver.setRepository(this.modelRepository);
    assertEquals(new ModelId("ColorLightIM", "com.mycompany", "1.0.0"), resolver.resolve(new BluetoothQuery("4810")));
    assertNotNull(this.modelRepository.getById(resolver.resolve(new BluetoothQuery("4810"))));
}
Also used : DefaultResolver(org.eclipse.vorto.repository.core.impl.resolver.DefaultResolver) BluetoothQuery(org.eclipse.vorto.repository.api.resolver.BluetoothQuery) ModelId(org.eclipse.vorto.repository.api.ModelId) AbstractIntegrationTest(org.eclipse.vorto.repository.AbstractIntegrationTest) Test(org.junit.Test)

Example 33 with ModelId

use of org.eclipse.vorto.repository.api.ModelId in project vorto by eclipse.

the class NotificationServiceTest method testSendCheckedModelEmail.

@Test
public void testSendCheckedModelEmail() throws Exception {
    User user = new User();
    user.setEmail("alexander.edelmann@bosch-si.com");
    user.setUsername("aedelmann");
    ModelInfo resource = new ModelInfo(new ModelId("Fridge", "org.eclipse.vorto.examples", "1.0.0"), ModelType.Functionblock);
    resource.setAuthor("andreas");
    resource.setCreationDate(new Date());
    resource.setDescription("A fridge keeps groceries fresh");
    notificationService.sendNotification(new CheckinMessage(user, resource));
    assertEquals(1, wiser.getMessages().size());
    assertTrue(((String) wiser.getMessages().get(0).getMimeMessage().getContent()).contains("A new model has just been checked into the Vorto Repository"));
    assertTrue(((String) wiser.getMessages().get(0).getMimeMessage().getContent()).contains("Dear aedelmann"));
}
Also used : ModelInfo(org.eclipse.vorto.repository.api.ModelInfo) User(org.eclipse.vorto.repository.account.impl.User) CheckinMessage(org.eclipse.vorto.repository.notification.message.CheckinMessage) ModelId(org.eclipse.vorto.repository.api.ModelId) Date(java.util.Date) Test(org.junit.Test)

Example 34 with ModelId

use of org.eclipse.vorto.repository.api.ModelId in project vorto by eclipse.

the class ModelGenerationController method generateAndExtract.

@ApiOperation(value = "Generate code for a specified platform, and extract specified path")
@ApiResponses(value = { @ApiResponse(code = 400, message = "Wrong input"), @ApiResponse(code = 404, message = "Model not found") })
@RequestMapping(value = "/{namespace}/{name}/{version:.+}/{serviceKey:[^!]+}!/**", method = RequestMethod.GET)
public void generateAndExtract(@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 = "Service key for a specified platform, e.g. lwm2m", required = true) @PathVariable String serviceKey, final HttpServletRequest request, final HttpServletResponse response) {
    try {
        GeneratedOutput generatedOutput = generatorService.generate(new ModelId(name, namespace, version), URLDecoder.decode(serviceKey, "utf-8"), getRequestParams(request));
        String extractPath = getExtractPath(request);
        if (extractPath == null || extractPath.trim().isEmpty()) {
            writeToResponse(response, generatedOutput);
            return;
        }
        if (generatedOutput.getFileName().endsWith(ZIPFILE_EXTENSION)) {
            Optional<GeneratedOutput> extractionResult = extractFromZip(generatedOutput.getContent(), extractPath);
            if (extractionResult.isPresent()) {
                writeToResponse(response, extractionResult.get());
                return;
            }
        }
        response.sendError(HttpServletResponse.SC_NOT_FOUND);
    } catch (IOException e) {
        throw new RuntimeException("Error copying file.", e);
    }
}
Also used : GeneratedOutput(org.eclipse.vorto.repository.api.generation.GeneratedOutput) IOException(java.io.IOException) ModelId(org.eclipse.vorto.repository.api.ModelId) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 35 with ModelId

use of org.eclipse.vorto.repository.api.ModelId in project vorto by eclipse.

the class ModelGenerationController method generate.

@ApiOperation(value = "Generate code for a specified platform")
@ApiResponses(value = { @ApiResponse(code = 400, message = "Wrong input"), @ApiResponse(code = 404, message = "Model not found") })
@RequestMapping(value = "/{namespace}/{name}/{version:.+}/{serviceKey:[^!]+}", method = RequestMethod.GET)
public void generate(@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 = "Service key for a specified platform, e.g. lwm2m", required = true) @PathVariable String serviceKey, final HttpServletRequest request, 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");
    Objects.requireNonNull(serviceKey, "version must not be null");
    try {
        GeneratedOutput generatedOutput = generatorService.generate(new ModelId(name, namespace, version), URLDecoder.decode(serviceKey, "utf-8"), getRequestParams(request));
        writeToResponse(response, generatedOutput);
    } catch (IOException e) {
        throw new RuntimeException("Error copying file.", e);
    }
}
Also used : GeneratedOutput(org.eclipse.vorto.repository.api.generation.GeneratedOutput) IOException(java.io.IOException) ModelId(org.eclipse.vorto.repository.api.ModelId) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

ModelId (org.eclipse.vorto.repository.api.ModelId)36 ModelInfo (org.eclipse.vorto.repository.api.ModelInfo)12 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)11 ApiOperation (io.swagger.annotations.ApiOperation)10 IOException (java.io.IOException)10 ApiResponses (io.swagger.annotations.ApiResponses)9 Test (org.junit.Test)9 ModelNotFoundException (org.eclipse.vorto.repository.api.exception.ModelNotFoundException)8 AbstractIntegrationTest (org.eclipse.vorto.repository.AbstractIntegrationTest)7 ByteArrayInputStream (java.io.ByteArrayInputStream)6 MappingModel (org.eclipse.vorto.core.api.model.mapping.MappingModel)6 ContentType (org.eclipse.vorto.repository.core.IModelRepository.ContentType)6 UnsupportedEncodingException (java.io.UnsupportedEncodingException)5 UploadTooLargeException (org.eclipse.vorto.repository.web.core.exceptions.UploadTooLargeException)5 ByteArrayOutputStream (java.io.ByteArrayOutputStream)4 Optional (java.util.Optional)4 ZipEntry (java.util.zip.ZipEntry)4 ZipOutputStream (java.util.zip.ZipOutputStream)4 MappingRule (org.eclipse.vorto.core.api.model.mapping.MappingRule)4 StereoTypeTarget (org.eclipse.vorto.core.api.model.mapping.StereoTypeTarget)4