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);
}
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"))));
}
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"));
}
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);
}
}
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);
}
}
Aggregations