Java Code Examples for org.eclipse.microprofile.graphql.Description

The following examples show how to use org.eclipse.microprofile.graphql.Description. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: microprofile-graphql   Source File: HeroFinder.java    License: Apache License 2.0 6 votes vote down vote up
@Mutation
@Description("Update an item's powerLevel") 
public Item updateItemPowerLevel(@Name("itemID") long itemID,
                                 @DefaultValue("5") @Name("powerLevel") int newLevel) {
    LOG.log(Level.INFO, "updateItemPowerLevel invoked [{0}],[{1}]", new Object[]{itemID, newLevel});
    Item item = null;
    for (SuperHero hero : allHeroes()) {
        for (Item i : hero.getEquipment()) {
            if (i.getId() == itemID) {
                item = i;
                item.setPowerLevel(newLevel);
            }
        }
    }
    return item;
}
 
Example 2
Source Project: microprofile-graphql   Source File: HeroFinder.java    License: Apache License 2.0 6 votes vote down vote up
@Mutation
@Description("Update an item's powerLevel in percentage") 
public Item updateItemPowerLevelPercentage(@Name("itemID") long itemID,
                                 @JsonbNumberFormat("##'%'") @Name("powerLevel") int newLevel) {
    LOG.log(Level.INFO, "updateItemPowerLevelPercentage invoked [{0}],[{1}]", new Object[]{itemID, newLevel});
    Item item = null;
    for (SuperHero hero : allHeroes()) {
        for (Item i : hero.getEquipment()) {
            if (i.getId() == itemID) {
                item = i;
                item.setPowerLevel(newLevel/20 );
            }
        }
    }
    return item;
}
 
Example 3
Source Project: microprofile-graphql   Source File: HeroFinder.java    License: Apache License 2.0 5 votes vote down vote up
@Mutation
@Description("Adds a hero to the specified team and returns the updated team.")
public Team addHeroToTeam(@Name("hero") String heroName,
                          @Name("team") String teamName)
        throws UnknownTeamException, UnknownHeroException {

    LOG.log(Level.INFO, "addHeroToTeam invoked [{0}],[{1}]", new Object[]{heroName, teamName});
    return heroDB.getTeam(teamName)
            .addMembers(heroDB.getHero(heroName));
}
 
Example 4
Source Project: microprofile-graphql   Source File: HeroFinder.java    License: Apache License 2.0 5 votes vote down vote up
@Mutation
@Description("Removes a hero to the specified team and returns the updated team.")
public Team removeHeroFromTeam(@Name("hero") String heroName,
                               @Name("team") String teamName)
        throws UnknownTeamException, UnknownHeroException {
    LOG.log(Level.INFO, "removeHeroFromTeam invoked [{0}],[{1}]", new Object[]{heroName, teamName});
    return heroDB.getTeam(teamName)
            .removeMembers(heroDB.getHero(heroName));
}
 
Example 5
Source Project: microprofile-graphql   Source File: HeroFinder.java    License: Apache License 2.0 5 votes vote down vote up
@Mutation
@Description("Removes a hero... permanently...")
public Collection<SuperHero> removeHero(@Name("hero") String heroName) throws UnknownHeroException {
    LOG.log(Level.INFO, "removeHero invoked [{0}]", heroName);
    if (heroDB.removeHero(heroName) == null) {
        throw new UnknownHeroException(heroName);
    }
    return allHeroes();
}
 
Example 6
Source Project: microprofile-graphql   Source File: HeroFinder.java    License: Apache License 2.0 5 votes vote down vote up
@Mutation
@Description("Gives a hero new equipment")
public SuperHero provisionHero(@Name("hero") String heroName,
                               @DefaultValue(Item.CAPE) @Name("item") Item item)
        throws UnknownHeroException {
    LOG.log(Level.INFO, "provisionHero invoked [{0}],[{1}]", new Object[]{heroName, item});
    SuperHero hero = heroDB.getHero(heroName);
    if (hero == null) {
        throw new UnknownHeroException(heroName);
    }
    hero.getEquipment().add(item);
    return hero;
}
 
Example 7
Source Project: microprofile-graphql   Source File: HeroFinder.java    License: Apache License 2.0 5 votes vote down vote up
@Mutation
@Description("Removes equipment from a hero")
public SuperHero removeItemFromHero(@Name("hero") String heroName,
                                    @Name("itemID") long itemID)
        throws UnknownHeroException {
    LOG.log(Level.INFO, "removeItemFromHero invoked [{0}],[{1}]", new Object[]{heroName, itemID});
    SuperHero hero = heroDB.getHero(heroName);
    if (hero == null) {
        throw new UnknownHeroException(heroName);
    }
    hero.getEquipment().removeIf(i -> {
        return i.getId() == itemID;
    });
    return hero;
}
 
Example 8
Source Project: microprofile-graphql   Source File: HeroFinder.java    License: Apache License 2.0 5 votes vote down vote up
@Mutation
@Description("Update a hero's bank account") 
public SuperHero updateBankBalance(@Name("name") String name,
                                 @Name("bankBalance") double bankBalance) throws UnknownHeroException {
    LOG.log(Level.INFO, "updateBankBalance invoked [{0}],[{1}]", new Object[]{name, bankBalance});
    SuperHero superHero = heroDB.getHero(name);
    if(superHero!=null){
        superHero.setBankBalance(bankBalance);
    }
    return superHero;
}
 
Example 9
Source Project: microprofile-graphql   Source File: HeroFinder.java    License: Apache License 2.0 5 votes vote down vote up
@Mutation
@Description("Update a hero's bank account in US Dollar") 
public SuperHero updateBankBalanceInUS(@Name("name") String name,
                                 @JsonbNumberFormat(value = "¤ ###,###.##",locale = "en-US") 
                                 @Name("bankBalance") Double bankBalance) throws UnknownHeroException {
    LOG.log(Level.INFO, "updateBankBalance invoked [{0}],[{1}]", new Object[]{name, bankBalance});
    SuperHero superHero = heroDB.getHero(name);
    if(superHero!=null){
        superHero.setBankBalance(bankBalance);
    }
    return superHero;
}
 
Example 10
Source Project: microprofile-graphql   Source File: HeroFinder.java    License: Apache License 2.0 5 votes vote down vote up
@Mutation
@Description("Update a hero's favourite drink size") 
public SuperHero favouriteDrinkSize(@Name("name") String name,
                                 @Name("size") float size) throws UnknownHeroException {
    LOG.log(Level.INFO, "favouriteDrinkSize invoked [{0}],[{1}]", new Object[]{name, size});
    SuperHero superHero = heroDB.getHero(name);
    if(superHero!=null){
        superHero.setFavouriteDrinkSize(size);
    }
    return superHero;
}
 
Example 11
Source Project: microprofile-graphql   Source File: HeroFinder.java    License: Apache License 2.0 5 votes vote down vote up
@Mutation
@Description("Update a hero's favourite drink size in milliliters") 
public SuperHero favouriteDrinkSizeInML(@Name("name") String name,
                                 @JsonbNumberFormat(value = "000.00 'kl'") // This should be ignored due to NumberFormat below
                                 @NumberFormat(value = "###.## 'ml'", locale = "en-GB") 
                                 @Name("size") Float size) throws UnknownHeroException {
    LOG.log(Level.INFO, "favouriteDrinkSizeInML invoked [{0}],[{1}]", new Object[]{name, size});
    SuperHero superHero = heroDB.getHero(name);
    if(superHero!=null){
        superHero.setFavouriteDrinkSize(size);
    }
    return superHero;
}
 
Example 12
Source Project: microprofile-graphql   Source File: HeroFinder.java    License: Apache License 2.0 5 votes vote down vote up
@Mutation
@Description("Update a hero's net worth") 
public SuperHero updateNetWorth(@Name("name") String name,
                                 @Name("netWorth") BigDecimal netWorth) throws UnknownHeroException {
    LOG.log(Level.INFO, "updateNetWorth invoked [{0}],[{1}]", new Object[]{name, netWorth});
    SuperHero superHero = heroDB.getHero(name);
    if(superHero!=null){
        superHero.setNetWorth(netWorth);
    }
    return superHero;
}
 
Example 13
Source Project: microprofile-graphql   Source File: HeroFinder.java    License: Apache License 2.0 5 votes vote down vote up
@Mutation
@Description("Update a hero's back account in USD") 
public SuperHero updateNetWorthInUSD(@Name("name") String name,
                                 @JsonbNumberFormat(value = "¤ 000.00",locale = "en-US") 
                                 @Name("netWorth") BigDecimal netWorth) throws UnknownHeroException {
    LOG.log(Level.INFO, "updateBankBalance invoked [{0}],[{1}]", new Object[]{name, netWorth});
    SuperHero superHero = heroDB.getHero(name);
    if(superHero!=null){
        superHero.setNetWorth(netWorth);
    }
    return superHero;
}
 
Example 14
Source Project: microprofile-graphql   Source File: HeroFinder.java    License: Apache License 2.0 5 votes vote down vote up
@Mutation
@Description("All the places this hero has been") 
public SuperHero beenThere(@Name("name") String name,
                                 @Name("places") Set<String> places) throws UnknownHeroException {
    LOG.log(Level.INFO, "beenThere invoked [{0}],[{1}]", new Object[]{name, places});
    SuperHero superHero = heroDB.getHero(name);
    if(superHero!=null){
        superHero.setBeenThere(places);
    }
    return superHero;
}
 
Example 15
Source Project: microprofile-graphql   Source File: HeroFinder.java    License: Apache License 2.0 5 votes vote down vote up
@Mutation
@Description("Log the last place the hero was seen") 
public SuperHero logLocation(@Name("name") String name,
                                 @Name("coordinates") LinkedList<BigDecimal> coordinates) throws UnknownHeroException {
    LOG.log(Level.INFO, "logLocation invoked [{0}],[{1}]", new Object[]{name, coordinates});
    SuperHero superHero = heroDB.getHero(name);
    if(superHero!=null){
        superHero.setLastKnownCoordinates(coordinates);
    }
    return superHero;
}
 
Example 16
Source Project: microprofile-graphql   Source File: HeroFinder.java    License: Apache License 2.0 5 votes vote down vote up
@Mutation
@Description("Log the last place the hero was seen (Long Lat)") 
public SuperHero logLocationLongLat(@Name("name") String name,
                                 @JsonbNumberFormat(value = "00.0000000 longlat", locale = "en-GB") 
                                 @Name("coordinates") List<BigDecimal> coordinates) throws UnknownHeroException {
    LOG.log(Level.INFO, "logLocationLongLat invoked [{0}],[{1}]", new Object[]{name, coordinates});
    SuperHero superHero = heroDB.getHero(name);
    if(superHero!=null){
        superHero.setLastKnownCoordinates(coordinates);
    }
    return superHero;
}
 
Example 17
Source Project: microprofile-graphql   Source File: HeroFinder.java    License: Apache License 2.0 5 votes vote down vote up
@Mutation
@Description("Log the last few places the hero was seen") 
public SuperHero trackHero(@Name("name") String name,
                                 @Name("coordinates") List<List<BigDecimal>> coordinates) throws UnknownHeroException {
    LOG.log(Level.INFO, "trackHero invoked [{0}],[{1}]", new Object[]{name, coordinates});
    SuperHero superHero = heroDB.getHero(name);
    if(superHero!=null){
        superHero.setTrack(coordinates);
    }
    return superHero;
}
 
Example 18
Source Project: microprofile-graphql   Source File: HeroFinder.java    License: Apache License 2.0 5 votes vote down vote up
@Mutation
@Description("Log the last few places the hero was seen (Long Lat)") 
public SuperHero trackHeroLongLat(@Name("name") String name,
                    @JsonbNumberFormat(value = "00.0000000 'latlong'") // This should be ignored due to NumberFormat below
                    @Name("coordinates") List<List<@NumberFormat(value = "00.0000000 longlat", locale = "en-GB") BigDecimal>> coordinates) 
        throws UnknownHeroException {
    LOG.log(Level.INFO, "trackHeroLongLat invoked [{0}],[{1}]", new Object[]{name, coordinates});
    SuperHero superHero = heroDB.getHero(name);
    if(superHero!=null){
        superHero.setTrack(coordinates);
    }
    return superHero;
}
 
Example 19
Source Project: microprofile-graphql   Source File: HeroFinder.java    License: Apache License 2.0 5 votes vote down vote up
@Mutation
@Description("Log the last place the hero was seen (using an array)") 
public SuperHero logLocationWithArray(@Name("name") String name,
                                 @Name("coordinates") BigDecimal[] coordinates) throws UnknownHeroException {
    LOG.log(Level.INFO, "logLocationWithArray invoked [{0}],[{1}]", new Object[]{name, coordinates});
    SuperHero superHero = heroDB.getHero(name);
    if(superHero!=null){
        superHero.setLastKnownCoordinates(Arrays.asList(coordinates));
    }
    return superHero;
}
 
Example 20
Source Project: microprofile-graphql   Source File: HeroFinder.java    License: Apache License 2.0 5 votes vote down vote up
@Mutation
@Description("Log the last place the hero was seen (Long Lat) using an array") 
public SuperHero logLocationLongLatWithArray(@Name("name") String name,
                                 @JsonbNumberFormat(value = "00.0000000 longlat", locale = "en-GB") 
                                 @Name("coordinates") BigDecimal[] coordinates) throws UnknownHeroException {
    LOG.log(Level.INFO, "logLocationLongLatWithArray invoked [{0}],[{1}]", new Object[]{name, coordinates});
    SuperHero superHero = heroDB.getHero(name);
    if(superHero!=null){
        superHero.setLastKnownCoordinates(Arrays.asList(coordinates));
    }
    return superHero;
}
 
Example 21
Source Project: microprofile-graphql   Source File: HeroFinder.java    License: Apache License 2.0 5 votes vote down vote up
@Mutation
@Description("Check in a superhero") 
public SuperHero checkIn(@Name("name") String name,
                         @Name("date") LocalDate localDate) throws UnknownHeroException {
    LOG.log(Level.INFO, "checkIn invoked [{0}],[{1}]", new Object[]{name, localDate});
    SuperHero superHero = heroDB.getHero(name);
    if(superHero!=null){
        superHero.setDateOfLastCheckin(localDate);
    }
    return superHero;
}
 
Example 22
Source Project: microprofile-graphql   Source File: HeroFinder.java    License: Apache License 2.0 5 votes vote down vote up
@Mutation
@Description("Check in a superhero") 
public SuperHero checkInWithCorrectDateFormat(@Name("name") String name,
                         @JsonbDateFormat("yy dd MM") // This should be ignored due to DateFormat below
                         @DateFormat("MM/dd/yyyy") @Name("date") LocalDate localDate) throws UnknownHeroException {
    LOG.log(Level.INFO, "checkInWithCorrectDateFormat invoked [{0}],[{1}]", new Object[]{name, localDate});
    SuperHero superHero = heroDB.getHero(name);
    if(superHero!=null){
        superHero.setDateOfLastCheckin(localDate);
    }
    return superHero;
}
 
Example 23
Source Project: microprofile-graphql   Source File: HeroFinder.java    License: Apache License 2.0 5 votes vote down vote up
@Mutation
@Description("Set all the important dates for a certain hero") 
public SuperHero importantDates(@Name("name") String name,
                         @Name("dates") List<LocalDate> localDates) throws UnknownHeroException {
    LOG.log(Level.INFO, "importantDates invoked [{0}],[{1}]", new Object[]{name, localDates});
    SuperHero superHero = heroDB.getHero(name);
    if(superHero!=null){
        superHero.setImportantDates(localDates);
    }
    return superHero;
}
 
Example 24
Source Project: microprofile-graphql   Source File: HeroFinder.java    License: Apache License 2.0 5 votes vote down vote up
@Mutation
@Description("Set all the important dates (US format) for a certain hero") 
public SuperHero importantDatesUS(@Name("name") String name,
                         @JsonbDateFormat("yy dd MM") // This should be ignored due to DateFormat below
                         @Name("dates") List<@DateFormat("MM/dd/yyyy") LocalDate> localDates) throws UnknownHeroException {
    LOG.log(Level.INFO, "importantDatesUS invoked [{0}],[{1}]", new Object[]{name, localDates});
    SuperHero superHero = heroDB.getHero(name);
    if(superHero!=null){
        superHero.setImportantDates(localDates);
    }
    return superHero;
}
 
Example 25
Source Project: microprofile-graphql   Source File: HeroFinder.java    License: Apache License 2.0 5 votes vote down vote up
@Mutation
@Description("Set the time a hero started patrolling") 
public SuperHero startPatrolling(@Name("name") String name,
                         @Name("time") LocalTime localTime) throws UnknownHeroException {
    LOG.log(Level.INFO, "startPatrolling invoked [{0}],[{1}]", new Object[]{name, localTime});
    SuperHero superHero = heroDB.getHero(name);
    if(superHero!=null){
        superHero.setPatrolStartTime(localTime);
    }
    return superHero;
}
 
Example 26
Source Project: microprofile-graphql   Source File: HeroFinder.java    License: Apache License 2.0 5 votes vote down vote up
@Mutation
@Description("Set the time a hero started patrolling (using formatted time)") 
public SuperHero startPatrollingWithCorrectDateFormat(@Name("name") String name,
                         @JsonbDateFormat("HH:mm") @Name("time") LocalTime localTime) throws UnknownHeroException {
    LOG.log(Level.INFO, "startPatrollingWithCorrectDateFormat invoked [{0}],[{1}]", new Object[]{name, localTime});
    SuperHero superHero = heroDB.getHero(name);
    if(superHero!=null){
        superHero.setPatrolStartTime(localTime);
    }
    return superHero;
}
 
Example 27
Source Project: microprofile-graphql   Source File: HeroFinder.java    License: Apache License 2.0 5 votes vote down vote up
@Mutation
@Description("Start a battle") 
public SuperHero battle(@Name("name") String name,
                         @Name("dateTime") LocalDateTime localDateTime) throws UnknownHeroException {
    LOG.log(Level.INFO, "battle invoked [{0}],[{1}]", new Object[]{name, localDateTime});
    SuperHero superHero = heroDB.getHero(name);
    if(superHero!=null){
        superHero.setTimeOfLastBattle(localDateTime);
    }
    return superHero;
}
 
Example 28
Source Project: microprofile-graphql   Source File: HeroFinder.java    License: Apache License 2.0 5 votes vote down vote up
@Mutation
@Description("Start a battle") 
public SuperHero battleWithCorrectDateFormat(@Name("name") String name,
                         @JsonbDateFormat("HH:mm:ss dd-MM-yyyy") @Name("dateTime") LocalDateTime localDateTime) throws UnknownHeroException {
    LOG.log(Level.INFO, "battleWithCorrectDateFormat invoked [{0}],[{1}]", new Object[]{name, localDateTime});
    SuperHero superHero = heroDB.getHero(name);
    if(superHero!=null){
        superHero.setTimeOfLastBattle(localDateTime);
    }
    return superHero;
}
 
Example 29
Source Project: microprofile-graphql   Source File: HeroFinder.java    License: Apache License 2.0 5 votes vote down vote up
@Mutation
@Description("Set the ID Number for a hero") 
public SuperHero idNumberWithCorrectFormat(@Name("name") String name,
                         @JsonbNumberFormat("ID-00000000") @Name("id") Long idNumber) throws UnknownHeroException {
    LOG.log(Level.INFO, "idNumberWithCorrectFormat invoked [{0}],[{1}]", new Object[]{name, idNumber});
    SuperHero superHero = heroDB.getHero(name);
    if(superHero!=null){
        superHero.setIdNumber(idNumber);
    }
    return superHero;
}
 
Example 30
Source Project: microprofile-graphql   Source File: ScalarTestApi.java    License: Apache License 2.0 5 votes vote down vote up
@Query
@Description("Testing transformed date as a response")
@DateFormat(value = "dd MMM yyyy")
public LocalDate transformedDate(){
    String date = "2016-08-16";
    return LocalDate.parse(date);
}