@Override public ModuleType getModuleType(String typeUID, Locale locale) { if (moduleTypeRegistry != null) { return moduleTypeRegistry.get(typeUID, locale); } return null; }
@SuppressWarnings("unchecked") @Override public Collection<ActionType> getActions(Locale locale) { if (moduleTypeRegistry != null) { return moduleTypeRegistry.getActions(locale); } return null; }
@SuppressWarnings("unchecked") @Override public Collection<ConditionType> getConditions(Locale locale) { if (moduleTypeRegistry != null) { return moduleTypeRegistry.getConditions(locale); } return null; }
@GET @Produces(MediaType.APPLICATION_JSON) @ApiOperation(value = "Get all available module types.", response = ModuleTypeDTO.class, responseContainer = "List") @ApiResponses(value = { @ApiResponse(code = 200, message = "OK", response = ModuleTypeDTO.class, responseContainer = "List") }) public Response getAll(@HeaderParam("Accept-Language") @ApiParam(value = "language") String language, @QueryParam("tags") @ApiParam(value = "tags for filtering", required = false) String tagList, @QueryParam("type") @ApiParam(value = "filtering by action, condition or trigger", required = false) String type) { final Locale locale = localeService.getLocale(language); final String[] tags = tagList != null ? tagList.split(",") : null; final List<ModuleTypeDTO> modules = new ArrayList<ModuleTypeDTO>(); if (type == null || type.equals("trigger")) { modules.addAll(TriggerTypeDTOMapper.map(moduleTypeRegistry.getTriggers(locale, tags))); } if (type == null || type.equals("condition")) { modules.addAll(ConditionTypeDTOMapper.map(moduleTypeRegistry.getConditions(locale, tags))); } if (type == null || type.equals("action")) { modules.addAll(ActionTypeDTOMapper.map(moduleTypeRegistry.getActions(locale, tags))); } return Response.ok(modules).build(); }
@SuppressWarnings("unchecked") @Override public Collection<TriggerType> getTriggers(Locale locale) { if (moduleTypeRegistry != null) { return moduleTypeRegistry.getTriggers(locale); } return null; }
/** * Unbind the {@link ModuleTypeRegistry} service - called from DS. * * @param moduleTypeRegistry a {@link ModuleTypeRegistry} service. */ protected void unsetModuleTypeRegistry(ModuleTypeRegistry moduleTypeRegistry) { mtRegistry.removeRegistryChangeListener(this); mtRegistry = null; }
/** * Bind the {@link ModuleTypeRegistry} service - called from DS. * * @param moduleTypeRegistry a {@link ModuleTypeRegistry} service. */ @Reference protected void setModuleTypeRegistry(ModuleTypeRegistry moduleTypeRegistry) { mtRegistry = moduleTypeRegistry; mtRegistry.addRegistryChangeListener(this); }
/** * Gets the {@link ModuleHandlerFactory} for the {@link ModuleType} with the specified UID. * * @param moduleTypeId the UID of the {@link ModuleType}. * @return the {@link ModuleHandlerFactory} responsible for the {@link ModuleType}. */ public @Nullable ModuleHandlerFactory getModuleHandlerFactory(String moduleTypeId) { ModuleHandlerFactory mhf = null; synchronized (this) { mhf = moduleHandlerFactories.get(moduleTypeId); } if (mhf == null) { ModuleType mt = mtRegistry.get(moduleTypeId); if (mt instanceof CompositeTriggerType || // mt instanceof CompositeConditionType || // mt instanceof CompositeActionType) { mhf = compositeFactory; } } return mhf; }
@GET @Path("/{moduleTypeUID}") @Produces(MediaType.APPLICATION_JSON) @ApiOperation(value = "Gets a module type corresponding to the given UID.", response = ModuleTypeDTO.class) @ApiResponses(value = { @ApiResponse(code = 200, message = "OK", response = ModuleTypeDTO.class), @ApiResponse(code = 404, message = "Module Type corresponding to the given UID does not found.") }) public Response getByUID(@HeaderParam("Accept-Language") @ApiParam(value = "language") String language, @PathParam("moduleTypeUID") @ApiParam(value = "moduleTypeUID", required = true) String moduleTypeUID) { Locale locale = localeService.getLocale(language); final ModuleType moduleType = moduleTypeRegistry.get(moduleTypeUID, locale); if (moduleType != null) { return Response.ok(getModuleTypeDTO(moduleType)).build(); } else { return Response.status(Status.NOT_FOUND).build(); } }
/** * This method is responsible for checking the existence of {@link ModuleType}s with the same * UIDs before these objects to be added in the system. * * @param uid UID of the newly created {@link ModuleType}, which to be checked. * @param exceptions accumulates exceptions if {@link ModuleType} with the same UID exists. */ protected void checkExistence(String uid, List<ParsingNestedException> exceptions) { if (this.moduleTypeRegistry == null) { exceptions.add(new ParsingNestedException(ParsingNestedException.MODULE_TYPE, uid, new IllegalArgumentException("Failed to create Module Type with UID \"" + uid + "\"! Can't guarantee yet that other Module Type with the same UID does not exist."))); } if (moduleTypeRegistry.get(uid) != null) { exceptions.add(new ParsingNestedException(ParsingNestedException.MODULE_TYPE, uid, new IllegalArgumentException("Module Type with UID \"" + uid + "\" already exists! Failed to create a second with the same UID!"))); } }
/** * This method is used to obtain a {@link ModuleHandler} for the specified {@link ModuleImpl}. * * @param m the {@link ModuleImpl} which is looking for a handler. * @param ruleUID UID of the {@link Rule} that the specified {@link ModuleImpl} belongs to. * @return handler that processing this module. Could be {@code null} if the {@link ModuleHandlerFactory} is not * available. */ private @Nullable ModuleHandler getModuleHandler(Module m, String ruleUID) { String moduleTypeId = m.getTypeUID(); ModuleHandlerFactory mhf = getModuleHandlerFactory(moduleTypeId); if (mhf == null || mtRegistry.get(moduleTypeId) == null) { return null; } return mhf.getHandler(m, ruleUID); }
TriggerType triggerType = (TriggerType) mtRegistry.get(triggerTypeUID); if (triggerType == null) { throw new IllegalArgumentException(
@NonNull List<? extends @NonNull Trigger> triggers) { ConditionType type = (ConditionType) mtRegistry.get(condition.getTypeUID()); // get module type of the condition if (type == null) {
/** * Normalizes the configurations of the provided {@link ModuleImpl}s. * * @param modules a list of {@link ModuleImpl}s to normalize. * @param mtRegistry the {@link ModuleTypeRegistry} that provides the meta-data needed for the normalization. * @see ConfigurationNormalizer#normalizeConfiguration(Configuration, Map) */ public static <T extends Module> void normalizeModuleConfigurations(List<T> modules, ModuleTypeRegistry mtRegistry) { for (Module module : modules) { ModuleType mt = mtRegistry.get(module.getTypeUID()); if (mt != null) { Map<String, ConfigDescriptionParameter> mapConfigDescriptions = getConfigDescriptionMap( mt.getConfigurationDescriptions()); normalizeConfiguration(module.getConfiguration(), mapConfigDescriptions); } } }
@NonNull List<? extends @NonNull Trigger> triggers, @NonNull List<? extends @NonNull Action> actions) { ActionType type = (ActionType) mtRegistry.get(action.getTypeUID()); // get module type of the condition if (type == null) {
if (moduleId != null && action != null) { String typeUID = action.getTypeUID(); ActionType actionType = (ActionType) mtRegistry.get(typeUID); if (actionType == null) { throw new IllegalArgumentException(msg + " Action Type with UID \"" + typeUID + "\" does not exist!");
ModuleHandler handler = null; String moduleType = module.getTypeUID(); ModuleType mt = mtRegistry.get(moduleType); if (mt instanceof CompositeTriggerType) { List<Trigger> childModules = ((CompositeTriggerType) mt).getChildren();
for (WrappedTrigger mt : rule.getTriggers()) { final Trigger t = mt.unwrap(); TriggerType tt = (TriggerType) mtRegistry.get(t.getTypeUID()); if (tt != null) { initTagsMap(t.getId(), tt.getOutputs(), triggerOutputTags); for (WrappedAction ma : rule.getActions()) { final Action a = ma.unwrap(); ActionType at = (ActionType) mtRegistry.get(a.getTypeUID()); if (at != null) { initTagsMap(a.getId(), at.getOutputs(), actionOutputTags); final Condition c = mc.unwrap(); boolean isConnectionChanged = false; ConditionType ct = (ConditionType) mtRegistry.get(c.getTypeUID()); if (ct != null) { Set<Connection> connections = copyConnections(mc.getConnections()); final Action a = ma.unwrap(); boolean isConnectionChanged = false; ActionType at = (ActionType) mtRegistry.get(a.getTypeUID()); if (at != null) { Set<Connection> connections = copyConnections(ma.getConnections());