Search in sources :

Example 1 with Card

use of org.openhab.ui.habot.card.Card in project habot by ghys.

the class CreateRuleSkill method interpret.

@Override
public IntentInterpretation interpret(Intent intent, String language) {
    IntentInterpretation interpretation = new IntentInterpretation();
    Card card = new Card("HbCreateRuleCard");
    // TODO: try to parse a day/time to pre-configure the new rule card
    interpretation.setAnswer(answerFormatter.getRandomAnswer("answer_create_rule"));
    interpretation.setCard(card);
    return interpretation;
}
Also used : IntentInterpretation(org.openhab.ui.habot.nlp.IntentInterpretation) Card(org.openhab.ui.habot.card.Card)

Example 2 with Card

use of org.openhab.ui.habot.card.Card in project habot by ghys.

the class HABotResource method createCard.

@POST
@Path("/cards")
@Produces(MediaType.APPLICATION_JSON)
@ApiOperation(value = "Creates a new card in the card deck.")
@ApiResponses(value = { @ApiResponse(code = 200, message = "The card was created"), @ApiResponse(code = 500, message = "An error occured") })
public Response createCard(@ApiParam(value = "card", required = true) Card card) {
    card.updateTimestamp();
    card.setEphemeral(false);
    Card existingCard = this.cardRegistry.get(card.getUID());
    if (existingCard != null && existingCard.isEphemeral()) {
        this.cardRegistry.remove(card.getUID());
    }
    Card createdCard = this.cardRegistry.add(card);
    return Response.ok(createdCard).build();
}
Also used : Card(org.openhab.ui.habot.card.Card) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Produces(javax.ws.rs.Produces) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Example 3 with Card

use of org.openhab.ui.habot.card.Card in project habot by ghys.

the class HABotResource method unsetCardBookmark.

@DELETE
@Path("/cards/{cardUID}/bookmark")
@ApiOperation(value = "Removes the bookmark on a card.")
@ApiResponses(value = { @ApiResponse(code = 200, message = "OK"), @ApiResponse(code = 404, message = "The card with the provided UID doesn't exist"), @ApiResponse(code = 500, message = "An error occured") })
public Response unsetCardBookmark(@PathParam("cardUID") @ApiParam(value = "cardUID", required = true) String cardUID) {
    Card card = this.cardRegistry.get(cardUID);
    if (card == null) {
        return Response.status(Status.NOT_FOUND).build();
    }
    card.setBookmark(false);
    this.cardRegistry.update(card);
    return Response.ok().build();
}
Also used : Card(org.openhab.ui.habot.card.Card) Path(javax.ws.rs.Path) DELETE(javax.ws.rs.DELETE) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Example 4 with Card

use of org.openhab.ui.habot.card.Card in project habot by ghys.

the class HABotResource method updateCard.

@PUT
@Path("/cards/{cardUID}")
@Produces(MediaType.APPLICATION_JSON)
@ApiOperation(value = "Updates a card in the card deck.")
public Response updateCard(@PathParam("cardUID") @ApiParam(value = "cardUID", required = true) String cardUID, @ApiParam(value = "card", required = true) Card card) {
    if (!card.getUID().equals(cardUID)) {
        throw new InvalidParameterException("The card UID in the body of the request should match the UID in the URL");
    }
    card.updateTimestamp();
    Card updatedCard = this.cardRegistry.update(card);
    return Response.ok(updatedCard).build();
}
Also used : InvalidParameterException(java.security.InvalidParameterException) Card(org.openhab.ui.habot.card.Card) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) ApiOperation(io.swagger.annotations.ApiOperation) PUT(javax.ws.rs.PUT)

Example 5 with Card

use of org.openhab.ui.habot.card.Card in project habot by ghys.

the class HABotResource method updateCardTimestamp.

@PUT
@Path("/cards/{cardUID}/timestamp")
@ApiOperation(value = "Updates the timestamp on a card to the current time")
@ApiResponses(value = { @ApiResponse(code = 200, message = "OK"), @ApiResponse(code = 404, message = "The card with the provided UID doesn't exist"), @ApiResponse(code = 500, message = "An error occured") })
public Response updateCardTimestamp(@PathParam("cardUID") @ApiParam(value = "cardUID", required = true) String cardUID) {
    Card card = this.cardRegistry.get(cardUID);
    if (card == null) {
        return Response.status(Status.NOT_FOUND).build();
    }
    card.updateTimestamp();
    this.cardRegistry.update(card);
    return Response.ok().build();
}
Also used : Card(org.openhab.ui.habot.card.Card) Path(javax.ws.rs.Path) ApiOperation(io.swagger.annotations.ApiOperation) PUT(javax.ws.rs.PUT) ApiResponses(io.swagger.annotations.ApiResponses)

Aggregations

Card (org.openhab.ui.habot.card.Card)8 ApiOperation (io.swagger.annotations.ApiOperation)5 Path (javax.ws.rs.Path)5 ApiResponses (io.swagger.annotations.ApiResponses)4 PUT (javax.ws.rs.PUT)3 Set (java.util.Set)2 Collectors (java.util.stream.Collectors)2 Produces (javax.ws.rs.Produces)2 IntentInterpretation (org.openhab.ui.habot.nlp.IntentInterpretation)2 Reference (org.osgi.service.component.annotations.Reference)2 InvalidParameterException (java.security.InvalidParameterException)1 DateFormat (java.text.DateFormat)1 SimpleDateFormat (java.text.SimpleDateFormat)1 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 Comparator (java.util.Comparator)1 Date (java.util.Date)1 List (java.util.List)1 DELETE (javax.ws.rs.DELETE)1 POST (javax.ws.rs.POST)1