use of org.eclipse.vorto.repository.api.content.ModelProperty in project vorto by eclipse.
the class ModelDtoFactory method createProperty.
private static ModelProperty createProperty(FunctionblockProperty property, Optional<MappingModel> mappingModel) {
ModelProperty p = new ModelProperty();
p.setDescription(property.getDescription());
p.setName(property.getName());
p.setType(createModelId(property.getType()));
if (mappingModel.isPresent()) {
p.setTargetPlatformKey(mappingModel.get().getTargetPlatform());
for (MappingRule rule : getPropertyRule(p.getName(), mappingModel.get().getRules())) {
if (rule.getTarget() instanceof StereoTypeTarget) {
StereoTypeTarget target = (StereoTypeTarget) rule.getTarget();
p.addStereotype(Stereotype.create(target.getName(), convertAttributesToMap(target.getAttributes())));
} else if (rule.getTarget() instanceof ReferenceTarget) {
ReferenceTarget target = (ReferenceTarget) rule.getTarget();
p.setMappingReference(createModelId(target.getMappingModel()));
}
}
}
return p;
}
use of org.eclipse.vorto.repository.api.content.ModelProperty 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.repository.api.content.ModelProperty in project vorto by eclipse.
the class MappingSpecificationBuilder method build.
public IMappingSpecification build() {
try {
Infomodel infomodel = this.repositoryClient.getContent(ModelId.fromPrettyFormat(this.modelId), Infomodel.class, this.targetPlatformKey).get();
DefaultMappingSpecification specification = new DefaultMappingSpecification();
specification.setInfomodel(infomodel);
for (ModelProperty fbProperty : infomodel.getFunctionblocks()) {
ModelId fbModelId = (ModelId) fbProperty.getType();
ModelId mappingId = fbProperty.getMappingReference();
FunctionblockModel fbm;
if (mappingId != null) {
fbm = this.repositoryClient.getContent(fbModelId, FunctionblockModel.class, mappingId).get();
} else {
fbm = this.repositoryClient.getContent(fbModelId, FunctionblockModel.class, this.targetPlatformKey).get();
}
if (fbm.getStereotype(STEREOTYPE_FUNCTIONS).isPresent()) {
Stereotype functionsStereotype = fbm.getStereotype(STEREOTYPE_FUNCTIONS).get();
JavascriptFunctions functions = new JavascriptFunctions(fbProperty.getName().toLowerCase());
for (String functionName : functionsStereotype.getAttributes().keySet()) {
if (!"_namespace".equalsIgnoreCase(functionName)) {
functions.addFunction(functionName, functionsStereotype.getAttributes().get(functionName));
}
}
this.library.addFunctions(functions);
}
specification.getFbs().put(fbProperty.getName(), fbm);
}
specification.setLibrary(this.library);
return specification;
} catch (Exception e) {
throw new MappingSpecificationProblem("Problem reading mapping specification", e);
}
}
use of org.eclipse.vorto.repository.api.content.ModelProperty in project vorto by eclipse.
the class DefaultMappingClient method newPropertyQuery.
@Override
public IMappingQuery<ModelProperty> newPropertyQuery(IMappedElement element) {
final List<ModelProperty> properties = new ArrayList<ModelProperty>();
if (element instanceof FunctionblockModel) {
FunctionblockModel fbm = (FunctionblockModel) element;
properties.addAll(fbm.getConfigurationProperties());
properties.addAll(fbm.getStatusProperties());
properties.addAll(fbm.getFaultProperties());
} else if (element instanceof Infomodel) {
Infomodel im = (Infomodel) element;
properties.addAll(im.getFunctionblocks());
} else if (element instanceof EntityModel) {
EntityModel entity = (EntityModel) element;
properties.addAll(entity.getProperties());
} else {
throw new UnsupportedOperationException();
}
return new MappingQueryJxPath<ModelProperty>() {
@Override
protected Collection<ModelProperty> getAll() {
return properties;
}
};
}
use of org.eclipse.vorto.repository.api.content.ModelProperty in project vorto by eclipse.
the class ModelRepositoryClientTest method testQueryModelPropertyByMappedAttribute.
@Test
public void testQueryModelPropertyByMappedAttribute() throws Exception {
FunctionblockModel accelerometer = modelRepo.getContent(ModelId.fromPrettyFormat("com.ipso.smartobjects.Accelerometer:0.0.1"), FunctionblockModel.class, "lwm2m").get();
List<ModelProperty> properties = mapping.newPropertyQuery(accelerometer).stereotype("Resource").attribute("ID", "5702").list();
assertEquals(1, properties.size());
assertEquals("x_value", properties.get(0).getName());
}
Aggregations