use of org.eclipse.smarthome.automation.template.Template in project smarthome by eclipse.
the class TemplateResource method getAll.
@GET
@Produces(MediaType.APPLICATION_JSON)
@ApiOperation(value = "Get all available templates.", response = Template.class, responseContainer = "Collection")
@ApiResponses(value = { @ApiResponse(code = 200, message = "OK", response = Template.class, responseContainer = "Collection") })
public Response getAll(@HeaderParam("Accept-Language") @ApiParam(value = "language") String language) {
Locale locale = LocaleUtil.getLocale(language);
Collection<RuleTemplateDTO> result = templateRegistry.getAll(locale).stream().map(template -> RuleTemplateDTOMapper.map(template)).collect(Collectors.toList());
return Response.ok(result).build();
}
use of org.eclipse.smarthome.automation.template.Template in project smarthome by eclipse.
the class TemplateGSONParser method parse.
@Override
public Set<Template> parse(InputStreamReader reader) throws ParsingException {
JsonReader jr = new JsonReader(reader);
try {
if (jr.hasNext()) {
JsonToken token = jr.peek();
Set<Template> templates = new HashSet<>();
if (JsonToken.BEGIN_ARRAY.equals(token)) {
templates.addAll(gson.fromJson(jr, new TypeToken<List<RuleTemplate>>() {
}.getType()));
} else {
Template template = gson.fromJson(jr, RuleTemplate.class);
templates.add(template);
}
return templates;
}
} catch (Exception e) {
throw new ParsingException(new ParsingNestedException(ParsingNestedException.TEMPLATE, null, e));
} finally {
try {
jr.close();
} catch (IOException e) {
}
}
return Collections.emptySet();
}
use of org.eclipse.smarthome.automation.template.Template in project smarthome by eclipse.
the class AutomationCommandList method listTemplates.
/**
* This method is responsible for execution of command {@link AutomationCommands#LIST_TEMPLATES}.
*
* @return a string representing understandable for the user message containing information on the outcome of the
* command {@link AutomationCommands#LIST_TEMPLATES}.
*/
private String listTemplates() {
Collection<RuleTemplate> collection = autoCommands.getTemplates(locale);
Map<String, Template> templates = new Hashtable<String, Template>();
Map<String, String> listTemplates = null;
if (collection != null && !collection.isEmpty()) {
addCollection(collection, templates);
String[] uids = new String[templates.size()];
Utils.quickSort(templates.keySet().toArray(uids), 0, templates.size());
listTemplates = Utils.putInHastable(uids);
}
if (listTemplates != null && !listTemplates.isEmpty()) {
if (id != null) {
collection = getTemplateByFilter(listTemplates);
if (collection.size() == 1) {
Template t = (Template) collection.toArray()[0];
if (t != null) {
return Printer.printTemplate(t);
} else {
return String.format("Nonexistent ID: %s", id);
}
} else if (collection.isEmpty()) {
return String.format("Nonexistent ID: %s", id);
} else {
if (!templates.isEmpty()) {
templates.clear();
}
addCollection(collection, templates);
listTemplates = Utils.filterList(templates, listTemplates);
}
}
if (listTemplates != null && !listTemplates.isEmpty()) {
return Printer.printTemplates(listTemplates);
}
}
return "There are no Templates available!";
}
Aggregations