use of org.eclipse.vorto.core.api.model.mapping.MappingModel in project vorto by eclipse.
the class MappingModelSyntaxTest method parseMappingWithEnumProperty.
@Test
public void parseMappingWithEnumProperty() throws IOException {
MappingModel mappingModel = createMappingModel("type/Enum_Property.mapping");
EList<MappingRule> rules = mappingModel.getRules();
assertEquals(2, rules.size());
}
use of org.eclipse.vorto.core.api.model.mapping.MappingModel in project vorto by eclipse.
the class MappingModelSyntaxTest method parseMappingWithInfomodelReference.
@Test
public void parseMappingWithInfomodelReference() throws IOException {
MappingModel mappingModel = createMappingModel("Infomodel_FBRef.mapping");
EList<MappingRule> rules = mappingModel.getRules();
assertEquals(1, rules.size());
}
use of org.eclipse.vorto.core.api.model.mapping.MappingModel in project vorto by eclipse.
the class MappingModelSyntaxTest method parseMappingWithFunctionBlockAttribute.
@Test
public void parseMappingWithFunctionBlockAttribute() throws IOException {
MappingModel mappingModel = createMappingModel("fb/FunctionBlock_Attribute.mapping");
EList<MappingRule> rules = mappingModel.getRules();
assertEquals(6, rules.size());
}
use of org.eclipse.vorto.core.api.model.mapping.MappingModel in project vorto by eclipse.
the class ModelDtoFactory method createResource.
public static org.eclipse.vorto.repository.api.content.FunctionblockModel createResource(FunctionblockModel model, Optional<MappingModel> mappingModel) {
org.eclipse.vorto.repository.api.content.FunctionblockModel resource = new org.eclipse.vorto.repository.api.content.FunctionblockModel(new ModelId(model.getName(), model.getNamespace(), model.getVersion()), ModelType.Functionblock);
resource.setDescription(model.getDescription());
resource.setDisplayName(model.getDisplayname());
resource.setReferences(model.getReferences().stream().map(reference -> createModelId(reference)).collect(Collectors.toList()));
if (model.getFunctionblock().getConfiguration() != null) {
resource.setConfigurationProperties(model.getFunctionblock().getConfiguration().getProperties().stream().map(p -> createProperty(p, mappingModel)).collect(Collectors.toList()));
}
if (model.getFunctionblock().getStatus() != null) {
resource.setStatusProperties(model.getFunctionblock().getStatus().getProperties().stream().map(p -> createProperty(p, mappingModel)).collect(Collectors.toList()));
}
if (model.getFunctionblock().getFault() != null) {
resource.setFaultProperties(model.getFunctionblock().getFault().getProperties().stream().map(p -> createProperty(p, mappingModel)).collect(Collectors.toList()));
}
if (model.getFunctionblock().getEvents() != null) {
resource.setEvents(model.getFunctionblock().getEvents().stream().map(e -> createEvent(e, mappingModel)).collect(Collectors.toList()));
}
if (model.getFunctionblock().getOperations() != null) {
resource.setOperations(model.getFunctionblock().getOperations().stream().map(o -> createOperation(o)).collect(Collectors.toList()));
}
if (mappingModel.isPresent()) {
MappingModel _mappingModel = mappingModel.get();
resource.setTargetPlatformKey(_mappingModel.getTargetPlatform());
for (MappingRule rule : getFbRule(_mappingModel.getRules())) {
StereoTypeTarget target = (StereoTypeTarget) rule.getTarget();
resource.addStereotype(Stereotype.create(target.getName(), convertAttributesToMap(target.getAttributes())));
}
}
return resource;
}
use of org.eclipse.vorto.core.api.model.mapping.MappingModel in project vorto by eclipse.
the class ModelRepositoryController method getModelContentForTargetPlatform.
@ApiOperation(value = "Returns the model content including target platform specific attributes")
@ApiResponses(value = { @ApiResponse(code = 400, message = "Wrong input"), @ApiResponse(code = 404, message = "Model not found") })
@RequestMapping(value = "/content/{namespace}/{name}/{version:.+}/mapping/{targetplatformKey}", method = RequestMethod.GET)
public AbstractModel getModelContentForTargetPlatform(@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 key of the targetplatform, e.g. lwm2m", required = true) @PathVariable final String targetplatformKey) {
List<ModelInfo> mappingResource = modelRepository.getMappingModelsForTargetPlatform(new ModelId(name, namespace, version), targetplatformKey);
if (!mappingResource.isEmpty()) {
byte[] mappingContentZip = createZipWithAllDependencies(mappingResource.get(0).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(new ModelId(name, namespace, version), ContentType.DSL);
workspace = IModelWorkspace.newReader().addZip(new ZipInputStream(new ByteArrayInputStream(modelContent))).read();
return ModelDtoFactory.createResource(workspace.get().stream().filter(p -> p.getName().equals(name)).findFirst().get(), Optional.of(mappingModel));
} else {
return getModelContent(namespace, name, version);
}
}
Aggregations