Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package no.seeds.app.football;
- import java.io.IOException;
- import java.io.InputStream;
- import java.nio.file.Files;
- import java.nio.file.Paths;
- import java.security.PrivateKey;
- import java.util.Map;
- import java.util.HashMap;
- import com.enonic.xp.jaxrs.JaxRsComponent;
- import org.codehaus.jackson.map.ObjectMapper;
- import org.osgi.service.component.annotations.Activate;
- import org.osgi.service.component.annotations.Component;
- import javax.annotation.security.RolesAllowed;
- import javax.ws.rs.GET;
- import javax.ws.rs.Path;
- import javax.ws.rs.Produces;
- import javax.ws.rs.QueryParam;
- import javax.ws.rs.core.MediaType;
- import com.enonic.xp.security.RoleKeys;
- @RolesAllowed(RoleKeys.ADMIN_ID)
- @Path("admin/rest/config")
- @Component(immediate = true, configurationPid = "no.seeds.app.football", property = "group=admin")
- public class ConfigurationHelper implements JaxRsComponent
- {
- private static Map<String, String> configurationMap = new HashMap<String, String>();
- @Activate
- public void activate( final Map<String, String> map )
- {
- for (Map.Entry<String, String> entry : map.entrySet()) {
- this.configurationMap.put(entry.getKey(), entry.getValue());
- }
- for (Map.Entry<String, String> entry : this.configurationMap.entrySet()) {
- System.out.println(entry.getKey()+"\n\n");
- }
- }
- @GET
- @Path("get")
- @Produces(MediaType.APPLICATION_JSON)
- public static String GetConfig(@QueryParam("key") String configKey) throws Exception{
- Map<String, String> entryResponse = new HashMap<String, String>();
- ObjectMapper mapper = new ObjectMapper();
- System.out.println("Config Key: "+configKey+"\n\n");
- for (Map.Entry<String, String> entry : configurationMap.entrySet()) {
- System.out.println("Test: ["+ entry.getKey().getClass() +"] "+entry.getKey() + " - ["+configKey.getClass()+"] "+configKey+"\n\n");
- if(configKey.equals(entry.getKey())){
- System.out.println("=========== TEST PASSED");
- entryResponse.put((String) entry.getKey(), (String) entry.getValue());
- }
- }
- return mapper.writeValueAsString(entryResponse);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment