use of org.opentosca.toscana.core.parse.model.MappingEntity in project TOSCAna by StuPro-TOSCAna.
the class MapperUtilsTest method setUp.
@Before
public void setUp() {
ServiceGraph graph = new ServiceGraph(logMock());
entity = new MappingEntity(entityId, graph);
graph.addEntity(entity);
}
use of org.opentosca.toscana.core.parse.model.MappingEntity in project TOSCAna by StuPro-TOSCAna.
the class GraphNormalizer method normalize.
private static void normalize(ServiceGraph graph, Entity entity, String... referencedKeys) {
if (entity instanceof ScalarEntity) {
ScalarEntity shortEntity = (ScalarEntity) entity;
MappingEntity normalizedEntity = new MappingEntity(shortEntity.getId(), graph);
EntityId referencedId = shortEntity.getId();
for (String referencedKey : referencedKeys) {
referencedId = referencedId.descend(referencedKey);
}
ScalarEntity referencedEntity = new ScalarEntity(shortEntity.getValue(), referencedId, graph);
graph.replaceEntity(shortEntity, normalizedEntity);
graph.addEntity(referencedEntity);
}
}
use of org.opentosca.toscana.core.parse.model.MappingEntity in project TOSCAna by StuPro-TOSCAna.
the class IntrinsicFunctionResolver method resolveFunction.
/**
* @param functionHolder the outcome of a call to {@link #holdsFunction(Entity)} with this entity must be true
* @return returns the resolved target. Returns null if target does not exist and function type allows missing target
* @throws IllegalStateException if call to {@link #holdsFunction(Entity)}
* with same entity as argument comes out as false
*/
public static Entity resolveFunction(Entity functionHolder) throws AttributeNotSetException {
if (!holdsFunction(functionHolder)) {
throw new IllegalStateException(String.format("Given entity '%s' does not hold a function - illegal call to resolveFunction", functionHolder));
}
Entity parent = functionHolder.getParent().orElseThrow(() -> new IllegalStateException("Function does not have a parent"));
Entity functionTarget = getTarget((MappingEntity) functionHolder);
if (functionTarget != null) {
ServiceGraph graph = functionHolder.getGraph();
// only removing connection - the actual function entities stay in the graph; might be easier for debugging
graph.removeEdge(parent, functionHolder);
graph.addConnection(parent, functionTarget, functionHolder.getName());
}
return functionTarget;
}
use of org.opentosca.toscana.core.parse.model.MappingEntity in project TOSCAna by StuPro-TOSCAna.
the class BaseToscaElement method getThisAsSet.
protected <T> Set<T> getThisAsSet(Class<T> type) {
TypeWrapper factory = new TypeWrapper();
Collection<Entity> values = mappingEntity.getChildren();
Set<T> results = new HashSet<>();
for (Entity v : values) {
T result = factory.wrapEntity((MappingEntity) v, type);
results.add(result);
}
return results;
}
use of org.opentosca.toscana.core.parse.model.MappingEntity in project TOSCAna by StuPro-TOSCAna.
the class KeyReflector method detectRealSubtype.
/**
* Returns the real class belonging to given entity.
*
* @param type the (possibly abstract) parent class
* @return the real class, is a subclass of given type
*/
public static Class detectRealSubtype(MappingEntity entity, Class type) {
MappingEntity nodeEntity = NavigationUtil.getEnclosingNode(entity);
String nodeTypeIdentifier = nodeEntity.getValue(BaseToscaElement.TYPE);
Class nodeType = TypeResolver.resolve(nodeTypeIdentifier);
String filterName;
Class toscaKeyType;
ToscaKey result;
if (Capability.class.isAssignableFrom(type)) {
filterName = entity.getName();
toscaKeyType = type;
result = detectRealKey(entity, nodeType, toscaKeyType, filterName);
return result.getType();
} else if (RootRelationship.class.isAssignableFrom(type)) {
filterName = entity.getParent().get().getName();
toscaKeyType = Requirement.class;
result = detectRealKey(entity, nodeType, toscaKeyType, filterName);
return (Class) result.getDirectives().get(RequirementKey.RELATIONSHIP);
} else {
throw new IllegalStateException(String.format("Conversion of given abstract type %s not yet supported", type));
}
}
Aggregations