org.eclipse.microprofile.graphql.Name Java Examples

The following examples show how to use org.eclipse.microprofile.graphql.Name. 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 File: HeroFinder.java    From microprofile-graphql with Apache License 2.0 6 votes vote down vote up
@Query
public Character character(@Name("name") String name) throws UnknownCharacterException {
    LOG.log(Level.INFO, "character invoked [{0}]", name);

    try {
        SuperHero superHero = heroDB.getHero(name);
        return superHero;
    } catch (UnknownHeroException e) {
        try {
            Sidekick sidekick = sidekickDB.getSidekick(name);
            return sidekick;
        } catch (UnknownSidekickException ex) {
            throw new UnknownCharacterException(name);
        }
    }
}
 
Example #2
Source File: HeroFinder.java    From microprofile-graphql with 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 #3
Source File: HeroFinder.java    From microprofile-graphql with 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 #4
Source File: HeroFinder.java    From microprofile-graphql with Apache License 2.0 5 votes vote down vote up
@Query
public Collection<SuperHero> allHeroesWithPower(@Name("power") String power) {
    LOG.log(Level.INFO, "allHeroesWithPower invoked [{0}]", power);
    return allHeroesByFilter(hero -> {
        return hero.getSuperPowers().contains(power);
    });
}
 
Example #5
Source File: HeroFinder.java    From microprofile-graphql with 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 #6
Source File: HeroFinder.java    From microprofile-graphql with 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 #7
Source File: HeroFinder.java    From microprofile-graphql with 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 #8
Source File: HeroFinder.java    From microprofile-graphql with 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 #9
Source File: HeroFinder.java    From microprofile-graphql with Apache License 2.0 5 votes vote down vote up
@Mutation
public SuperHero[] createNewHeroesWithArray(@Name("heroes") SuperHero[] newHeroes) throws DuplicateSuperHeroException, UnknownHeroException {
    LOG.log(Level.INFO, "createNewHeroesWithArray invoked [{0}]", newHeroes);
    List<SuperHero> asList = Arrays.asList(newHeroes);
    heroDB.addHeroes(asList);
    return newHeroes;
}
 
Example #10
Source File: HeroFinder.java    From microprofile-graphql with 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 #11
Source File: HeroFinder.java    From microprofile-graphql with 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 #12
Source File: HeroFinder.java    From microprofile-graphql with 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 #13
Source File: HeroFinder.java    From microprofile-graphql with 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 #14
Source File: HeroFinder.java    From microprofile-graphql with 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 #15
Source File: HeroFinder.java    From microprofile-graphql with 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 #16
Source File: HeroFinder.java    From microprofile-graphql with 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 #17
Source File: HeroFinder.java    From microprofile-graphql with 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 #18
Source File: HeroFinder.java    From microprofile-graphql with 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 #19
Source File: HeroFinder.java    From microprofile-graphql with 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 #20
Source File: HeroFinder.java    From microprofile-graphql with 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 #21
Source File: HeroFinder.java    From microprofile-graphql with 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 #22
Source File: HeroFinder.java    From microprofile-graphql with 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 #23
Source File: HeroFinder.java    From microprofile-graphql with 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 #24
Source File: HeroFinder.java    From microprofile-graphql with 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 #25
Source File: HeroFinder.java    From microprofile-graphql with 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 #26
Source File: HeroFinder.java    From microprofile-graphql with Apache License 2.0 5 votes vote down vote up
@Query
public String getCurrentLocation(@Name("superHero")@Source SuperHero hero) throws GraphQLException {
    LOG.log(Level.INFO, "currentLocation invoked [{0}]", hero);
    final String heroName = hero.getName();
    return heroLocator.getHeroLocation(heroName)
            .orElseThrow(() -> {
                return new GraphQLException("Cannot find location for " + heroName,
                        GraphQLException.ExceptionType.DataFetchingException);
            });
}
 
Example #27
Source File: HeroFinder.java    From microprofile-graphql with Apache License 2.0 5 votes vote down vote up
@Name("secretToken")
public Token generateSecretToken(@Source SuperHero hero,
                                  @DefaultValue("true") 
                                  @Name("maskFirstPart") boolean maskFirstPart) throws GraphQLException {
    LOG.log(Level.INFO, "generateSecretToken invoked [{0}],[{1}]", new Object[]{hero,maskFirstPart});
    
    String uuid = UUID.randomUUID().toString();
    if(maskFirstPart){
        return new Token(uuid.substring(0,uuid.length()-4).replaceAll("[A-Za-z0-9]", "*") + uuid.substring(uuid.length()-4,uuid.length()));
    }else{
        return new Token(uuid);
    }
}
 
Example #28
Source File: HeroFinder.java    From microprofile-graphql with Apache License 2.0 5 votes vote down vote up
@Mutation("setRivalTeam")
public Team setRivalTeam(@Name("teamName") String teamName, @Name("rivalTeam") Team rivalTeam)
        throws UnknownTeamException {

    LOG.log(Level.INFO, "setRivalTeam invoked [{0}],[{1}]", new Object[]{teamName, rivalTeam});
    Team team = heroDB.getTeam(teamName);
    team.setRivalTeam(rivalTeam);
    return team;
}
 
Example #29
Source File: HeroFinder.java    From microprofile-graphql with Apache License 2.0 5 votes vote down vote up
@Query
public Item getItemById(@Name("id") long id) {
    LOG.log(Level.INFO, "getItemById invoked [{0}]", id);
    for (SuperHero hero : allHeroes()) {
        for (Item item : hero.getEquipment()) {
            if (id == item.getId()) {
                return item;
            }
        }
    }
    return null;
}
 
Example #30
Source File: HeroFinder.java    From microprofile-graphql with Apache License 2.0 5 votes vote down vote up
@Mutation
public Team createNewTeam(@Name("newTeam") Team newTeam) {
    LOG.log(Level.INFO, "createNewTeam invoked [{0}]", newTeam);
    List<SuperHero> members = newTeam.getMembers();
    Team team = heroDB.createNewTeam(newTeam.getName());
    if (members != null && members.size() > 0) {
        team.setMembers(members);
    }
    team.setRivalTeam(newTeam.getRivalTeam());
    return team;
}