Guest User

Untitled

a guest
Mar 16th, 2017
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.15 KB | None | 0 0
  1. package no.seeds.app.football;
  2.  
  3. import java.io.IOException;
  4. import java.io.InputStream;
  5. import java.nio.file.Files;
  6. import java.nio.file.Paths;
  7. import java.security.PrivateKey;
  8. import java.util.Map;
  9. import java.util.HashMap;
  10.  
  11. import com.enonic.xp.jaxrs.JaxRsComponent;
  12.  
  13. import org.codehaus.jackson.map.ObjectMapper;
  14. import org.osgi.service.component.annotations.Activate;
  15. import org.osgi.service.component.annotations.Component;
  16.  
  17. import javax.annotation.security.RolesAllowed;
  18. import javax.ws.rs.GET;
  19. import javax.ws.rs.Path;
  20. import javax.ws.rs.Produces;
  21. import javax.ws.rs.QueryParam;
  22. import javax.ws.rs.core.MediaType;
  23.  
  24. import com.enonic.xp.security.RoleKeys;
  25.  
  26. @RolesAllowed(RoleKeys.ADMIN_ID)
  27. @Path("admin/rest/config")
  28. @Component(immediate = true, configurationPid = "no.seeds.app.football", property = "group=admin")
  29. public class ConfigurationHelper implements JaxRsComponent
  30. {
  31. private static Map<String, String> configurationMap = new HashMap<String, String>();
  32.  
  33. @Activate
  34. public void activate( final Map<String, String> map )
  35. {
  36. for (Map.Entry<String, String> entry : map.entrySet()) {
  37. this.configurationMap.put(entry.getKey(), entry.getValue());
  38. }
  39.  
  40. for (Map.Entry<String, String> entry : this.configurationMap.entrySet()) {
  41. System.out.println(entry.getKey()+"\n\n");
  42. }
  43. }
  44.  
  45. @GET
  46. @Path("get")
  47. @Produces(MediaType.APPLICATION_JSON)
  48. public static String GetConfig(@QueryParam("key") String configKey) throws Exception{
  49. Map<String, String> entryResponse = new HashMap<String, String>();
  50.  
  51. ObjectMapper mapper = new ObjectMapper();
  52. System.out.println("Config Key: "+configKey+"\n\n");
  53.  
  54. for (Map.Entry<String, String> entry : configurationMap.entrySet()) {
  55. System.out.println("Test: ["+ entry.getKey().getClass() +"] "+entry.getKey() + " - ["+configKey.getClass()+"] "+configKey+"\n\n");
  56.  
  57. if(configKey.equals(entry.getKey())){
  58. System.out.println("=========== TEST PASSED");
  59. entryResponse.put((String) entry.getKey(), (String) entry.getValue());
  60. }
  61. }
  62.  
  63. return mapper.writeValueAsString(entryResponse);
  64. }
  65. }
Advertisement
Add Comment
Please, Sign In to add comment