Search in sources :

Example 1 with Property

use of org.eclipse.vorto.core.api.model.datatype.Property in project vorto by eclipse.

the class ModelDtoFactory method createProperty.

private static ModelProperty createProperty(Property property, Optional<MappingModel> mappingModel) {
    ModelProperty p = new ModelProperty();
    p.setDescription(property.getDescription());
    p.setMandatory(property.getPresence() != null ? property.getPresence().isMandatory() : true);
    p.setMultiple(property.isMultiplicity());
    p.setName(property.getName());
    if (property.getType() instanceof PrimitivePropertyType) {
        PrimitiveType pt = ((PrimitivePropertyType) property.getType()).getType();
        p.setType(org.eclipse.vorto.repository.api.content.PrimitiveType.valueOf(pt.name()));
    } else {
        p.setType(createModelId(((ObjectPropertyType) property.getType()).getType()));
    }
    if (property.getConstraintRule() != null && property.getConstraintRule().getConstraints() != null) {
        List<Constraint> constraints = property.getConstraintRule().getConstraints().stream().map(c -> createConstraint(c)).collect(Collectors.toList());
        p.setConstraints(constraints);
    }
    if (property.getPropertyAttributes() != null) {
        List<IPropertyAttribute> attributes = property.getPropertyAttributes().stream().map(a -> createAttribute(a)).collect(Collectors.toList());
        p.setAttributes(attributes);
    }
    if (mappingModel.isPresent()) {
        p.setTargetPlatformKey(mappingModel.get().getTargetPlatform());
        for (MappingRule rule : getPropertyRule(p.getName(), mappingModel.get().getRules())) {
            StereoTypeTarget target = (StereoTypeTarget) rule.getTarget();
            p.addStereotype(Stereotype.create(target.getName(), convertAttributesToMap(target.getAttributes())));
        }
    }
    return p;
}
Also used : InformationModel(org.eclipse.vorto.core.api.model.informationmodel.InformationModel) EntitySource(org.eclipse.vorto.core.api.model.mapping.EntitySource) ReturnPrimitiveType(org.eclipse.vorto.core.api.model.functionblock.ReturnPrimitiveType) Event(org.eclipse.vorto.core.api.model.functionblock.Event) PropertyAttribute(org.eclipse.vorto.core.api.model.datatype.PropertyAttribute) BooleanPropertyAttribute(org.eclipse.vorto.core.api.model.datatype.BooleanPropertyAttribute) Entity(org.eclipse.vorto.core.api.model.datatype.Entity) Attribute(org.eclipse.vorto.core.api.model.mapping.Attribute) BooleanAttributeProperty(org.eclipse.vorto.repository.api.content.BooleanAttributeProperty) PrimitivePropertyType(org.eclipse.vorto.core.api.model.datatype.PrimitivePropertyType) RefParam(org.eclipse.vorto.core.api.model.functionblock.RefParam) ModelProperty(org.eclipse.vorto.repository.api.content.ModelProperty) Map(java.util.Map) ReturnObjectType(org.eclipse.vorto.core.api.model.functionblock.ReturnObjectType) AbstractModel(org.eclipse.vorto.repository.api.AbstractModel) ModelId(org.eclipse.vorto.repository.api.ModelId) EnumAttributePropertyType(org.eclipse.vorto.repository.api.content.EnumAttributePropertyType) Infomodel(org.eclipse.vorto.repository.api.content.Infomodel) ConfigurationSource(org.eclipse.vorto.core.api.model.mapping.ConfigurationSource) InfoModelPropertySource(org.eclipse.vorto.core.api.model.mapping.InfoModelPropertySource) EntityModel(org.eclipse.vorto.repository.api.content.EntityModel) Collectors(java.util.stream.Collectors) List(java.util.List) BooleanAttributePropertyType(org.eclipse.vorto.repository.api.content.BooleanAttributePropertyType) FunctionblockModel(org.eclipse.vorto.core.api.model.functionblock.FunctionblockModel) ReturnType(org.eclipse.vorto.repository.api.content.ReturnType) Optional(java.util.Optional) IPropertyAttribute(org.eclipse.vorto.repository.api.content.IPropertyAttribute) EnumLiteral(org.eclipse.vorto.repository.api.content.EnumLiteral) Stereotype(org.eclipse.vorto.repository.api.content.Stereotype) EnumAttributeProperty(org.eclipse.vorto.repository.api.content.EnumAttributeProperty) FunctionblockProperty(org.eclipse.vorto.core.api.model.informationmodel.FunctionblockProperty) MappingModel(org.eclipse.vorto.core.api.model.mapping.MappingModel) ConstraintType(org.eclipse.vorto.repository.api.content.ConstraintType) FunctionBlockAttributeSource(org.eclipse.vorto.core.api.model.mapping.FunctionBlockAttributeSource) StatusSource(org.eclipse.vorto.core.api.model.mapping.StatusSource) Model(org.eclipse.vorto.core.api.model.model.Model) ModelInfo(org.eclipse.vorto.repository.api.ModelInfo) Property(org.eclipse.vorto.core.api.model.datatype.Property) PrimitiveParam(org.eclipse.vorto.core.api.model.functionblock.PrimitiveParam) MappingRule(org.eclipse.vorto.core.api.model.mapping.MappingRule) StereoTypeTarget(org.eclipse.vorto.core.api.model.mapping.StereoTypeTarget) Enum(org.eclipse.vorto.core.api.model.datatype.Enum) ModelType(org.eclipse.vorto.repository.api.ModelType) ModelReference(org.eclipse.vorto.core.api.model.model.ModelReference) InfoModelAttributeSource(org.eclipse.vorto.core.api.model.mapping.InfoModelAttributeSource) Param(org.eclipse.vorto.repository.api.content.Param) ReferenceTarget(org.eclipse.vorto.core.api.model.mapping.ReferenceTarget) FunctionBlockPropertySource(org.eclipse.vorto.core.api.model.mapping.FunctionBlockPropertySource) EnumLiteralPropertyAttribute(org.eclipse.vorto.core.api.model.datatype.EnumLiteralPropertyAttribute) Source(org.eclipse.vorto.core.api.model.mapping.Source) Operation(org.eclipse.vorto.repository.api.content.Operation) FaultSource(org.eclipse.vorto.core.api.model.mapping.FaultSource) Constraint(org.eclipse.vorto.repository.api.content.Constraint) ModelEvent(org.eclipse.vorto.repository.api.content.ModelEvent) ObjectPropertyType(org.eclipse.vorto.core.api.model.datatype.ObjectPropertyType) EnumModel(org.eclipse.vorto.repository.api.content.EnumModel) PrimitiveType(org.eclipse.vorto.core.api.model.datatype.PrimitiveType) IPropertyAttribute(org.eclipse.vorto.repository.api.content.IPropertyAttribute) ObjectPropertyType(org.eclipse.vorto.core.api.model.datatype.ObjectPropertyType) Constraint(org.eclipse.vorto.repository.api.content.Constraint) PrimitivePropertyType(org.eclipse.vorto.core.api.model.datatype.PrimitivePropertyType) ModelProperty(org.eclipse.vorto.repository.api.content.ModelProperty) ReturnPrimitiveType(org.eclipse.vorto.core.api.model.functionblock.ReturnPrimitiveType) PrimitiveType(org.eclipse.vorto.core.api.model.datatype.PrimitiveType) MappingRule(org.eclipse.vorto.core.api.model.mapping.MappingRule) StereoTypeTarget(org.eclipse.vorto.core.api.model.mapping.StereoTypeTarget)

Example 2 with Property

use of org.eclipse.vorto.core.api.model.datatype.Property in project vorto by eclipse.

the class CodeGenTools method getReferencedTypes.

public static EList<Type> getReferencedTypes(Entity entity) {
    EList<Type> types = new BasicEList<Type>();
    for (Property property : entity.getProperties()) {
        types.addAll(getReferencedTypes(property));
    }
    types.add(entity.getSuperType());
    return types;
}
Also used : ObjectPropertyType(org.eclipse.vorto.core.api.model.datatype.ObjectPropertyType) Type(org.eclipse.vorto.core.api.model.datatype.Type) BasicEList(org.eclipse.emf.common.util.BasicEList) Property(org.eclipse.vorto.core.api.model.datatype.Property)

Example 3 with Property

use of org.eclipse.vorto.core.api.model.datatype.Property in project vorto by eclipse.

the class CoAPGenerator method generate.

public IGenerationResult generate(InformationModel infomodel, InvocationContext mappingContext, IVortoCodeGenProgressMonitor monitor) throws VortoCodeGeneratorException {
    GenerationResultZip zipOutputter = new GenerationResultZip(infomodel, getServiceKey());
    ChainedCodeGeneratorTask<InformationModel> generator = new ChainedCodeGeneratorTask<InformationModel>();
    /*
		/ Generate the client part...
		*/
    String CLIENT_PROJ = infomodel.getName() + COAP_CLIENT_PROJECT_SUFFIX;
    initPaths(CLIENT_PROJ);
    generator.addTask(new CoAPClientInformationModelGeneratorTask(JAVA_FILE_EXTENSION, imTargetPath, IM_PACKAGE, JAVA_INTERFACE_PREFIX, JAVA_IMPL_SUFFIX, GETTER_PREFIX, SETTER_PREFIX, FB_INTERFACE_PACKAGE, FB_IMPL_PACKAGE));
    generator.addTask(new JavaInformationModelInterfaceGeneratorTask(JAVA_FILE_EXTENSION, imTargetPath, IM_PACKAGE, JAVA_INTERFACE_PREFIX, GETTER_PREFIX, SETTER_PREFIX, FB_INTERFACE_PACKAGE));
    generator.addTask(new GeneratorTaskFromFileTemplate<InformationModel>(new ClientTemplate(coapClientPath, COAP_CLIENT_PACKAGE)));
    generator.addTask(new GeneratorTaskFromFileTemplate<InformationModel>(new CoAPMethodTemplate(coapClientPath, COAP_CLIENT_PACKAGE)));
    generator.addTask(new GeneratorTaskFromFileTemplate<InformationModel>(new ClientDemoAppTemplate(coapDemoPath, COAP_DEMO_PACKAGE)));
    generator.addTask(new GeneratorTaskFromFileTemplate<InformationModel>(new PomFileTemplate("artifact", COAP_DEMO_PACKAGE + ".ClientDemoApp", CLIENT_PROJ)));
    generator.generate(infomodel, mappingContext, zipOutputter);
    for (FunctionblockProperty fbp : infomodel.getProperties()) {
        FunctionBlock fb = fbp.getType().getFunctionblock();
        for (Entity entity : Utils.getReferencedEntities(fb)) {
            generateForEntity(entity, zipOutputter);
        }
        for (Enum en : Utils.getReferencedEnums(fb)) {
            generateForEnum(en, zipOutputter);
        }
        for (Operation op : fb.getOperations()) {
            generateForOperation(op, zipOutputter);
        }
        if (fb.getStatus() != null) {
            for (Property property : fb.getStatus().getProperties()) {
                generateForProperty(property, zipOutputter);
            }
        }
        this.generateForClientFunctionBlock(fbp.getType(), zipOutputter);
    }
    /*
		/ Generate the server part...
		*/
    String SERVER_PROJ = infomodel.getName() + COAP_SERVER_PROJECT_SUFFIX;
    initPaths(SERVER_PROJ);
    generator.addTask(new CoAPServerGeneratorTask(COAP_SERVER_NAME, COAP_SERVER_PACKAGE, JAVA_FILE_EXTENSION, coapServerPath, JAVA_INTERFACE_PREFIX + COAP_REQUEST_HANDLER_NAME, COAP_REQUEST_HANDLER_PACKAGE));
    generator.addTask(new CoAPServerIMRequestHandlerGeneratorTask(COAP_REQUEST_HANDLER_NAME, JAVA_FILE_EXTENSION, coapRequestHandlerPath, COAP_REQUEST_HANDLER_PACKAGE, JAVA_INTERFACE_PREFIX, COAP_PRIM_TYPE_WRAPPER_SUFFIX, IM_PACKAGE, DT_PACKAGE, getOpParamSetPackage(), getPrimitiveParamWrapperPackage()));
    generator.addTask(new JavaInformationModelGeneratorTask(JAVA_FILE_EXTENSION, imTargetPath, IM_PACKAGE, JAVA_INTERFACE_PREFIX, JAVA_IMPL_SUFFIX, GETTER_PREFIX, SETTER_PREFIX, FB_INTERFACE_PACKAGE, FB_IMPL_PACKAGE));
    generator.addTask(new JavaInformationModelInterfaceGeneratorTask(JAVA_FILE_EXTENSION, imTargetPath, IM_PACKAGE, JAVA_INTERFACE_PREFIX, GETTER_PREFIX, SETTER_PREFIX, FB_INTERFACE_PACKAGE, FB_IMPL_PACKAGE));
    generator.addTask(new GeneratorTaskFromFileTemplate<InformationModel>(new ICoAPRequestHandlerTemplate(coapRequestHandlerPath, COAP_REQUEST_HANDLER_PACKAGE)));
    generator.addTask(new GeneratorTaskFromFileTemplate<InformationModel>(new JsonTransformerTemplate(coapRequestHandlerPath, COAP_REQUEST_HANDLER_PACKAGE)));
    generator.addTask(new GeneratorTaskFromFileTemplate<InformationModel>(new URIAnalyzerTemplate(coapRequestHandlerPath, COAP_REQUEST_HANDLER_PACKAGE)));
    generator.addTask(new GeneratorTaskFromFileTemplate<InformationModel>(new ResourceTemplate(coapServerPath, COAP_SERVER_PACKAGE, COAP_REQUEST_HANDLER_PACKAGE)));
    generator.addTask(new GeneratorTaskFromFileTemplate<InformationModel>(new LinkTemplate(coapServerPath, COAP_SERVER_PACKAGE)));
    generator.addTask(new GeneratorTaskFromFileTemplate<InformationModel>(new CoAPServerDemoAppTemplate(coapDemoPath, COAP_DEMO_PACKAGE, COAP_REQUEST_HANDLER_PACKAGE, COAP_SERVER_PACKAGE)));
    generator.addTask(new GeneratorTaskFromFileTemplate<InformationModel>(new PomFileTemplate("artifact", COAP_DEMO_PACKAGE + ".ServerDemoApp", SERVER_PROJ)));
    generator.generate(infomodel, mappingContext, zipOutputter);
    for (FunctionblockProperty fbp : infomodel.getProperties()) {
        this.generateForFunctionBlock(fbp.getType(), zipOutputter);
        FunctionBlock fb = fbp.getType().getFunctionblock();
        for (Entity entity : Utils.getReferencedEntities(fb)) {
            generateForEntity(entity, zipOutputter);
        }
        for (Enum en : Utils.getReferencedEnums(fb)) {
            generateForEnum(en, zipOutputter);
        }
        for (Operation op : fb.getOperations()) {
            generateForOperation(op, zipOutputter);
        }
    }
    return zipOutputter;
}
Also used : Enum(org.eclipse.vorto.core.api.model.datatype.Enum) Entity(org.eclipse.vorto.core.api.model.datatype.Entity) ICoAPRequestHandlerTemplate(org.eclipse.vorto.codegen.coap.server.templates.ICoAPRequestHandlerTemplate) InformationModel(org.eclipse.vorto.core.api.model.informationmodel.InformationModel) ClientTemplate(org.eclipse.vorto.codegen.coap.client.templates.ClientTemplate) ClientDemoAppTemplate(org.eclipse.vorto.codegen.coap.client.templates.ClientDemoAppTemplate) Operation(org.eclipse.vorto.core.api.model.functionblock.Operation) JavaInformationModelInterfaceGeneratorTask(org.eclipse.vorto.codegen.coap.common.tasks.JavaInformationModelInterfaceGeneratorTask) JavaInformationModelGeneratorTask(org.eclipse.vorto.codegen.coap.common.tasks.JavaInformationModelGeneratorTask) PomFileTemplate(org.eclipse.vorto.codegen.coap.common.templates.PomFileTemplate) CoAPServerDemoAppTemplate(org.eclipse.vorto.codegen.coap.server.templates.CoAPServerDemoAppTemplate) FunctionblockProperty(org.eclipse.vorto.core.api.model.informationmodel.FunctionblockProperty) Property(org.eclipse.vorto.core.api.model.datatype.Property) FunctionblockProperty(org.eclipse.vorto.core.api.model.informationmodel.FunctionblockProperty) FunctionBlock(org.eclipse.vorto.core.api.model.functionblock.FunctionBlock) CoAPClientInformationModelGeneratorTask(org.eclipse.vorto.codegen.coap.client.tasks.CoAPClientInformationModelGeneratorTask) CoAPServerIMRequestHandlerGeneratorTask(org.eclipse.vorto.codegen.coap.server.tasks.CoAPServerIMRequestHandlerGeneratorTask) GenerationResultZip(org.eclipse.vorto.codegen.api.GenerationResultZip) ChainedCodeGeneratorTask(org.eclipse.vorto.codegen.api.ChainedCodeGeneratorTask) CoAPMethodTemplate(org.eclipse.vorto.codegen.coap.client.templates.CoAPMethodTemplate) URIAnalyzerTemplate(org.eclipse.vorto.codegen.coap.server.templates.URIAnalyzerTemplate) ResourceTemplate(org.eclipse.vorto.codegen.coap.server.templates.ResourceTemplate) CoAPServerGeneratorTask(org.eclipse.vorto.codegen.coap.server.tasks.CoAPServerGeneratorTask) JsonTransformerTemplate(org.eclipse.vorto.codegen.coap.server.templates.JsonTransformerTemplate) LinkTemplate(org.eclipse.vorto.codegen.coap.server.templates.LinkTemplate)

Example 4 with Property

use of org.eclipse.vorto.core.api.model.datatype.Property in project vorto by eclipse.

the class ModelTransformer method transformProperty.

private void transformProperty(Service service, Property property) {
    IMapped<Property> map = this.context.getMappedElement(property, "source");
    if (map.hasAttribute("uuid")) {
        String uuid = map.getAttributeValue("uuid", "");
        Characteristic characteristic = null;
        for (Characteristic ch : service.getCharacteristics()) {
            if (ch.getUuid().equals(uuid)) {
                characteristic = ch;
                break;
            }
        }
        if (characteristic == null) {
            characteristic = this.factory.createCharacteristic();
            characteristic.setUuid(uuid);
            if (map.hasAttribute("name")) {
                characteristic.setName(map.getAttributeValue("name", ""));
            } else {
                characteristic.setName(((FunctionblockModel) (property.eContainer().eContainer().eContainer())).getName() + property.getName());
            }
            service.getCharacteristics().add(characteristic);
        }
        if (Integer.valueOf(map.getAttributeValue("length", "0")) + Integer.valueOf(map.getAttributeValue("offset", "0")) > characteristic.getLength()) {
            characteristic.setLength(Integer.valueOf(map.getAttributeValue("length", "0")) + Integer.valueOf(map.getAttributeValue("offset", "0")));
        }
        if (Utils.isReadable(property)) {
            characteristic.setIsReadable(true);
        }
        if (Utils.isWritable(property)) {
            characteristic.setIsWritable(true);
        }
        if (Utils.isEventable(property)) {
            characteristic.setIsEventable(true);
        }
        if (map.hasAttribute("length") && map.hasAttribute("offset") && map.hasAttribute("datatype")) {
            CharacteristicProperty cp = this.factory.createCharacteristicProperty();
            cp.setDatatype(map.getAttributeValue("datatype", ""));
            cp.setLength(Integer.parseInt(map.getAttributeValue("length", "0")));
            cp.setOffset(Integer.parseInt(map.getAttributeValue("offset", "0")));
            cp.setProperty(property);
            characteristic.getProperties().add(cp);
        }
    }
}
Also used : FunctionblockModel(org.eclipse.vorto.core.api.model.functionblock.FunctionblockModel) CharacteristicProperty(org.eclipse.vorto.codegen.ble.model.blegatt.CharacteristicProperty) Characteristic(org.eclipse.vorto.codegen.ble.model.blegatt.Characteristic) CharacteristicProperty(org.eclipse.vorto.codegen.ble.model.blegatt.CharacteristicProperty) FunctionblockProperty(org.eclipse.vorto.core.api.model.informationmodel.FunctionblockProperty) Property(org.eclipse.vorto.core.api.model.datatype.Property)

Example 5 with Property

use of org.eclipse.vorto.core.api.model.datatype.Property in project vorto by eclipse.

the class ModelTransformer method transformFunctionblock.

private void transformFunctionblock(FunctionblockModel fbm) {
    IMapped<FunctionblockModel> map = this.context.getMappedElement(fbm, "Service");
    if (map.hasAttribute("uuid")) {
        String uuid = map.getAttributeValue("uuid", "");
        Service service = null;
        for (Service s : this.device.getServices()) {
            if (s.getUuid().equals(uuid)) {
                service = s;
                break;
            }
        }
        if (service == null) {
            service = this.factory.createService();
            service.setUuid(uuid);
            if (map.hasAttribute("serviceName")) {
                service.setName(map.getAttributeValue("serviceName", ""));
            } else {
                service.setName(fbm.getName());
            }
            this.device.getServices().add(service);
        }
        service.getFunctionblocks().add(fbm);
        FunctionBlock fb = fbm.getFunctionblock();
        if (fb.getStatus() != null) {
            for (Property property : fb.getStatus().getProperties()) {
                transformProperty(service, property);
            }
        }
        if (fb.getConfiguration() != null) {
            for (Property property : fb.getConfiguration().getProperties()) {
                transformProperty(service, property);
            }
        }
        if (fb.getFault() != null) {
            for (Property property : fb.getFault().getProperties()) {
                transformProperty(service, property);
            }
        }
    }
}
Also used : FunctionblockModel(org.eclipse.vorto.core.api.model.functionblock.FunctionblockModel) Service(org.eclipse.vorto.codegen.ble.model.blegatt.Service) CharacteristicProperty(org.eclipse.vorto.codegen.ble.model.blegatt.CharacteristicProperty) FunctionblockProperty(org.eclipse.vorto.core.api.model.informationmodel.FunctionblockProperty) Property(org.eclipse.vorto.core.api.model.datatype.Property) FunctionBlock(org.eclipse.vorto.core.api.model.functionblock.FunctionBlock)

Aggregations

Property (org.eclipse.vorto.core.api.model.datatype.Property)11 FunctionblockModel (org.eclipse.vorto.core.api.model.functionblock.FunctionblockModel)5 FunctionblockProperty (org.eclipse.vorto.core.api.model.informationmodel.FunctionblockProperty)4 CharacteristicProperty (org.eclipse.vorto.codegen.ble.model.blegatt.CharacteristicProperty)3 Entity (org.eclipse.vorto.core.api.model.datatype.Entity)3 FunctionBlock (org.eclipse.vorto.core.api.model.functionblock.FunctionBlock)3 Enum (org.eclipse.vorto.core.api.model.datatype.Enum)2 ObjectPropertyType (org.eclipse.vorto.core.api.model.datatype.ObjectPropertyType)2 PrimitivePropertyType (org.eclipse.vorto.core.api.model.datatype.PrimitivePropertyType)2 Event (org.eclipse.vorto.core.api.model.functionblock.Event)2 InformationModel (org.eclipse.vorto.core.api.model.informationmodel.InformationModel)2 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Map (java.util.Map)1 Optional (java.util.Optional)1 Collectors (java.util.stream.Collectors)1 BasicEList (org.eclipse.emf.common.util.BasicEList)1 ENotificationImpl (org.eclipse.emf.ecore.impl.ENotificationImpl)1 ChainedCodeGeneratorTask (org.eclipse.vorto.codegen.api.ChainedCodeGeneratorTask)1 GenerationResultZip (org.eclipse.vorto.codegen.api.GenerationResultZip)1