@Test public void testCreateProvider() throws DocumentException, IOException, InvalidArgumentsException, AlreadyExistsException, ObjectNotFoundException { String aggregatorId = "SampleAggregatorId"; WebTarget target = target("/" + ProviderOptionListContainer.PROVIDERS).queryParam("aggregatorId", aggregatorId); mockStatic(Countries.class); HashMap<String, String> hashMap = new HashMap<String, String>(); hashMap.put("at", "AUSTRIA"); when(Countries.getCountries()).thenReturn(hashMap); DataProvider dataProvider = new DataProvider("SampleId", "SampleName", "at", "SampleDescription", null, "SampleNameCode", "http: dataProvider.setCountry("AUSTRIA"); when( dataManager.createDataProvider(aggregatorId, dataProvider.getId(), dataProvider.getName(), dataProvider.getCountry(), dataProvider.getCountryCode(), dataProvider.getDescription(), dataProvider.getNameCode(), dataProvider.getHomepage(), dataProvider.getProviderType().toString(), dataProvider.getEmail())).thenReturn(dataProvider).thenThrow(new ObjectNotFoundException(aggregatorId)) .thenThrow(new AlreadyExistsException("DataProvider " + dataProvider.getId() + " already exists!")).thenThrow(new InvalidArgumentsException("Invalid Argument URL")) .thenThrow(new IOException()); Response response = target.request(MediaType.APPLICATION_XML).post(Entity.entity(dataProvider, MediaType.APPLICATION_XML), Response.class); assertEquals(201, response.getStatus()); response = target.request(MediaType.APPLICATION_XML).post(Entity.entity(dataProvider, MediaType.APPLICATION_XML), Response.class); assertEquals(404, response.getStatus()); response = target.request(MediaType.APPLICATION_XML).post(Entity.entity(dataProvider, MediaType.APPLICATION_XML), Response.class); assertEquals(409, response.getStatus()); response = target.request(MediaType.APPLICATION_XML).post(Entity.entity(dataProvider, MediaType.APPLICATION_XML), Response.class); assertEquals(400, response.getStatus()); response = target.request(MediaType.APPLICATION_JSON).post(Entity.entity(dataProvider, MediaType.APPLICATION_XML), Response.class); assertEquals(500, response.getStatus()); dataProvider.setCountry("SomeInvalidCountry"); dataProvider.setCountryCode(""); response = target.request(MediaType.APPLICATION_JSON).post(Entity.entity(dataProvider, MediaType.APPLICATION_XML), Response.class); assertEquals(400, response.getStatus()); dataProvider.setCountryCode("SomeInvalidCountryCode"); response = target.request(MediaType.APPLICATION_JSON).post(Entity.entity(dataProvider, MediaType.APPLICATION_XML), Response.class); assertEquals(400, response.getStatus()); target = target("/" + ProviderOptionListContainer.PROVIDERS); response = target.request(MediaType.APPLICATION_JSON).post(Entity.entity(dataProvider, MediaType.APPLICATION_XML), Response.class); assertEquals(406, response.getStatus()); dataProvider = new DataProvider("SampleId", null, "SampleCounty", "SampleDescription", null, "SampleNameCode", "http: response = target.request(MediaType.APPLICATION_JSON).post(Entity.entity(dataProvider, MediaType.APPLICATION_XML), Response.class); assertEquals(406, response.getStatus()); dataProvider = new DataProvider("SampleId", "SampleName", null, "SampleDescription", null, "SampleNameCode", "http: response = target.request(MediaType.APPLICATION_JSON).post(Entity.entity(dataProvider, MediaType.APPLICATION_XML), Response.class); assertEquals(406, response.getStatus()); dataProvider = new DataProvider("SampleId", "SampleName", "SampleCounty", "SampleDescription", null, "SampleNameCode", "http: response = target.request(MediaType.APPLICATION_JSON).post(Entity.entity(dataProvider, MediaType.APPLICATION_XML), Response.class); assertEquals(406, response.getStatus()); }
@POST @Consumes({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}) @Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}) @ApiOperation(value = "Create a provider.", httpMethod = "POST", response = String.class) @ApiResponses(value = { @ApiResponse(code = 201, message = "Created (Response containing a String message)"), @ApiResponse(code = 400, message = "InvalidArgumentsException"), @ApiResponse(code = 404, message = "DoesNotExistException"), @ApiResponse(code = 406, message = "MissingArgumentsException"), @ApiResponse(code = 409, message = "AlreadyExistsException"), @ApiResponse(code = 500, message = "InternalServerErrorException")}) public Response createProvider( @ApiParam(value = "AggregatorId", required = true) @QueryParam("aggregatorId") String aggregatorId, @ApiParam(value = "Provider data", required = true) DataProvider provider) throws MissingArgumentsException, AlreadyExistsException, InvalidArgumentsException, DoesNotExistException { if (aggregatorId == null || aggregatorId.equals("")) throw new MissingArgumentsException("Missing argument aggregatorId!"); String providerId = provider.getId(); String name = provider.getName(); String country = provider.getCountry(); String countryCode = provider.getCountryCode(); String description = provider.getDescription(); String nameCode = provider.getNameCode(); String homepage = provider.getHomepage(); String providerType = null; if (provider.getProviderType() != null) providerType = provider.getProviderType().toString(); String email = provider.getEmail(); if (name == null || name.isEmpty()) throw new MissingArgumentsException("Missing value: " + "Provider name must not be empty."); else if ((country == null || country.equals("")) && (countryCode == null || countryCode.equals(""))) throw new MissingArgumentsException("Missing value: " + "Provider country or countryCode must not be empty."); else if (providerType == null || providerType.equals("")) throw new MissingArgumentsException("Missing value: " + "Provider dataSetType must not be empty."); Map<String, String> countries = Countries.getCountries(); if (countryCode != null && !countryCode.equals("")) { boolean flag = false; for (Map.Entry<String, String> mapEntry : countries.entrySet()) if (mapEntry.getKey().equalsIgnoreCase(countryCode)) { country = mapEntry.getValue(); countryCode = mapEntry.getKey(); flag = true; break; } if (!flag) throw new InvalidArgumentsException("Invalid argument: " + "Provider countryCode doesn't exist."); } else if (country != null && !country.equals("")) { boolean flag = false; for (Map.Entry<String, String> mapEntry : countries.entrySet()) if (mapEntry.getValue().equalsIgnoreCase(country)) { country = mapEntry.getValue(); countryCode = mapEntry.getKey(); flag = true; break; } if (!flag) throw new InvalidArgumentsException("Invalid argument: " + "Provider country doesn't exist."); } DataProvider createdProvider = null; try { createdProvider = dataManager.createDataProvider(aggregatorId, providerId, name, country, countryCode, description, nameCode, homepage, providerType, email); } catch (IOException e) { throw new InternalServerErrorException("Internal Server Error : " + e.getMessage()); } catch (InvalidArgumentsException e) { throw new InvalidArgumentsException("Invalid argument: " + e.getMessage()); } catch (AlreadyExistsException e) { throw new AlreadyExistsException("Already exists: " + e.getMessage(), e.getDatasetId()); } catch (ObjectNotFoundException e) { throw new DoesNotExistException("Does NOT exist: " + e.getMessage()); } return Response .created(null) .entity( new Result("DataProvider with id = <" + createdProvider.getId() + "> and name = " + createdProvider.getName() + " created successfully")).build(); }
ProvidersResource { @POST @Consumes({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}) @Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}) @ApiOperation(value = "Create a provider.", httpMethod = "POST", response = String.class) @ApiResponses(value = { @ApiResponse(code = 201, message = "Created (Response containing a String message)"), @ApiResponse(code = 400, message = "InvalidArgumentsException"), @ApiResponse(code = 404, message = "DoesNotExistException"), @ApiResponse(code = 406, message = "MissingArgumentsException"), @ApiResponse(code = 409, message = "AlreadyExistsException"), @ApiResponse(code = 500, message = "InternalServerErrorException")}) public Response createProvider( @ApiParam(value = "AggregatorId", required = true) @QueryParam("aggregatorId") String aggregatorId, @ApiParam(value = "Provider data", required = true) DataProvider provider) throws MissingArgumentsException, AlreadyExistsException, InvalidArgumentsException, DoesNotExistException { if (aggregatorId == null || aggregatorId.equals("")) throw new MissingArgumentsException("Missing argument aggregatorId!"); String providerId = provider.getId(); String name = provider.getName(); String country = provider.getCountry(); String countryCode = provider.getCountryCode(); String description = provider.getDescription(); String nameCode = provider.getNameCode(); String homepage = provider.getHomepage(); String providerType = null; if (provider.getProviderType() != null) providerType = provider.getProviderType().toString(); String email = provider.getEmail(); if (name == null || name.isEmpty()) throw new MissingArgumentsException("Missing value: " + "Provider name must not be empty."); else if ((country == null || country.equals("")) && (countryCode == null || countryCode.equals(""))) throw new MissingArgumentsException("Missing value: " + "Provider country or countryCode must not be empty."); else if (providerType == null || providerType.equals("")) throw new MissingArgumentsException("Missing value: " + "Provider dataSetType must not be empty."); Map<String, String> countries = Countries.getCountries(); if (countryCode != null && !countryCode.equals("")) { boolean flag = false; for (Map.Entry<String, String> mapEntry : countries.entrySet()) if (mapEntry.getKey().equalsIgnoreCase(countryCode)) { country = mapEntry.getValue(); countryCode = mapEntry.getKey(); flag = true; break; } if (!flag) throw new InvalidArgumentsException("Invalid argument: " + "Provider countryCode doesn't exist."); } else if (country != null && !country.equals("")) { boolean flag = false; for (Map.Entry<String, String> mapEntry : countries.entrySet()) if (mapEntry.getValue().equalsIgnoreCase(country)) { country = mapEntry.getValue(); countryCode = mapEntry.getKey(); flag = true; break; } if (!flag) throw new InvalidArgumentsException("Invalid argument: " + "Provider country doesn't exist."); } DataProvider createdProvider = null; try { createdProvider = dataManager.createDataProvider(aggregatorId, providerId, name, country, countryCode, description, nameCode, homepage, providerType, email); } catch (IOException e) { throw new InternalServerErrorException("Internal Server Error : " + e.getMessage()); } catch (InvalidArgumentsException e) { throw new InvalidArgumentsException("Invalid argument: " + e.getMessage()); } catch (AlreadyExistsException e) { throw new AlreadyExistsException("Already exists: " + e.getMessage(), e.getDatasetId()); } catch (ObjectNotFoundException e) { throw new DoesNotExistException("Does NOT exist: " + e.getMessage()); } return Response .created(null) .entity( new Result("DataProvider with id = <" + createdProvider.getId() + "> and name = " + createdProvider.getName() + " created successfully")).build(); } }
ProvidersResource { @POST @Consumes({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}) @Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}) @ApiOperation(value = "Create a provider.", httpMethod = "POST", response = String.class) @ApiResponses(value = { @ApiResponse(code = 201, message = "Created (Response containing a String message)"), @ApiResponse(code = 400, message = "InvalidArgumentsException"), @ApiResponse(code = 404, message = "DoesNotExistException"), @ApiResponse(code = 406, message = "MissingArgumentsException"), @ApiResponse(code = 409, message = "AlreadyExistsException"), @ApiResponse(code = 500, message = "InternalServerErrorException")}) public Response createProvider( @ApiParam(value = "AggregatorId", required = true) @QueryParam("aggregatorId") String aggregatorId, @ApiParam(value = "Provider data", required = true) DataProvider provider) throws MissingArgumentsException, AlreadyExistsException, InvalidArgumentsException, DoesNotExistException { if (aggregatorId == null || aggregatorId.equals("")) throw new MissingArgumentsException("Missing argument aggregatorId!"); String providerId = provider.getId(); String name = provider.getName(); String country = provider.getCountry(); String countryCode = provider.getCountryCode(); String description = provider.getDescription(); String nameCode = provider.getNameCode(); String homepage = provider.getHomepage(); String providerType = null; if (provider.getProviderType() != null) providerType = provider.getProviderType().toString(); String email = provider.getEmail(); if (name == null || name.isEmpty()) throw new MissingArgumentsException("Missing value: " + "Provider name must not be empty."); else if ((country == null || country.equals("")) && (countryCode == null || countryCode.equals(""))) throw new MissingArgumentsException("Missing value: " + "Provider country or countryCode must not be empty."); else if (providerType == null || providerType.equals("")) throw new MissingArgumentsException("Missing value: " + "Provider dataSetType must not be empty."); Map<String, String> countries = Countries.getCountries(); if (countryCode != null && !countryCode.equals("")) { boolean flag = false; for (Map.Entry<String, String> mapEntry : countries.entrySet()) if (mapEntry.getKey().equalsIgnoreCase(countryCode)) { country = mapEntry.getValue(); countryCode = mapEntry.getKey(); flag = true; break; } if (!flag) throw new InvalidArgumentsException("Invalid argument: " + "Provider countryCode doesn't exist."); } else if (country != null && !country.equals("")) { boolean flag = false; for (Map.Entry<String, String> mapEntry : countries.entrySet()) if (mapEntry.getValue().equalsIgnoreCase(country)) { country = mapEntry.getValue(); countryCode = mapEntry.getKey(); flag = true; break; } if (!flag) throw new InvalidArgumentsException("Invalid argument: " + "Provider country doesn't exist."); } DataProvider createdProvider = null; try { createdProvider = dataManager.createDataProvider(aggregatorId, providerId, name, country, countryCode, description, nameCode, homepage, providerType, email); } catch (IOException e) { throw new InternalServerErrorException("Internal Server Error : " + e.getMessage()); } catch (InvalidArgumentsException e) { throw new InvalidArgumentsException("Invalid argument: " + e.getMessage()); } catch (AlreadyExistsException e) { throw new AlreadyExistsException("Already exists: " + e.getMessage(), e.getDatasetId()); } catch (ObjectNotFoundException e) { throw new DoesNotExistException("Does NOT exist: " + e.getMessage()); } return Response .created(null) .entity( new Result("DataProvider with id = <" + createdProvider.getId() + "> and name = " + createdProvider.getName() + " created successfully")).build(); } ProvidersResource();  ProvidersResource(DefaultDataManager dataManager); }
ProvidersResource { @POST @Consumes({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}) @Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}) @ApiOperation(value = "Create a provider.", httpMethod = "POST", response = String.class) @ApiResponses(value = { @ApiResponse(code = 201, message = "Created (Response containing a String message)"), @ApiResponse(code = 400, message = "InvalidArgumentsException"), @ApiResponse(code = 404, message = "DoesNotExistException"), @ApiResponse(code = 406, message = "MissingArgumentsException"), @ApiResponse(code = 409, message = "AlreadyExistsException"), @ApiResponse(code = 500, message = "InternalServerErrorException")}) public Response createProvider( @ApiParam(value = "AggregatorId", required = true) @QueryParam("aggregatorId") String aggregatorId, @ApiParam(value = "Provider data", required = true) DataProvider provider) throws MissingArgumentsException, AlreadyExistsException, InvalidArgumentsException, DoesNotExistException { if (aggregatorId == null || aggregatorId.equals("")) throw new MissingArgumentsException("Missing argument aggregatorId!"); String providerId = provider.getId(); String name = provider.getName(); String country = provider.getCountry(); String countryCode = provider.getCountryCode(); String description = provider.getDescription(); String nameCode = provider.getNameCode(); String homepage = provider.getHomepage(); String providerType = null; if (provider.getProviderType() != null) providerType = provider.getProviderType().toString(); String email = provider.getEmail(); if (name == null || name.isEmpty()) throw new MissingArgumentsException("Missing value: " + "Provider name must not be empty."); else if ((country == null || country.equals("")) && (countryCode == null || countryCode.equals(""))) throw new MissingArgumentsException("Missing value: " + "Provider country or countryCode must not be empty."); else if (providerType == null || providerType.equals("")) throw new MissingArgumentsException("Missing value: " + "Provider dataSetType must not be empty."); Map<String, String> countries = Countries.getCountries(); if (countryCode != null && !countryCode.equals("")) { boolean flag = false; for (Map.Entry<String, String> mapEntry : countries.entrySet()) if (mapEntry.getKey().equalsIgnoreCase(countryCode)) { country = mapEntry.getValue(); countryCode = mapEntry.getKey(); flag = true; break; } if (!flag) throw new InvalidArgumentsException("Invalid argument: " + "Provider countryCode doesn't exist."); } else if (country != null && !country.equals("")) { boolean flag = false; for (Map.Entry<String, String> mapEntry : countries.entrySet()) if (mapEntry.getValue().equalsIgnoreCase(country)) { country = mapEntry.getValue(); countryCode = mapEntry.getKey(); flag = true; break; } if (!flag) throw new InvalidArgumentsException("Invalid argument: " + "Provider country doesn't exist."); } DataProvider createdProvider = null; try { createdProvider = dataManager.createDataProvider(aggregatorId, providerId, name, country, countryCode, description, nameCode, homepage, providerType, email); } catch (IOException e) { throw new InternalServerErrorException("Internal Server Error : " + e.getMessage()); } catch (InvalidArgumentsException e) { throw new InvalidArgumentsException("Invalid argument: " + e.getMessage()); } catch (AlreadyExistsException e) { throw new AlreadyExistsException("Already exists: " + e.getMessage(), e.getDatasetId()); } catch (ObjectNotFoundException e) { throw new DoesNotExistException("Does NOT exist: " + e.getMessage()); } return Response .created(null) .entity( new Result("DataProvider with id = <" + createdProvider.getId() + "> and name = " + createdProvider.getName() + " created successfully")).build(); } ProvidersResource();  ProvidersResource(DefaultDataManager dataManager); @OPTIONS @Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}) @ApiOperation(value = "Get options over providers conext.", httpMethod = "OPTIONS", response = ProviderOptionListContainer.class) @ApiResponses(value = {@ApiResponse(code = 200, message = "OK (Response containing a list of all available options)")}) ProviderOptionListContainer getOptions(); @GET @Path("/" + ProviderOptionListContainer.OPTIONS) @Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}) @ApiOperation(value = "Get options over providers conext.", httpMethod = "GET", response = ProviderOptionListContainer.class) @ApiResponses(value = {@ApiResponse(code = 200, message = "OK (Response containing a list of all available options)")}) ProviderOptionListContainer getGETOptions(); @GET @Path("/" + ProviderOptionListContainer.PROVIDERID) @Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}) @ApiOperation(value = "Get specific provider.", httpMethod = "GET", response = DataProvider.class) @ApiResponses(value = { @ApiResponse(code = 200, message = "OK (Response containing an Provider)"), @ApiResponse(code = 404, message = "DoesNotExistException")}) DataProvider getProvider(
      @ApiParam(value = "Id of provider", required = true) @PathParam("providerId") String providerId); @POST @Consumes({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}) @Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}) @ApiOperation(value = "Create a provider.", httpMethod = "POST", response = String.class) @ApiResponses(value = { @ApiResponse(code = 201, message = "Created (Response containing a String message)"), @ApiResponse(code = 400, message = "InvalidArgumentsException"), @ApiResponse(code = 404, message = "DoesNotExistException"), @ApiResponse(code = 406, message = "MissingArgumentsException"), @ApiResponse(code = 409, message = "AlreadyExistsException"), @ApiResponse(code = 500, message = "InternalServerErrorException")}) Response createProvider(
      @ApiParam(value = "AggregatorId", required = true) @QueryParam("aggregatorId") String aggregatorId,
      @ApiParam(value = "Provider data", required = true) DataProvider provider); @DELETE @Path("/" + ProviderOptionListContainer.PROVIDERID) @Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}) @ApiOperation(value = "Delete a provider.", httpMethod = "DELETE", response = String.class) @ApiResponses(value = { @ApiResponse(code = 200, message = "OK (Response containing a String message)"), @ApiResponse(code = 404, message = "DoesNotExistException"), @ApiResponse(code = 500, message = "InternalServerErrorException")}) Response deleteProvider(
      @ApiParam(value = "Id of provider", required = true) @PathParam("providerId") String dataProviderId); @PUT @Path("/" + ProviderOptionListContainer.PROVIDERID) @Consumes({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}) @Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}) @ApiOperation(value = "Update a provider.", httpMethod = "PUT", response = String.class) @ApiResponses(value = { @ApiResponse(code = 200, message = "OK (Response containing a String message)"), @ApiResponse(code = 400, message = "InvalidArgumentsException"), @ApiResponse(code = 404, message = "DoesNotExistException"), @ApiResponse(code = 406, message = "MissingArgumentsException"), @ApiResponse(code = 409, message = "AlreadyExistsException"), @ApiResponse(code = 500, message = "InternalServerErrorException")}) Response updateProvider(
      @ApiParam(value = "Id of provider", required = true) @PathParam("providerId") String providerId,
      @ApiParam(value = "Aggregator Id", required = false) @QueryParam("newAggregatorId") String newAggregatorId,
      @ApiParam(value = "Provider data", required = true) DataProvider provider); @GET @Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}) @ApiOperation(value = "Get a list of providers.", httpMethod = "GET", response = DataProvider.class, responseContainer = "List") @ApiResponses(value = { @ApiResponse(code = 200, message = "OK (Response containing a list of providers)"), @ApiResponse(code = 400, message = "InvalidArgumentsException"), @ApiResponse(code = 404, message = "DoesNotExistException")}) Response getProviderList(
      @ApiParam(value = "AggregatorId", required = true) @QueryParam("aggregatorId") String aggregatorId,
      @ApiParam(value = "Index where to start from(negative not allowed)", defaultValue = "0") @DefaultValue("0") @QueryParam("offset") int offset,
      @ApiParam(value = "Number of aggregators requested(-1 to get all)", defaultValue = "-1") @DefaultValue("-1") @QueryParam("number") int number); }
ProvidersResource { @POST @Consumes({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}) @Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}) @ApiOperation(value = "Create a provider.", httpMethod = "POST", response = String.class) @ApiResponses(value = { @ApiResponse(code = 201, message = "Created (Response containing a String message)"), @ApiResponse(code = 400, message = "InvalidArgumentsException"), @ApiResponse(code = 404, message = "DoesNotExistException"), @ApiResponse(code = 406, message = "MissingArgumentsException"), @ApiResponse(code = 409, message = "AlreadyExistsException"), @ApiResponse(code = 500, message = "InternalServerErrorException")}) public Response createProvider( @ApiParam(value = "AggregatorId", required = true) @QueryParam("aggregatorId") String aggregatorId, @ApiParam(value = "Provider data", required = true) DataProvider provider) throws MissingArgumentsException, AlreadyExistsException, InvalidArgumentsException, DoesNotExistException { if (aggregatorId == null || aggregatorId.equals("")) throw new MissingArgumentsException("Missing argument aggregatorId!"); String providerId = provider.getId(); String name = provider.getName(); String country = provider.getCountry(); String countryCode = provider.getCountryCode(); String description = provider.getDescription(); String nameCode = provider.getNameCode(); String homepage = provider.getHomepage(); String providerType = null; if (provider.getProviderType() != null) providerType = provider.getProviderType().toString(); String email = provider.getEmail(); if (name == null || name.isEmpty()) throw new MissingArgumentsException("Missing value: " + "Provider name must not be empty."); else if ((country == null || country.equals("")) && (countryCode == null || countryCode.equals(""))) throw new MissingArgumentsException("Missing value: " + "Provider country or countryCode must not be empty."); else if (providerType == null || providerType.equals("")) throw new MissingArgumentsException("Missing value: " + "Provider dataSetType must not be empty."); Map<String, String> countries = Countries.getCountries(); if (countryCode != null && !countryCode.equals("")) { boolean flag = false; for (Map.Entry<String, String> mapEntry : countries.entrySet()) if (mapEntry.getKey().equalsIgnoreCase(countryCode)) { country = mapEntry.getValue(); countryCode = mapEntry.getKey(); flag = true; break; } if (!flag) throw new InvalidArgumentsException("Invalid argument: " + "Provider countryCode doesn't exist."); } else if (country != null && !country.equals("")) { boolean flag = false; for (Map.Entry<String, String> mapEntry : countries.entrySet()) if (mapEntry.getValue().equalsIgnoreCase(country)) { country = mapEntry.getValue(); countryCode = mapEntry.getKey(); flag = true; break; } if (!flag) throw new InvalidArgumentsException("Invalid argument: " + "Provider country doesn't exist."); } DataProvider createdProvider = null; try { createdProvider = dataManager.createDataProvider(aggregatorId, providerId, name, country, countryCode, description, nameCode, homepage, providerType, email); } catch (IOException e) { throw new InternalServerErrorException("Internal Server Error : " + e.getMessage()); } catch (InvalidArgumentsException e) { throw new InvalidArgumentsException("Invalid argument: " + e.getMessage()); } catch (AlreadyExistsException e) { throw new AlreadyExistsException("Already exists: " + e.getMessage(), e.getDatasetId()); } catch (ObjectNotFoundException e) { throw new DoesNotExistException("Does NOT exist: " + e.getMessage()); } return Response .created(null) .entity( new Result("DataProvider with id = <" + createdProvider.getId() + "> and name = " + createdProvider.getName() + " created successfully")).build(); } ProvidersResource();  ProvidersResource(DefaultDataManager dataManager); @OPTIONS @Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}) @ApiOperation(value = "Get options over providers conext.", httpMethod = "OPTIONS", response = ProviderOptionListContainer.class) @ApiResponses(value = {@ApiResponse(code = 200, message = "OK (Response containing a list of all available options)")}) ProviderOptionListContainer getOptions(); @GET @Path("/" + ProviderOptionListContainer.OPTIONS) @Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}) @ApiOperation(value = "Get options over providers conext.", httpMethod = "GET", response = ProviderOptionListContainer.class) @ApiResponses(value = {@ApiResponse(code = 200, message = "OK (Response containing a list of all available options)")}) ProviderOptionListContainer getGETOptions(); @GET @Path("/" + ProviderOptionListContainer.PROVIDERID) @Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}) @ApiOperation(value = "Get specific provider.", httpMethod = "GET", response = DataProvider.class) @ApiResponses(value = { @ApiResponse(code = 200, message = "OK (Response containing an Provider)"), @ApiResponse(code = 404, message = "DoesNotExistException")}) DataProvider getProvider(
      @ApiParam(value = "Id of provider", required = true) @PathParam("providerId") String providerId); @POST @Consumes({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}) @Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}) @ApiOperation(value = "Create a provider.", httpMethod = "POST", response = String.class) @ApiResponses(value = { @ApiResponse(code = 201, message = "Created (Response containing a String message)"), @ApiResponse(code = 400, message = "InvalidArgumentsException"), @ApiResponse(code = 404, message = "DoesNotExistException"), @ApiResponse(code = 406, message = "MissingArgumentsException"), @ApiResponse(code = 409, message = "AlreadyExistsException"), @ApiResponse(code = 500, message = "InternalServerErrorException")}) Response createProvider(
      @ApiParam(value = "AggregatorId", required = true) @QueryParam("aggregatorId") String aggregatorId,
      @ApiParam(value = "Provider data", required = true) DataProvider provider); @DELETE @Path("/" + ProviderOptionListContainer.PROVIDERID) @Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}) @ApiOperation(value = "Delete a provider.", httpMethod = "DELETE", response = String.class) @ApiResponses(value = { @ApiResponse(code = 200, message = "OK (Response containing a String message)"), @ApiResponse(code = 404, message = "DoesNotExistException"), @ApiResponse(code = 500, message = "InternalServerErrorException")}) Response deleteProvider(
      @ApiParam(value = "Id of provider", required = true) @PathParam("providerId") String dataProviderId); @PUT @Path("/" + ProviderOptionListContainer.PROVIDERID) @Consumes({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}) @Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}) @ApiOperation(value = "Update a provider.", httpMethod = "PUT", response = String.class) @ApiResponses(value = { @ApiResponse(code = 200, message = "OK (Response containing a String message)"), @ApiResponse(code = 400, message = "InvalidArgumentsException"), @ApiResponse(code = 404, message = "DoesNotExistException"), @ApiResponse(code = 406, message = "MissingArgumentsException"), @ApiResponse(code = 409, message = "AlreadyExistsException"), @ApiResponse(code = 500, message = "InternalServerErrorException")}) Response updateProvider(
      @ApiParam(value = "Id of provider", required = true) @PathParam("providerId") String providerId,
      @ApiParam(value = "Aggregator Id", required = false) @QueryParam("newAggregatorId") String newAggregatorId,
      @ApiParam(value = "Provider data", required = true) DataProvider provider); @GET @Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}) @ApiOperation(value = "Get a list of providers.", httpMethod = "GET", response = DataProvider.class, responseContainer = "List") @ApiResponses(value = { @ApiResponse(code = 200, message = "OK (Response containing a list of providers)"), @ApiResponse(code = 400, message = "InvalidArgumentsException"), @ApiResponse(code = 404, message = "DoesNotExistException")}) Response getProviderList(
      @ApiParam(value = "AggregatorId", required = true) @QueryParam("aggregatorId") String aggregatorId,
      @ApiParam(value = "Index where to start from(negative not allowed)", defaultValue = "0") @DefaultValue("0") @QueryParam("offset") int offset,
      @ApiParam(value = "Number of aggregators requested(-1 to get all)", defaultValue = "-1") @DefaultValue("-1") @QueryParam("number") int number); public DefaultDataManager dataManager; }