use of org.eclipse.vorto.model.ModelContent in project vorto by eclipse.
the class DefaultPayloadMappingService method addReferencesRecursive.
/**
* Adds reference types of the given properties to the mapping Specification (needed for lookup)
*
* @param model to traverse properties
*/
private void addReferencesRecursive(IModel model, String targetPlatformKey) {
if (model instanceof Infomodel) {
Infomodel infomodel = (Infomodel) model;
for (ModelProperty property : infomodel.getFunctionblocks()) {
ModelId referenceModelId = (ModelId) property.getType();
ModelId mappingId = property.getMappingReference();
IModel referenceModel = null;
if (mappingId != null) {
referenceModel = getModelContentByModelAndMappingId(referenceModelId.getPrettyFormat(), mappingId.getPrettyFormat());
} else {
ModelContent modelContent = getModelContent(referenceModelId, targetPlatformKey);
referenceModel = modelContent.getModels().get(modelContent.getRoot());
}
property.setType((FunctionblockModel) referenceModel);
addReferencesRecursive(referenceModel, targetPlatformKey);
}
} else if (model instanceof EntityModel) {
EntityModel entityModel = (EntityModel) model;
for (ModelProperty property : entityModel.getProperties()) {
initStereotypeIfMissing(property);
if (property.getType() instanceof ModelId) {
ModelId referenceModelId = (ModelId) property.getType();
ModelId mappingId = property.getMappingReference();
IModel referenceModel = null;
if (mappingId != null) {
referenceModel = getModelContentByModelAndMappingId(referenceModelId.getPrettyFormat(), mappingId.getPrettyFormat());
} else {
ModelContent modelContent = getModelContent(referenceModelId, targetPlatformKey);
referenceModel = modelContent.getModels().get(modelContent.getRoot());
}
if (referenceModel instanceof EntityModel) {
property.setType((EntityModel) referenceModel);
addReferencesRecursive(referenceModel, targetPlatformKey);
} else {
property.setType((EnumModel) referenceModel);
}
}
}
} else if (model instanceof FunctionblockModel) {
FunctionblockModel fbModel = (FunctionblockModel) model;
for (ModelProperty property : fbModel.getProperties()) {
initStereotypeIfMissing(property);
if (property.getType() instanceof ModelId) {
ModelId referenceModelId = (ModelId) property.getType();
ModelId mappingId = property.getMappingReference();
IModel referenceModel = null;
if (mappingId != null) {
referenceModel = getModelContentByModelAndMappingId(referenceModelId.getPrettyFormat(), mappingId.getPrettyFormat());
} else {
ModelContent modelContent = getModelContent(referenceModelId, targetPlatformKey);
referenceModel = modelContent.getModels().get(modelContent.getRoot());
}
if (referenceModel instanceof EntityModel) {
property.setType((EntityModel) referenceModel);
addReferencesRecursive(referenceModel, targetPlatformKey);
} else {
property.setType((EnumModel) referenceModel);
}
}
}
}
}
use of org.eclipse.vorto.model.ModelContent in project vorto by eclipse.
the class DefaultPayloadMappingService method getOrCreateSpecification.
@Override
public IMappingSpecification getOrCreateSpecification(ModelId modelId) {
ModelContent modelContent = getModelContent(modelId, createTargetPlatformKey(modelId));
Infomodel infomodel = (Infomodel) modelContent.getModels().get(modelContent.getRoot());
MappingSpecification specification = new MappingSpecification();
specification.setInfoModel(infomodel);
addReferencesRecursive(infomodel, infomodel.getTargetPlatformKey());
return specification;
}
use of org.eclipse.vorto.model.ModelContent in project vorto by eclipse.
the class ModelIdToModelContentConverterTest method testConvertWithoutTargetPlatformLatestTag.
@Test
public void testConvertWithoutTargetPlatformLatestTag() throws Exception {
setupTestDataForLatestTag();
ModelIdToModelContentConverter converter = new ModelIdToModelContentConverter(this.repositoryFactory);
ModelContent content = converter.convert(ModelId.fromPrettyFormat("org.eclipse.vorto.examples.type:Color:latest"), Optional.empty());
assertEquals(ModelId.fromPrettyFormat("org.eclipse.vorto.examples.type:Color:1.0.1"), content.getModels().get(content.getRoot()).getId());
assertEquals(0, ((EntityModel) content.getModels().get(content.getRoot())).getStereotypes().size());
}
use of org.eclipse.vorto.model.ModelContent in project vorto by eclipse.
the class ModelIdToModelContentConverterTest method testConvertWithoutTargetPlatform.
@Test
public void testConvertWithoutTargetPlatform() throws Exception {
importModel("Color.type");
importModel("sample.mapping");
ModelIdToModelContentConverter converter = new ModelIdToModelContentConverter(this.repositoryFactory);
ModelContent content = converter.convert(ModelId.fromPrettyFormat("org.eclipse.vorto.examples.type:Color:1.0.0"), Optional.empty());
assertEquals(ModelId.fromPrettyFormat("org.eclipse.vorto.examples.type:Color:1.0.0"), content.getModels().get(content.getRoot()).getId());
assertEquals(0, ((EntityModel) content.getModels().get(content.getRoot())).getStereotypes().size());
}
use of org.eclipse.vorto.model.ModelContent in project vorto by eclipse.
the class ModelIdToModelContentConverterTest method testConvertFbWithMultipleProperty.
@Test
public void testConvertFbWithMultipleProperty() {
importModel("FbWithMultipleProperty.fbmodel");
ModelIdToModelContentConverter converter = new ModelIdToModelContentConverter(this.repositoryFactory);
ModelContent content = converter.convert(ModelId.fromPrettyFormat("org.eclipse.vorto:TestFb:1.0.0"), Optional.empty());
FunctionblockModel fbm = (FunctionblockModel) content.getModels().get(content.getRoot());
assertTrue(fbm.getStatusProperty("foos").get().isMultiple());
}
Aggregations