Search in sources :

Example 1 with LayerDescriptor

use of org.qi4j.api.structure.LayerDescriptor in project qi4j-sdk by Qi4j.

the class AbstractSQLStartup method constructApplicationInfo.

private ApplicationInfo constructApplicationInfo(Boolean setQNameTableNameToNull) throws SQLException {
    final ApplicationInfo appInfo = new ApplicationInfo();
    final List<CompositeDescriptorInfo> valueDescriptors = new ArrayList<>();
    final Deque<Object> currentPath = new ArrayDeque<>();
    _app.descriptor().accept(new HierarchicalVisitorAdapter<Object, Object, RuntimeException>() {

        @Override
        public boolean visitEnter(Object visited) throws RuntimeException {
            if (visited instanceof LayerDescriptor || visited instanceof ModuleDescriptor) {
                currentPath.push(visited);
            }
            if (visited instanceof EntityDescriptor || visited instanceof ValueDescriptor) {
                // TODO filter non-visible descriptors away.
                if (visited instanceof EntityDescriptor) {
                    EntityDescriptor entityDescriptor = (EntityDescriptor) visited;
                    if (entityDescriptor.queryable()) {
                        LOGGER.debug("THIS ONE WORKS: {}", entityDescriptor);
                        appInfo.entityDescriptors.put(first(entityDescriptor.types()).getName(), entityDescriptor);
                    }
                } else {
                    valueDescriptors.add(new CompositeDescriptorInfo((LayerDescriptor) Iterables.first(Iterables.skip(1, currentPath)), (ModuleDescriptor) Iterables.first(currentPath), (CompositeDescriptor) visited));
                }
                return false;
            }
            return true;
        }

        @Override
        public boolean visitLeave(Object visited) {
            if (visited instanceof LayerDescriptor || visited instanceof ModuleDescriptor) {
                currentPath.pop();
            }
            return true;
        }
    });
    for (EntityDescriptor descriptor : appInfo.entityDescriptors.values()) {
        Set<QualifiedName> newQNames = new HashSet<>();
        this.extractPropertyQNames(descriptor, this._state.qNameInfos().get(), newQNames, valueDescriptors, appInfo.enumValues, setQNameTableNameToNull);
        this.extractAssociationQNames(descriptor, this._state.qNameInfos().get(), newQNames, setQNameTableNameToNull);
        this.extractManyAssociationQNames(descriptor, this._state.qNameInfos().get(), newQNames, setQNameTableNameToNull);
        this._state.entityUsedQNames().get().put(descriptor, newQNames);
    }
    appInfo.usedValueComposites.addAll(valueDescriptors);
    return appInfo;
}
Also used : ValueDescriptor(org.qi4j.api.value.ValueDescriptor) QualifiedName(org.qi4j.api.common.QualifiedName) ArrayList(java.util.ArrayList) ArrayDeque(java.util.ArrayDeque) ModuleDescriptor(org.qi4j.api.structure.ModuleDescriptor) EntityDescriptor(org.qi4j.api.entity.EntityDescriptor) LayerDescriptor(org.qi4j.api.structure.LayerDescriptor) HashSet(java.util.HashSet)

Example 2 with LayerDescriptor

use of org.qi4j.api.structure.LayerDescriptor in project qi4j-sdk by Qi4j.

the class ApplicationVisitor method visitEnter.

@Override
public boolean visitEnter(Object visited) throws RuntimeException {
    if (visited instanceof ApplicationDescriptor) {
        ApplicationDescriptor applicationDescriptor = (ApplicationDescriptor) visited;
        appUri = context.createApplicationUri(applicationDescriptor.name());
        context.setNameAndType(appUri, applicationDescriptor.name(), Qi4jRdf.TYPE_APPLICATION);
    }
    if (visited instanceof LayerDescriptor) {
        LayerDescriptor layerDescriptor = (LayerDescriptor) visited;
        layerUri = context.createLayerUri(appUri, layerDescriptor.name());
        context.setNameAndType(layerUri, layerDescriptor.name(), Qi4jRdf.TYPE_LAYER);
        context.addRelationship(appUri, Qi4jRdf.RELATIONSHIP_LAYER, layerUri);
    }
    if (visited instanceof ModuleDescriptor) {
        ModuleDescriptor moduleDescriptor = (ModuleDescriptor) visited;
        moduleUri = context.createModuleUri(layerUri, moduleDescriptor.name());
        context.setNameAndType(layerUri, moduleDescriptor.name(), Qi4jRdf.TYPE_MODULE);
        context.addRelationship(layerUri, Qi4jRdf.RELATIONSHIP_MODULE, moduleUri);
    }
    if (visited instanceof TransientDescriptor) {
        TransientDescriptor transientDescriptor = (TransientDescriptor) visited;
        compositeUri = context.createCompositeUri(moduleUri, first(transientDescriptor.types()));
        context.addType(compositeUri, Qi4jRdf.TYPE_COMPOSITE);
        context.addRelationship(moduleUri, Qi4jRdf.RELATIONSHIP_COMPOSITE, compositeUri);
    }
    if (visited instanceof EntityDescriptor) {
        EntityDescriptor entityDescriptor = (EntityDescriptor) visited;
        compositeUri = context.createCompositeUri(moduleUri, first(entityDescriptor.types()));
        context.addType(compositeUri, Qi4jRdf.TYPE_ENTITY);
        context.addRelationship(moduleUri, Qi4jRdf.RELATIONSHIP_ENTITY, compositeUri);
    }
    if (visited instanceof ObjectDescriptor) {
        ObjectDescriptor objectDescriptor = (ObjectDescriptor) visited;
        compositeUri = context.createCompositeUri(moduleUri, first(objectDescriptor.types()));
        context.addType(compositeUri, Qi4jRdf.TYPE_OBJECT);
        context.addRelationship(moduleUri, Qi4jRdf.RELATIONSHIP_OBJECT, compositeUri);
    }
    if (visited instanceof MethodDescriptor) {
        MethodDescriptor compositeMethodDescriptor = (MethodDescriptor) visited;
        String compositeMethodUri = context.createCompositeMethodUri(compositeUri, compositeMethodDescriptor.method());
        context.addType(compositeMethodUri, Qi4jRdf.TYPE_METHOD);
        context.addRelationship(compositeUri, Qi4jRdf.RELATIONSHIP_METHOD, compositeMethodUri);
    }
    return true;
}
Also used : ModuleDescriptor(org.qi4j.api.structure.ModuleDescriptor) EntityDescriptor(org.qi4j.api.entity.EntityDescriptor) TransientDescriptor(org.qi4j.api.composite.TransientDescriptor) ObjectDescriptor(org.qi4j.api.object.ObjectDescriptor) MethodDescriptor(org.qi4j.api.composite.MethodDescriptor) ApplicationDescriptor(org.qi4j.api.structure.ApplicationDescriptor) LayerDescriptor(org.qi4j.api.structure.LayerDescriptor)

Example 3 with LayerDescriptor

use of org.qi4j.api.structure.LayerDescriptor in project qi4j-sdk by Qi4j.

the class IssueTest method testLayersCanBeCreatedInOrderDifferentFromTheirDependency.

@Test
public void testLayersCanBeCreatedInOrderDifferentFromTheirDependency() throws AssemblyException {
    Energy4Java qi4j = new Energy4Java();
    Application app = qi4j.newApplication(new ApplicationAssembler() {

        public ApplicationAssembly assemble(ApplicationAssemblyFactory applicationFactory) throws AssemblyException {
            ApplicationAssembly assembly = applicationFactory.newApplicationAssembly();
            LayerAssembly domainLayer = assembly.layer(null);
            domainLayer.setName("Domain");
            LayerAssembly infrastructureLayer = assembly.layer(null);
            infrastructureLayer.setName("Infrastructure");
            domainLayer.uses(infrastructureLayer);
            return assembly;
        }
    });
    ApplicationDescriptor model = app.descriptor();
    model.accept(new HierarchicalVisitorAdapter<Object, Object, RuntimeException>() {

        @Override
        public boolean visitEnter(Object visited) throws RuntimeException {
            return visited instanceof ApplicationDescriptor;
        }

        @Override
        public boolean visitLeave(Object visited) throws RuntimeException {
            return visited instanceof LayerDescriptor;
        }

        @Override
        public boolean visit(Object visited) throws RuntimeException {
            if (visited instanceof LayerDescriptor) {
                Iterable<? extends LayerDescriptor> usedLayers = ((LayerDescriptor) visited).usedLayers().layers();
                for (LayerDescriptor usedLayerModel : usedLayers) {
                    Assert.assertNotNull("Used layer model is null", usedLayerModel);
                }
            }
            return false;
        }
    });
}
Also used : ApplicationAssemblyFactory(org.qi4j.bootstrap.ApplicationAssemblyFactory) ApplicationAssembly(org.qi4j.bootstrap.ApplicationAssembly) LayerAssembly(org.qi4j.bootstrap.LayerAssembly) ApplicationDescriptor(org.qi4j.api.structure.ApplicationDescriptor) AssemblyException(org.qi4j.bootstrap.AssemblyException) ApplicationAssembler(org.qi4j.bootstrap.ApplicationAssembler) Energy4Java(org.qi4j.bootstrap.Energy4Java) Application(org.qi4j.api.structure.Application) LayerDescriptor(org.qi4j.api.structure.LayerDescriptor) Test(org.junit.Test)

Example 4 with LayerDescriptor

use of org.qi4j.api.structure.LayerDescriptor in project qi4j-sdk by Qi4j.

the class AbstractSQLStartup method stringToCompositeDescriptor.

protected static <TCompositeDescriptor extends CompositeDescriptor> TCompositeDescriptor stringToCompositeDescriptor(final Class<TCompositeDescriptor> descriptorClass, ApplicationDescriptor appDesc, String str) {
    Matcher matcher = DESCRIPTOR_TEXTUAL_REGEXP.matcher(str);
    if (!matcher.matches()) {
        throw new IllegalArgumentException("Descriptor textual description " + str + " was invalid.");
    }
    final String layerName = matcher.group(1);
    final String moduleName = matcher.group(2);
    final Set<String> classNames = new HashSet<>();
    Matcher typesMatcher = DESCRIPTOR_TYPES_REGEXP.matcher(matcher.group(3));
    while (typesMatcher.find()) {
        classNames.add(typesMatcher.group(0));
    }
    final CompositeDescriptor[] result = new CompositeDescriptor[1];
    appDesc.accept(new HierarchicalVisitorAdapter<Object, Object, RuntimeException>() {

        @Override
        public boolean visitEnter(Object visited) {
            boolean thisResult = true;
            if (visited instanceof LayerDescriptor) {
                thisResult = ((LayerDescriptor) visited).name().equals(layerName);
            } else if (visited instanceof ModuleDescriptor) {
                thisResult = ((ModuleDescriptor) visited).name().equals(moduleName);
            } else if (descriptorClass.isAssignableFrom(visited.getClass())) {
                CompositeDescriptor desc = (CompositeDescriptor) visited;
                if (classNames.equals(new HashSet<>(Iterables.toList(Iterables.map(new Function<Class<?>, String>() {

                    @Override
                    public String map(Class<?> from) {
                        return from.getName();
                    }
                }, desc.types()))))) {
                    result[0] = desc;
                    thisResult = false;
                }
            }
            return thisResult;
        }

        @Override
        public boolean visitLeave(Object visited) {
            return result[0] == null;
        }
    });
    return (TCompositeDescriptor) result[0];
}
Also used : Matcher(java.util.regex.Matcher) ModuleDescriptor(org.qi4j.api.structure.ModuleDescriptor) CompositeDescriptor(org.qi4j.api.composite.CompositeDescriptor) HashSet(java.util.HashSet) LayerDescriptor(org.qi4j.api.structure.LayerDescriptor)

Example 5 with LayerDescriptor

use of org.qi4j.api.structure.LayerDescriptor in project qi4j-sdk by Qi4j.

the class LayerModelFormatter method enter.

@Override
public void enter(LayerDescriptor visited) throws JSONException {
    object();
    field("name", visited.name());
    array("uses");
    UsedLayersDescriptor usedLayersDescriptor = visited.usedLayers();
    for (LayerDescriptor used : usedLayersDescriptor.layers()) {
        value(used.name());
    }
    endArray();
    array("modules");
}
Also used : UsedLayersDescriptor(org.qi4j.api.structure.UsedLayersDescriptor) LayerDescriptor(org.qi4j.api.structure.LayerDescriptor)

Aggregations

LayerDescriptor (org.qi4j.api.structure.LayerDescriptor)6 ModuleDescriptor (org.qi4j.api.structure.ModuleDescriptor)4 ApplicationDescriptor (org.qi4j.api.structure.ApplicationDescriptor)3 HashSet (java.util.HashSet)2 MethodDescriptor (org.qi4j.api.composite.MethodDescriptor)2 TransientDescriptor (org.qi4j.api.composite.TransientDescriptor)2 EntityDescriptor (org.qi4j.api.entity.EntityDescriptor)2 ArrayDeque (java.util.ArrayDeque)1 ArrayList (java.util.ArrayList)1 Stack (java.util.Stack)1 Matcher (java.util.regex.Matcher)1 DocumentBuilder (javax.xml.parsers.DocumentBuilder)1 Test (org.junit.Test)1 QualifiedName (org.qi4j.api.common.QualifiedName)1 CompositeDescriptor (org.qi4j.api.composite.CompositeDescriptor)1 DependencyDescriptor (org.qi4j.api.composite.DependencyDescriptor)1 MixinDescriptor (org.qi4j.api.mixin.MixinDescriptor)1 ObjectDescriptor (org.qi4j.api.object.ObjectDescriptor)1 Application (org.qi4j.api.structure.Application)1 UsedLayersDescriptor (org.qi4j.api.structure.UsedLayersDescriptor)1