Changeset 5917 for ComponentRegistry
- Timestamp:
- 01/15/15 15:00:00 (9 years ago)
- Location:
- ComponentRegistry/trunk/ComponentRegistry/src
- Files:
-
- 7 edited
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
ComponentRegistry/trunk/ComponentRegistry/src/main/java/clarin/cmdi/componentregistry/Configuration.java
r5549 r5917 19 19 public class Configuration { 20 20 21 private static Logger LOG = LoggerFactory.getLogger(Configuration.class);21 private final static Logger LOG = LoggerFactory.getLogger(Configuration.class); 22 22 //NOTE: Default values, can be overwritten in applicationContext.xml 23 23 private String generalComponentSchema = "https://infra.clarin.eu/cmd/general-component-schema.xsd"; 24 24 private String component2SchemaXsl = "https://infra.clarin.eu/cmd/xslt/comp2schema-v2/comp2schema.xsl";//"http://www.clarin.eu/cmd/comp2schema.xsl"; 25 private String isocatRestUrl = "http://www.isocat.org/rest/";25 private String ccrRestUrl = "https://openskos.meertens.knaw.nl/ccr/api/"; 26 26 private Collection<String> adminUsers = new HashSet<String>(); 27 27 private List<String> displayNameShibbolethKeys = new ArrayList<String>(); 28 28 29 29 {//Default values 30 31 30 displayNameShibbolethKeys.add("displayName"); 31 displayNameShibbolethKeys.add("commonName"); 32 32 } 33 private Map<String, String> schemaLocations = new HashMap<String, String>();33 private final Map<String, String> schemaLocations = new HashMap<String, String>(); 34 34 35 35 {//Default values 36 37 36 schemaLocations.put(CMDComponentSpec.class.getName(), 37 "http://www.clarin.eu/cmd/ http://infra.clarin.eu/cmd/general-component-schema.xsd"); 38 38 } 39 39 private final static Configuration INSTANCE = new Configuration(); … … 43 43 44 44 public static Configuration getInstance() { 45 45 return INSTANCE; 46 46 } 47 47 48 48 public String getComponent2SchemaXsl() { 49 49 return component2SchemaXsl; 50 50 } 51 51 52 52 public List<String> getDisplayNameShibbolethKeys() { 53 53 return displayNameShibbolethKeys; 54 54 } 55 55 56 56 public String getGeneralComponentSchema() { 57 57 return generalComponentSchema; 58 58 } 59 59 60 public String get IsocatRestUrl() {61 return isocatRestUrl;60 public String getCcrRestUrl() { 61 return ccrRestUrl; 62 62 } 63 63 64 64 public String getSchemaLocation(String key) { 65 65 return schemaLocations.get(key); 66 66 } 67 67 68 68 public boolean isAdminUser(Principal principal) { 69 70 71 72 73 69 if (principal != null) { 70 return principal.getName().trim().length() > 0 // user name must be set (in case an empty entry is in admin users list) 71 && adminUsers.contains(principal.getName()); 72 } 73 return false; 74 74 } 75 75 76 76 public boolean isAdminUser(String name) { 77 78 79 80 81 77 if (name != null) { 78 return name.trim().length() > 0 // user name must be set (in case an empty entry is in admin users list) 79 && adminUsers.contains(name); 80 } 81 return false; 82 82 } 83 83 84 84 public void setAdminUsers(Collection<String> adminUsers) { 85 86 85 LOG.debug("Setting adminUsers to {}", Arrays.toString(adminUsers.toArray())); 86 this.adminUsers = adminUsers; 87 87 } 88 89 88 90 89 /** 91 90 * … … 93 92 */ 94 93 public void setAdminUsersList(String adminUsersList) { 95 96 97 98 99 94 String[] adminUsersArray = adminUsersList.trim().split("\\s+"); 95 if (LOG.isDebugEnabled()) { 96 LOG.info("Setting adminUsersList to {}", Arrays.toString(adminUsersArray)); 97 } 98 setAdminUsers(Arrays.asList(adminUsersArray)); 100 99 } 101 100 102 101 public void setComponent2SchemaXsl(String component2SchemaXsl) { 103 104 102 LOG.info("Setting component2SchemaXsl to {}", component2SchemaXsl); 103 this.component2SchemaXsl = component2SchemaXsl; 105 104 } 106 105 107 106 public void setComponentSpecSchemaLocation(String componentSpecSchemaLocation) { 108 109 107 LOG.info("Setting componentSpecSchemaLocation to {}", componentSpecSchemaLocation); 108 schemaLocations.put(CMDComponentSpec.class.getName(), componentSpecSchemaLocation); 110 109 } 111 110 112 111 public void setDisplayNameShibbolethKeys(List<String> displayNameShibbolethKeys) { 113 114 112 LOG.info("Setting displayNameShibbolethKeys to {}", displayNameShibbolethKeys); 113 this.displayNameShibbolethKeys = displayNameShibbolethKeys; 115 114 } 116 115 117 116 public void setGeneralComponentSchema(String generalComponentSchema) { 118 119 117 LOG.info("Setting generalComponentSchema to {}", generalComponentSchema); 118 this.generalComponentSchema = generalComponentSchema; 120 119 } 121 120 122 public void set IsocatRestUrl(String isocatRestUrl) {123 LOG.info("Setting isocatRestUrl to {}", isocatRestUrl);124 this.isocatRestUrl = isocatRestUrl;121 public void setCcrRestUrl(String ccrRestUrl) { 122 LOG.info("Setting ccrRestUrl to {}", ccrRestUrl); 123 this.ccrRestUrl = ccrRestUrl; 125 124 } 126 125 127 126 public String[] getAdminUsersArray() { 128 127 return adminUsers.toArray(new String[0]); 129 128 } 130 129 } -
ComponentRegistry/trunk/ComponentRegistry/src/main/java/clarin/cmdi/componentregistry/servlet/ConceptRegistryServlet.java
r5903 r5917 20 20 /** 21 21 * 22 * Servlet responsible for providing a bridge to the isocat REST interface. Can be called by the frontend to circumvent crosscripting and 23 * FLASH/Browser limitation in setting the headers of a request. 22 * Servlet responsible for providing a bridge to the CLARIN Concept Registry 23 * (CCR) REST interface. Can be called by the front end to circumvent 24 * cross-scripting and FLASH/Browser limitation in setting the headers of a 25 * request. 24 26 * 25 27 */ 26 public class IsocatServlet extends HttpServlet {28 public class ConceptRegistryServlet extends HttpServlet { 27 29 28 private final static Logger logger = LoggerFactory.getLogger( IsocatServlet.class);30 private final static Logger logger = LoggerFactory.getLogger(ConceptRegistryServlet.class); 29 31 private static final long serialVersionUID = 1L; 30 32 private transient WebResource service; 31 private final static String DCIF_XML = "application/dcif+xml";32 33 33 34 @Override 34 35 public void init(ServletConfig config) throws ServletException { 35 36 URI uri = UriBuilder.fromUri(Configuration.getInstance().getIsocatRestUrl()).build();37 38 39 logger.info("Instantiated ISOcatservlet on URI {}", uri);36 super.init(config); 37 URI uri = UriBuilder.fromUri(Configuration.getInstance().getCcrRestUrl()).build(); 38 Client client = Client.create(); 39 service = client.resource(uri); 40 logger.info("Instantiated CCR servlet on URI {}", uri); 40 41 } 41 42 42 43 @Override 43 44 protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { 44 MultivaluedMap<String, String> queryParams = new MultivaluedMapImpl(); 45 queryParams.add("dcif-mode", "list"); 46 String keywords = req.getParameter("keywords"); 47 logger.debug("ISOcat request: keywords = {}", keywords); 48 queryParams.add("keywords", keywords); 49 String type = req.getParameter("type"); //simple, complex or no type param to search in everything 50 logger.debug("ISOcat request: type = {}", type); 51 if (type != null) { 52 queryParams.add("type", type); 53 } 54 queryParams.add("profile", "Metadata"); //always search in metadata profile 55 resp.setContentType(MediaType.TEXT_XML); 45 final MultivaluedMap<String, String> queryParams = new MultivaluedMapImpl(); 56 46 57 final WebResource requestResource = service.path("/user/guest/search").queryParams(queryParams); 58 logger.info("Forwarding ISOcat request to {}", requestResource.getURI()); 59 60 final String result = requestResource.accept(DCIF_XML).get(String.class); 61 logger.debug("ISOcat result: {}", result); 62 resp.getWriter().write(result); 63 resp.flushBuffer(); 47 // Set keywords 48 String keywords = req.getParameter("keywords"); 49 logger.debug("ISOcat request: keywords = {}", keywords); 50 queryParams.add("q", keywords); 51 52 //TODO: Scope by concept scheme? 53 //TODO: Set fields to be returned (fl=...) 54 final WebResource requestResource = service.path("find-concepts").queryParams(queryParams); 55 logger.info("Forwarding CCR request to {}", requestResource.getURI()); 56 57 // Send request to CCR 58 final String result = requestResource.accept(MediaType.APPLICATION_XML).get(String.class); 59 logger.debug("CCR result: {}", result); 60 61 final String acceptHeader = req.getHeader("Accept"); 62 if (acceptHeader.contains(MediaType.APPLICATION_JSON)) { 63 serveJSON(resp, result); 64 } else { 65 serveDCIF(resp, result); 66 } 67 } 68 69 private void serveDCIF(HttpServletResponse resp, final String ccrResult) throws IOException { 70 // Prepare response 71 // TODO: transform to DCIF 72 resp.setContentType(MediaType.APPLICATION_XML); 73 resp.setCharacterEncoding("UTF-8"); 74 75 resp.getWriter().write(ccrResult); 76 resp.flushBuffer(); 77 } 78 79 private void serveJSON(HttpServletResponse resp, String result) throws IOException { 80 //TODO: Implement JSON response 81 resp.sendError(HttpServletResponse.SC_NOT_ACCEPTABLE, "JSON not supported yet - to be implemented in backend"); 64 82 } 65 83 } -
ComponentRegistry/trunk/ComponentRegistry/src/main/resources/spring-config/applicationContext.xml
r5549 r5917 51 51 <property name="componentSpecSchemaLocation" 52 52 value="${eu.clarin.cmdi.componentregistry.componentSpecSchemaLocation}" /> 53 <property name=" isocatRestUrl"54 value="${eu.clarin.cmdi.componentregistry. isocatRestUrl}" />53 <property name="ccrRestUrl" 54 value="${eu.clarin.cmdi.componentregistry.ccrRestUrl}" /> 55 55 <!-- Extra attribute keys that are passed in a shibboleth authenticated 56 56 request principal. You need to configure the shhaa.xml file to enable the -
ComponentRegistry/trunk/ComponentRegistry/src/main/webapp/META-INF/context.xml
r5879 r5917 67 67 Base location of the ISOcat service 68 68 --> 69 <Parameter name="eu.clarin.cmdi.componentregistry. isocatRestUrl" value="https://catalog.clarin.eu/isocat/rest/"/>69 <Parameter name="eu.clarin.cmdi.componentregistry.ccrRestUrl" value="https://openskos.meertens.knaw.nl/ccr/api/"/> 70 70 </Context> -
ComponentRegistry/trunk/ComponentRegistry/src/main/webapp/WEB-INF/web-shib.xml
r5827 r5917 102 102 103 103 <servlet> 104 <servlet-name> IsocatServlet</servlet-name>105 <servlet-class>clarin.cmdi.componentregistry.servlet. IsocatServlet</servlet-class>104 <servlet-name>Concept Registry Servlet</servlet-name> 105 <servlet-class>clarin.cmdi.componentregistry.servlet.ConceptRegistryServlet</servlet-class> 106 106 <load-on-startup>1</load-on-startup> 107 107 </servlet> 108 108 <servlet-mapping> 109 <servlet-name> IsocatServlet</servlet-name>110 <url-pattern>/ isocat/*</url-pattern>109 <servlet-name>Concept Registry Servlet</servlet-name> 110 <url-pattern>/ccr/*</url-pattern> 111 111 </servlet-mapping> 112 112 <servlet> -
ComponentRegistry/trunk/ComponentRegistry/src/main/webapp/WEB-INF/web-test.xml
r5826 r5917 76 76 <servlet-name>ComponentRegistry Web Application</servlet-name> 77 77 <url-pattern>/rest/*</url-pattern> 78 </servlet-mapping> 78 </servlet-mapping> 79 79 80 <servlet> 80 <servlet-name>Isocat Servlet</servlet-name> 81 <servlet-class>clarin.cmdi.componentregistry.servlet.IsocatServlet 82 </servlet-class> 81 <servlet-name>Concept Registry Servlet</servlet-name> 82 <servlet-class>clarin.cmdi.componentregistry.servlet.ConceptRegistryServlet</servlet-class> 83 83 <load-on-startup>1</load-on-startup> 84 84 </servlet> 85 85 <servlet-mapping> 86 <servlet-name> IsocatServlet</servlet-name>87 <url-pattern>/ isocat/*</url-pattern>86 <servlet-name>Concept Registry Servlet</servlet-name> 87 <url-pattern>/ccr/*</url-pattern> 88 88 </servlet-mapping> 89 89 90 <servlet> 90 91 <servlet-name>JerseyJaxrsConfig</servlet-name> -
ComponentRegistry/trunk/ComponentRegistry/src/main/webapp/WEB-INF/web.xml
r5879 r5917 82 82 <url-pattern>/rest/*</url-pattern> 83 83 </servlet-mapping> 84 84 85 <servlet> 85 <servlet-name>Isocat Servlet</servlet-name> 86 <servlet-class>clarin.cmdi.componentregistry.servlet.IsocatServlet 87 </servlet-class> 86 <servlet-name>Concept Registry Servlet</servlet-name> 87 <servlet-class>clarin.cmdi.componentregistry.servlet.ConceptRegistryServlet</servlet-class> 88 88 <load-on-startup>1</load-on-startup> 89 89 </servlet> 90 90 <servlet-mapping> 91 <servlet-name> IsocatServlet</servlet-name>92 <url-pattern>/ isocat/*</url-pattern>91 <servlet-name>Concept Registry Servlet</servlet-name> 92 <url-pattern>/ccr/*</url-pattern> 93 93 </servlet-mapping> 94 94 95 <servlet> 95 96 <servlet-name>JerseyJaxrsConfig</servlet-name> -
ComponentRegistry/trunk/ComponentRegistry/src/test/resources/spring-config/component-registry.properties
r4680 r5917 3 3 eu.clarin.cmdi.componentregistry.component2SchemaXslUrl=https://infra.clarin.eu/cmd/xslt/comp2schema-v2/comp2schema.xsl 4 4 eu.clarin.cmdi.componentregistry.componentSpecSchemaLocation=http://www.clarin.eu/cmd http://lux16.mpi.nl/general-component-schema.xsd 5 eu.clarin.cmdi.componentregistry. isocatRestUrl=https://catalog.clarin.eu/isocat/rest/5 eu.clarin.cmdi.componentregistry.ccrRestUrl=https://openskos.meertens.knaw.nl/ccr/api/ 6 6 eu.clarin.cmdi.componentregistry.jpaDialect=org.hibernate.dialect.HSQLDialect
Note: See TracChangeset
for help on using the changeset viewer.