Search in sources :

Example 1 with MappingEntity

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);
}
Also used : ServiceGraph(org.opentosca.toscana.core.parse.model.ServiceGraph) MappingEntity(org.opentosca.toscana.core.parse.model.MappingEntity) Before(org.junit.Before)

Example 2 with MappingEntity

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);
    }
}
Also used : EntityId(org.opentosca.toscana.model.EntityId) ScalarEntity(org.opentosca.toscana.core.parse.model.ScalarEntity) MappingEntity(org.opentosca.toscana.core.parse.model.MappingEntity)

Example 3 with MappingEntity

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;
}
Also used : ScalarEntity(org.opentosca.toscana.core.parse.model.ScalarEntity) Entity(org.opentosca.toscana.core.parse.model.Entity) MappingEntity(org.opentosca.toscana.core.parse.model.MappingEntity) ServiceGraph(org.opentosca.toscana.core.parse.model.ServiceGraph)

Example 4 with MappingEntity

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;
}
Also used : MappingEntity(org.opentosca.toscana.core.parse.model.MappingEntity) Entity(org.opentosca.toscana.core.parse.model.Entity) TypeWrapper(org.opentosca.toscana.core.parse.converter.TypeWrapper) HashSet(java.util.HashSet)

Example 5 with MappingEntity

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));
    }
}
Also used : Requirement(org.opentosca.toscana.model.requirement.Requirement) ToscaKey(org.opentosca.toscana.model.util.ToscaKey) MappingEntity(org.opentosca.toscana.core.parse.model.MappingEntity) RootRelationship(org.opentosca.toscana.model.relation.RootRelationship)

Aggregations

MappingEntity (org.opentosca.toscana.core.parse.model.MappingEntity)17 Entity (org.opentosca.toscana.core.parse.model.Entity)10 ScalarEntity (org.opentosca.toscana.core.parse.model.ScalarEntity)9 ServiceGraph (org.opentosca.toscana.core.parse.model.ServiceGraph)7 EntityId (org.opentosca.toscana.model.EntityId)5 Test (org.junit.Test)3 BaseUnitTest (org.opentosca.toscana.core.BaseUnitTest)3 Artifact (org.opentosca.toscana.model.artifact.Artifact)3 RootNode (org.opentosca.toscana.model.node.RootNode)2 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 Before (org.junit.Before)1 BeforeClass (org.junit.BeforeClass)1 ToscaTemplateException (org.opentosca.toscana.core.parse.ToscaTemplateException)1 TypeWrapper (org.opentosca.toscana.core.parse.converter.TypeWrapper)1 BaseToscaElement (org.opentosca.toscana.model.BaseToscaElement)1 WebApplication (org.opentosca.toscana.model.node.WebApplication)1 Operation (org.opentosca.toscana.model.operation.Operation)1 RootRelationship (org.opentosca.toscana.model.relation.RootRelationship)1 Requirement (org.opentosca.toscana.model.requirement.Requirement)1