private List<ImmutableMap<String, String>> buildApis() { Set<NamedComponent<RestxRouter>> routers = factory.queryByClass(RestxRouter.class).find(); List<ImmutableMap<String, String>> apis = Lists.newArrayList(); for (NamedComponent<RestxRouter> router : routers) { String routerApiPath = getRouterApiPath(router.getName().getName()); if (ApiDeclarationRoute.getRouterByName(factory, routerApiPath).isPresent()) { // we add the api only if we can find back the router from the name, otherwise it will trigger // 404 errors in API-DOCS apis.add(ImmutableMap.of( "path", "/@/api-docs/" + routerApiPath, "name", routerApiPath, "group", router.getComponent().getGroupName(), "description", "")); } } return apis; }
static Optional<NamedComponent<RestxRouter>> getRouterByName(Factory f, String routerName) { routerName = CaseFormat.LOWER_HYPHEN.to(CaseFormat.UPPER_CAMEL, routerName); Optional<NamedComponent<RestxRouter>> router = Optional.absent(); ImmutableList<String> suffixes = ImmutableList.of("ResourceRouter", "", "Resource", "Router"); for (int i = 0; i < suffixes.size() && !router.isPresent(); i++) { router = f.queryByName(Name.of(RestxRouter.class, routerName + suffixes.get(i))).optional().findOne(); } return router; }
Collection<Class> coldClasses = new HashSet<>(); for (Name<?> name : factory.getWarehouse().listNames()) { Optional<?> c = factory.queryByName(name).findOneAsComponent(); if (c.isPresent()) {
Class<?> dependeeClass = unsatisfiedDependency.getUnsatisfied().getComponentClass(); if (!dependerClass.getName().startsWith(hotPackage) && dependeeClass.getName().startsWith(hotPackage)) {
Class<?> dependeeClass = unsatisfiedDependency.getUnsatisfied().getComponentClass(); if (!dependerClass.getName().startsWith(hotPackage) && dependeeClass.getName().startsWith(hotPackage)) {
sb.append(" BOM:\n"); for (Query<?> query : bomQueries) { query = query.bind(this); sb.append(" - ").append(query).append("\n"); try { query.checkSatisfy(); for (Name<?> name : query.findNames()) { sb.append(" -> ").append(name).append("\n");
private <D> void buildBuildingBoxClosureForQuery( Map<Name<?>, BuildingBox<?>> dependenciesByName, Queue<BuildingBox<?>> dependenciesToSatisfy, BuildingBox<?> buildingBox, Query<D> query) { Set<? extends Name<D>> names = query.bind(this).findNames(); if (names.isEmpty() && query.isMandatory()) { Set<Name> similarNames = findSimilarNamesByNamedType(query.getComponentClass()); if (similarNames.isEmpty()) { throw UnsatisfiedDependency.on(buildingBox.hierarchy, query).raise(); Optional<MachineEngine<D>> machineFor = findMachineEngineFor(n); if (!machineFor.isPresent()) { if (query.isMandatory() && names.size() == 1) { throw UnsatisfiedDependency.on( buildingBox.hierarchy, query, machineNotFoundMessage(n)).raise();
MachineEngine<FactoryMachine> engine = machine.getEngine(name); try { machines.add(factory.buildAndStore(Query.byName(name), engine).get().getComponent()); } catch (UnsatisfiedDependenciesException e) { moreToBuild.put(name, engine); notSatisfied = notSatisfied.concat(e.getUnsatisfiedDependencies().prepend( SatisfiedQuery.of(Query.byName(name), name))); machines.add(factory.buildAndStore(Query.byName(entry.getKey()), entry.getValue()).get().getComponent()); toBuild.remove(entry.getKey()); } catch (UnsatisfiedDependenciesException e) { notSatisfied = notSatisfied.concat(e.getUnsatisfiedDependencies().prepend( SatisfiedQuery.of(Query.byName(entry.getKey()), entry.getKey())));
@Override public AutoCloseable recordIn(Map<String, Given> givens) { final Tape tape = new Tape(givens); final Factory.Query<Mapper> mapperQuery = Factory.Query.byName(Name.of(Mapper.class, "Mapper")); Factory.LocalMachines.threadLocal().addMachine( new SingleNameFactoryMachine<>(0, new StdMachineEngine<ComponentCustomizerEngine>( Name.of(ComponentCustomizerEngine.class, "JongoCollectionSequenceSupplier"), BoundlessComponentBox.FACTORY) { @Override protected ComponentCustomizerEngine doNewComponent(SatisfiedBOM satisfiedBOM) { final Mapper mapper = satisfiedBOM.getOne(mapperQuery).get().getComponent(); final ObjectIdUpdater objectIdUpdater = mapper.getObjectIdUpdater(); return new SingleComponentClassCustomizerEngine<JongoCollection>(0, JongoCollection.class) { @Override public NamedComponent<JongoCollection> customize(NamedComponent<JongoCollection> namedComponent) { final JongoCollection collection = namedComponent.getComponent(); return new NamedComponent<>(namedComponent.getName(), new SequencingJongoCollection(tape, collection, mapper, objectIdUpdater)); } }; } @Override public BillOfMaterials getBillOfMaterial() { return BillOfMaterials.of(mapperQuery); } })); return tape; }
Collection<Class> coldClasses = new HashSet<>(); for (Name<?> name : factory.getWarehouse().listNames()) { Optional<?> c = factory.queryByName(name).findOneAsComponent(); if (c.isPresent()) {
@Override public AutoCloseable recordIn(Map<String, Given> givens) { final Tape tape = new Tape(givens); final Factory.Query<Mapper> mapperQuery = Factory.Query.byName(Name.of(Mapper.class, "Mapper")); Factory.LocalMachines.threadLocal().addMachine( new SingleNameFactoryMachine<>(0, new StdMachineEngine<ComponentCustomizerEngine>( Name.of(ComponentCustomizerEngine.class, "JongoCollectionSequenceSupplier"), BoundlessComponentBox.FACTORY) { @Override protected ComponentCustomizerEngine doNewComponent(SatisfiedBOM satisfiedBOM) { final Mapper mapper = satisfiedBOM.getOne(mapperQuery).get().getComponent(); final ObjectIdUpdater objectIdUpdater = mapper.getObjectIdUpdater(); return new SingleComponentClassCustomizerEngine<JongoCollection>(0, JongoCollection.class) { @Override public NamedComponent<JongoCollection> customize(NamedComponent<JongoCollection> namedComponent) { final JongoCollection collection = namedComponent.getComponent(); return new NamedComponent<>(namedComponent.getName(), new SequencingJongoCollection(tape, collection, mapper, objectIdUpdater)); } }; } @Override public BillOfMaterials getBillOfMaterial() { return BillOfMaterials.of(mapperQuery); } })); return tape; }
public RoutingMachine() { super(0, new StdMachineEngine<RestxRouting>(Name.of(RestxRouting.class), BoundlessComponentBox.FACTORY) { private final Factory.Query<RestxFilter> filters = Factory.Query.byClass(RestxFilter.class); private final Factory.Query<RestxRouteFilter> routeFilters = Factory.Query.byClass(RestxRouteFilter.class); private final Factory.Query<RestxRouter> routers = Factory.Query.byClass(RestxRouter.class); private final Factory.Query<RestxRoute> routes = Factory.Query.byClass(RestxRoute.class); @Override public BillOfMaterials getBillOfMaterial() { return BillOfMaterials.of(filters, routeFilters, routers, routes); } @Override protected RestxRouting doNewComponent(SatisfiedBOM satisfiedBOM) { Collection<RestxRoute> r = Lists.newArrayList(); for (RestxRouter router : satisfiedBOM.getAsComponents(routers)) { r.addAll(router.getRoutes()); } Iterables.addAll(r, satisfiedBOM.getAsComponents(routes)); return new RestxRouting( ImmutableList.copyOf(satisfiedBOM.get(filters)), ImmutableList.copyOf(satisfiedBOM.get(routeFilters)), ImmutableList.copyOf(r)); } }); } }
private <T> boolean checkActive(Name<T> name) { if (name.getClazz() == String.class && name.getName().startsWith("restx.activation::")) { // can't deactivate activation keys themselves return true; } // check 'cache' for perf reasons - core Factory being immutable the 'cache' never needs to be invalidated if (deactivatedComponents.contains(name)) { return false; } if (activatedComponents.contains(name)) { return true; } // actual check Class<?> aClass = name.getClazz(); while (aClass != null) { if ("false".equals(queryByName(Name.of(String.class, activationKey(aClass, name.getName()))) .findOneAsComponent().or("true"))) { deactivatedComponents.add(name); return false; } aClass = aClass.getSuperclass(); } activatedComponents.add(name); return true; }
public RoutingMachine() { super(0, new StdMachineEngine<RestxRouting>(Name.of(RestxRouting.class), BoundlessComponentBox.FACTORY) { private final Factory.Query<RestxFilter> filters = Factory.Query.byClass(RestxFilter.class); private final Factory.Query<RestxRouteFilter> routeFilters = Factory.Query.byClass(RestxRouteFilter.class); private final Factory.Query<RestxRouter> routers = Factory.Query.byClass(RestxRouter.class); private final Factory.Query<RestxRoute> routes = Factory.Query.byClass(RestxRoute.class); @Override public BillOfMaterials getBillOfMaterial() { return BillOfMaterials.of(filters, routeFilters, routers, routes); } @Override protected RestxRouting doNewComponent(SatisfiedBOM satisfiedBOM) { Collection<RestxRoute> r = Lists.newArrayList(); for (RestxRouter router : satisfiedBOM.getAsComponents(routers)) { r.addAll(router.getRoutes()); } Iterables.addAll(r, satisfiedBOM.getAsComponents(routes)); return new RestxRouting( ImmutableList.copyOf(satisfiedBOM.get(filters)), ImmutableList.copyOf(satisfiedBOM.get(routeFilters)), ImmutableList.copyOf(r)); } }); } }
public AlternativesFactoryMachine(int priority, final Name<T> name, final ImmutableMap<T, ? extends FactoryMachine> alternatives, ComponentBox.BoxFactory boxFactory) { super(priority, new StdMachineEngine<FactoryMachine>( Name.of(FactoryMachine.class, name.getName() + "Alternatives"), priority, boxFactory) { private Factory.Query<T> query = Factory.Query.byName(name); @Override protected FactoryMachine doNewComponent(SatisfiedBOM satisfiedBOM) { FactoryMachine factoryMachine = alternatives.get(satisfiedBOM.getOne(query).get().getComponent()); if (factoryMachine != null) { return factoryMachine; } else { return NoopFactoryMachine.INSTANCE; } } @Override public BillOfMaterials getBillOfMaterial() { return BillOfMaterials.of(query); } }); } }
private Multimap<String, OperationReference> getOperationReferencesByType() { Multimap<String, OperationReference> operationsByType = ArrayListMultimap.create(); Set<NamedComponent<RestxRouter>> routers = factory.queryByClass(RestxRouter.class).find(); for (NamedComponent<RestxRouter> r : routers) { String routerApiPath = getRouterApiPath(r.getName().getName()); for (ResourceDescription resourceDescription : describeAllRoutes(r.getComponent())) { for (OperationDescription operation : resourceDescription.operations) { OperationReference ref = buildReferenceFor(routerApiPath, resourceDescription.path, operation); addIfRelevant(operationsByType, ref, operation.responseClass); Optional<OperationParameterDescription> bodyParameter = operation.findBodyParameter(); if (bodyParameter.isPresent()) { addIfRelevant(operationsByType, ref, bodyParameter.get().dataType); } } } } return operationsByType; }
private Multimap<String, OperationReference> getOperationReferencesByType() { Multimap<String, OperationReference> operationsByType = ArrayListMultimap.create(); Set<NamedComponent<RestxRouter>> routers = factory.queryByClass(RestxRouter.class).find(); for (NamedComponent<RestxRouter> r : routers) { String routerApiPath = getRouterApiPath(r.getName().getName()); for (ResourceDescription resourceDescription : describeAllRoutes(r.getComponent())) { for (OperationDescription operation : resourceDescription.operations) { OperationReference ref = buildReferenceFor(routerApiPath, resourceDescription.path, operation); addIfRelevant(operationsByType, ref, operation.responseClass); Optional<OperationParameterDescription> bodyParameter = operation.findBodyParameter(); if (bodyParameter.isPresent()) { addIfRelevant(operationsByType, ref, bodyParameter.get().dataType); } } } } return operationsByType; }
private List<ImmutableMap<String, String>> buildApis() { Set<NamedComponent<RestxRouter>> routers = factory.queryByClass(RestxRouter.class).find(); List<ImmutableMap<String, String>> apis = Lists.newArrayList(); for (NamedComponent<RestxRouter> router : routers) { String routerApiPath = getRouterApiPath(router.getName().getName()); if (ApiDeclarationRoute.getRouterByName(factory, routerApiPath).isPresent()) { // we add the api only if we can find back the router from the name, otherwise it will trigger // 404 errors in API-DOCS apis.add(ImmutableMap.of( "path", "/@/api-docs/" + routerApiPath, "name", routerApiPath, "group", router.getComponent().getGroupName(), "description", "")); } } return apis; }