use of org.opentosca.toscana.model.EntityId 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.model.EntityId in project TOSCAna by StuPro-TOSCAna.
the class LinkResolver method resolveRepositories.
private static void resolveRepositories(ServiceGraph graph) {
logger.debug(LogFormat.indent(1, "repositories"));
Map<String, RootNode> nodes = new TypeWrapper().wrapNodes(graph);
for (RootNode node : nodes.values()) {
for (Artifact artifact : node.getArtifacts()) {
MappingEntity artifactEntity = artifact.getBackingEntity();
Optional<Entity> repository = artifactEntity.getChild(Artifact.REPOSITORY.name);
if (repository.isPresent()) {
String url = ((ScalarEntity) repository.get()).getValue();
EntityId targetId = ToscaStructure.REPOSITORIES.descend(url);
Optional<Entity> target = graph.getEntity(targetId);
target.ifPresent(baseEntity -> {
logger.debug(LogFormat.pointAt(2, repository.get().getId(), baseEntity.getId()));
graph.replaceEntity(repository.get(), baseEntity);
});
}
}
}
}
use of org.opentosca.toscana.model.EntityId in project TOSCAna by StuPro-TOSCAna.
the class Entity method getParent.
public Optional<Entity> getParent() {
EntityId parentId = getId().ascend();
if (parentId == null) {
return Optional.empty();
}
Entity parent = graph.getEntityOrThrow(parentId);
return Optional.of(parent);
}
use of org.opentosca.toscana.model.EntityId in project TOSCAna by StuPro-TOSCAna.
the class Entity method setValue.
public <V> void setValue(ToscaKey<V> key, V value) {
EntityId id = this.id.descend(key);
final Entity newEntity;
if (BaseToscaElement.class.isAssignableFrom(key.getType())) {
newEntity = ((BaseToscaElement) value).getBackingEntity();
} else {
String normalizedValue = (value == null) ? null : value.toString();
newEntity = new ScalarEntity(normalizedValue, id, graph);
}
Optional<Entity> oldEntity = graph.getEntity(id);
if (oldEntity.isPresent()) {
graph.replaceEntity(oldEntity.get(), newEntity);
} else {
graph.addEntity(newEntity);
}
}
use of org.opentosca.toscana.model.EntityId in project TOSCAna by StuPro-TOSCAna.
the class MappingEntity method getOrNewChild.
/**
* Returns the child entity specified by given key. If the child entity does not exist yet, creates the entity.
*/
public MappingEntity getOrNewChild(ToscaKey<?> key) {
MappingEntity child;
Optional<Entity> entity = getChild(key);
if (entity.isPresent()) {
child = (MappingEntity) entity.get();
} else {
EntityId childId = getId();
if (key.getPredecessor().isPresent()) {
if (key.getPredecessor().get().isList()) {
// childId = childId.descend();
// todo
}
}
child = new MappingEntity(childId.descend(key), graph);
graph.addEntity(child);
}
return child;
}
Aggregations