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;
}
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;
}
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")));
}
}
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();
}
}
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));
}
}
Aggregations