Search in sources :

Example 21 with MappingModel

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());
}
Also used : MappingRule(org.eclipse.vorto.core.api.model.mapping.MappingRule) MappingModel(org.eclipse.vorto.core.api.model.mapping.MappingModel) Test(org.junit.Test)

Example 22 with MappingModel

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());
}
Also used : MappingRule(org.eclipse.vorto.core.api.model.mapping.MappingRule) MappingModel(org.eclipse.vorto.core.api.model.mapping.MappingModel) Test(org.junit.Test)

Example 23 with MappingModel

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());
}
Also used : MappingRule(org.eclipse.vorto.core.api.model.mapping.MappingRule) MappingModel(org.eclipse.vorto.core.api.model.mapping.MappingModel) Test(org.junit.Test)

Example 24 with MappingModel

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;
}
Also used : FunctionblockModel(org.eclipse.vorto.core.api.model.functionblock.FunctionblockModel) MappingRule(org.eclipse.vorto.core.api.model.mapping.MappingRule) StereoTypeTarget(org.eclipse.vorto.core.api.model.mapping.StereoTypeTarget) ModelId(org.eclipse.vorto.repository.api.ModelId) MappingModel(org.eclipse.vorto.core.api.model.mapping.MappingModel)

Example 25 with MappingModel

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);
    }
}
Also used : ZipOutputStream(java.util.zip.ZipOutputStream) PathVariable(org.springframework.web.bind.annotation.PathVariable) RequestParam(org.springframework.web.bind.annotation.RequestParam) ZipInputStream(java.util.zip.ZipInputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) URLDecoder(java.net.URLDecoder) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) MappingModel(org.eclipse.vorto.core.api.model.mapping.MappingModel) Autowired(org.springframework.beans.factory.annotation.Autowired) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ApiParam(io.swagger.annotations.ApiParam) ApiResponses(io.swagger.annotations.ApiResponses) ModelInfo(org.eclipse.vorto.repository.api.ModelInfo) IModelRepository(org.eclipse.vorto.repository.core.IModelRepository) Value(org.springframework.beans.factory.annotation.Value) Logger(org.apache.log4j.Logger) ApiOperation(io.swagger.annotations.ApiOperation) AbstractRepositoryController(org.eclipse.vorto.repository.web.AbstractRepositoryController) ByteArrayInputStream(java.io.ByteArrayInputStream) AbstractModel(org.eclipse.vorto.repository.api.AbstractModel) Api(io.swagger.annotations.Api) ZipEntry(java.util.zip.ZipEntry) ModelId(org.eclipse.vorto.repository.api.ModelId) UploadTooLargeException(org.eclipse.vorto.repository.web.core.exceptions.UploadTooLargeException) ContentType(org.eclipse.vorto.repository.core.IModelRepository.ContentType) HttpServletResponse(javax.servlet.http.HttpServletResponse) RequestMethod(org.springframework.web.bind.annotation.RequestMethod) IOException(java.io.IOException) Collectors(java.util.stream.Collectors) RestController(org.springframework.web.bind.annotation.RestController) ModelNotFoundException(org.eclipse.vorto.repository.api.exception.ModelNotFoundException) IModelWorkspace(org.eclipse.vorto.server.commons.reader.IModelWorkspace) Objects(java.util.Objects) IOUtils(org.apache.commons.io.IOUtils) List(java.util.List) ApiResponse(io.swagger.annotations.ApiResponse) Optional(java.util.Optional) MultipartFile(org.springframework.web.multipart.MultipartFile) UnsupportedEncodingException(java.io.UnsupportedEncodingException) ModelInfo(org.eclipse.vorto.repository.api.ModelInfo) ZipInputStream(java.util.zip.ZipInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) ModelId(org.eclipse.vorto.repository.api.ModelId) IModelWorkspace(org.eclipse.vorto.server.commons.reader.IModelWorkspace) MappingModel(org.eclipse.vorto.core.api.model.mapping.MappingModel) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

MappingModel (org.eclipse.vorto.core.api.model.mapping.MappingModel)27 MappingRule (org.eclipse.vorto.core.api.model.mapping.MappingRule)18 Test (org.junit.Test)15 ZipInputStream (java.util.zip.ZipInputStream)6 ModelId (org.eclipse.vorto.repository.api.ModelId)6 IModelWorkspace (org.eclipse.vorto.server.commons.reader.IModelWorkspace)6 ByteArrayInputStream (java.io.ByteArrayInputStream)5 List (java.util.List)5 Optional (java.util.Optional)5 Collectors (java.util.stream.Collectors)5 InvocationContext (org.eclipse.vorto.codegen.api.InvocationContext)4 FunctionblockModel (org.eclipse.vorto.core.api.model.functionblock.FunctionblockModel)4 InformationModel (org.eclipse.vorto.core.api.model.informationmodel.InformationModel)4 StereoTypeTarget (org.eclipse.vorto.core.api.model.mapping.StereoTypeTarget)4 ModelInfo (org.eclipse.vorto.repository.api.ModelInfo)4 ByteArrayOutputStream (java.io.ByteArrayOutputStream)3 IOException (java.io.IOException)3 ZipEntry (java.util.zip.ZipEntry)3 ZipOutputStream (java.util.zip.ZipOutputStream)3 IOUtils (org.apache.commons.io.IOUtils)3