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