Search in sources :

Example 6 with ModuleType

use of org.eclipse.smarthome.automation.type.ModuleType in project smarthome by eclipse.

the class ModuleTypeRegistryImpl method getConditions.

@Override
public Collection<ConditionType> getConditions(String... tags) {
    Collection<ModuleType> moduleTypes = getByTags(tags);
    Collection<ConditionType> conditionTypes = new ArrayList<ConditionType>();
    for (ModuleType mt : moduleTypes) {
        if (mt instanceof ConditionType) {
            conditionTypes.add((ConditionType) mt);
        }
    }
    return conditionTypes;
}
Also used : ModuleType(org.eclipse.smarthome.automation.type.ModuleType) ArrayList(java.util.ArrayList) CompositeConditionType(org.eclipse.smarthome.automation.type.CompositeConditionType) ConditionType(org.eclipse.smarthome.automation.type.ConditionType)

Example 7 with ModuleType

use of org.eclipse.smarthome.automation.type.ModuleType in project smarthome by eclipse.

the class ModuleTypeRegistryImpl method getByTags.

@Override
@SuppressWarnings("unchecked")
public <T extends ModuleType> Collection<T> getByTags(Locale locale, String... tags) {
    Set<String> tagSet = tags != null ? new HashSet<String>(Arrays.asList(tags)) : null;
    Collection<T> result = new ArrayList<T>(20);
    for (Provider<ModuleType> provider : elementMap.keySet()) {
        for (ModuleType mType : elementMap.get(provider)) {
            ModuleType mt = locale == null ? mType : ((ModuleTypeProvider) provider).getModuleType(mType.getUID(), locale);
            if (tagSet == null) {
                result.add((T) createCopy(mt));
            } else if (mt.getTags().containsAll(tagSet)) {
                result.add((T) createCopy(mt));
            }
        }
    }
    return result;
}
Also used : ModuleType(org.eclipse.smarthome.automation.type.ModuleType) ArrayList(java.util.ArrayList)

Example 8 with ModuleType

use of org.eclipse.smarthome.automation.type.ModuleType in project smarthome by eclipse.

the class CommandlineModuleTypeProvider method importModuleTypes.

/**
 * This method is responsible for importing a set of ModuleTypes from a specified file or URL resource.
 *
 * @param parserType is relevant to the format that you need for conversion of the ModuleTypes in text.
 * @param url a specified URL for import.
 * @throws IOException when I/O operation has failed or has been interrupted.
 * @throws ParsingException when parsing of the text fails for some reasons.
 * @see AutomationCommandsPluggable#importModuleTypes(String, URL)
 */
public Set<ModuleType> importModuleTypes(String parserType, URL url) throws IOException, ParsingException {
    Parser<ModuleType> parser = parsers.get(parserType);
    if (parser != null) {
        InputStream is = url.openStream();
        BufferedInputStream bis = new BufferedInputStream(is);
        InputStreamReader inputStreamReader = new InputStreamReader(bis);
        try {
            return importData(url, parser, inputStreamReader);
        } finally {
            inputStreamReader.close();
        }
    } else {
        throw new ParsingException(new ParsingNestedException(ParsingNestedException.MODULE_TYPE, null, new Exception("Parser " + parserType + " not available")));
    }
}
Also used : ModuleType(org.eclipse.smarthome.automation.type.ModuleType) InputStreamReader(java.io.InputStreamReader) BufferedInputStream(java.io.BufferedInputStream) BufferedInputStream(java.io.BufferedInputStream) InputStream(java.io.InputStream) ParsingException(org.eclipse.smarthome.automation.parser.ParsingException) ParsingNestedException(org.eclipse.smarthome.automation.parser.ParsingNestedException) ParsingException(org.eclipse.smarthome.automation.parser.ParsingException) ParsingNestedException(org.eclipse.smarthome.automation.parser.ParsingNestedException) IOException(java.io.IOException)

Example 9 with ModuleType

use of org.eclipse.smarthome.automation.type.ModuleType in project smarthome by eclipse.

the class ModuleTypeResource method getByUID.

@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 = LocaleUtil.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();
    }
}
Also used : Locale(java.util.Locale) ModuleType(org.eclipse.smarthome.automation.type.ModuleType) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Example 10 with ModuleType

use of org.eclipse.smarthome.automation.type.ModuleType in project smarthome by eclipse.

the class ModuleTypeGSONParser method parse.

@Override
public Set<ModuleType> parse(InputStreamReader reader) throws ParsingException {
    try {
        ModuleTypeParsingContainer mtContainer = gson.fromJson(reader, ModuleTypeParsingContainer.class);
        Set<ModuleType> result = new HashSet<ModuleType>();
        addAll(result, mtContainer.triggers);
        addAll(result, mtContainer.conditions);
        addAll(result, mtContainer.actions);
        return result;
    } catch (Exception e) {
        throw new ParsingException(new ParsingNestedException(ParsingNestedException.MODULE_TYPE, null, e));
    }
}
Also used : ModuleType(org.eclipse.smarthome.automation.type.ModuleType) ParsingException(org.eclipse.smarthome.automation.parser.ParsingException) ParsingNestedException(org.eclipse.smarthome.automation.parser.ParsingNestedException) ParsingException(org.eclipse.smarthome.automation.parser.ParsingException) ParsingNestedException(org.eclipse.smarthome.automation.parser.ParsingNestedException) HashSet(java.util.HashSet)

Aggregations

ModuleType (org.eclipse.smarthome.automation.type.ModuleType)18 ArrayList (java.util.ArrayList)11 CompositeActionType (org.eclipse.smarthome.automation.type.CompositeActionType)5 CompositeConditionType (org.eclipse.smarthome.automation.type.CompositeConditionType)5 CompositeTriggerType (org.eclipse.smarthome.automation.type.CompositeTriggerType)5 ActionType (org.eclipse.smarthome.automation.type.ActionType)4 ConditionType (org.eclipse.smarthome.automation.type.ConditionType)4 TriggerType (org.eclipse.smarthome.automation.type.TriggerType)4 ParsingException (org.eclipse.smarthome.automation.parser.ParsingException)3 ParsingNestedException (org.eclipse.smarthome.automation.parser.ParsingNestedException)3 List (java.util.List)2 ApiOperation (io.swagger.annotations.ApiOperation)1 ApiResponses (io.swagger.annotations.ApiResponses)1 BufferedInputStream (java.io.BufferedInputStream)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 InputStreamReader (java.io.InputStreamReader)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 Hashtable (java.util.Hashtable)1