diff --git a/Conceptpower+Spring/.settings/org.eclipse.jdt.core.prefs b/Conceptpower+Spring/.settings/org.eclipse.jdt.core.prefs index 25a1a8591..7628b437e 100644 --- a/Conceptpower+Spring/.settings/org.eclipse.jdt.core.prefs +++ b/Conceptpower+Spring/.settings/org.eclipse.jdt.core.prefs @@ -1,11 +1,11 @@ eclipse.preferences.version=1 org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled -org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7 -org.eclipse.jdt.core.compiler.compliance=1.7 +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 +org.eclipse.jdt.core.compiler.compliance=1.8 org.eclipse.jdt.core.compiler.problem.assertIdentifier=error org.eclipse.jdt.core.compiler.problem.enumIdentifier=error org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning -org.eclipse.jdt.core.compiler.source=1.7 +org.eclipse.jdt.core.compiler.source=1.8 org.eclipse.jdt.core.formatter.align_type_members_on_columns=false org.eclipse.jdt.core.formatter.alignment_for_arguments_in_allocation_expression=16 org.eclipse.jdt.core.formatter.alignment_for_arguments_in_annotation=0 diff --git a/Conceptpower+Spring/.settings/org.eclipse.m2e.core.prefs b/Conceptpower+Spring/.settings/org.eclipse.m2e.core.prefs index 41c8a3c6c..1742ee4cf 100644 --- a/Conceptpower+Spring/.settings/org.eclipse.m2e.core.prefs +++ b/Conceptpower+Spring/.settings/org.eclipse.m2e.core.prefs @@ -1,4 +1,4 @@ -activeProfiles=dev, dev +activeProfiles=dev, integration-test, dev, integration-test eclipse.preferences.version=1 resolveWorkspaceProjects=true version=1 diff --git a/Conceptpower+Spring/.settings/org.eclipse.wst.common.component b/Conceptpower+Spring/.settings/org.eclipse.wst.common.component index 90bf816d5..300a959b8 100644 --- a/Conceptpower+Spring/.settings/org.eclipse.wst.common.component +++ b/Conceptpower+Spring/.settings/org.eclipse.wst.common.component @@ -1,5 +1,5 @@ - + diff --git a/Conceptpower+Spring/.settings/org.eclipse.wst.common.project.facet.core.xml b/Conceptpower+Spring/.settings/org.eclipse.wst.common.project.facet.core.xml index 55073babf..baa5450a3 100644 --- a/Conceptpower+Spring/.settings/org.eclipse.wst.common.project.facet.core.xml +++ b/Conceptpower+Spring/.settings/org.eclipse.wst.common.project.facet.core.xml @@ -4,5 +4,5 @@ - + diff --git a/Conceptpower+Spring/pom.xml b/Conceptpower+Spring/pom.xml index 4d3a29f6e..a9a038fd9 100644 --- a/Conceptpower+Spring/pom.xml +++ b/Conceptpower+Spring/pom.xml @@ -29,11 +29,11 @@ /Users/karthikeyanmohan/Software/Conceptpower/indexFiles debug - false - false - https://www.dropbox.com/s/48gftjus29qyp2q/conceptLists.db?raw=1 - https://www.dropbox.com/s/mla61f63fgfil3y/conceptTypes.db?raw=1 - https://www.dropbox.com/s/n0vgpc5ow1xko4v/users.db?raw=1 + false + false + https://www.dropbox.com/s/48gftjus29qyp2q/conceptLists.db?raw=1 + https://www.dropbox.com/s/mla61f63fgfil3y/conceptTypes.db?raw=1 + https://www.dropbox.com/s/n0vgpc5ow1xko4v/users.db?raw=1 @@ -96,27 +96,27 @@ ${lucene.index} - - integration-test - - - ${db.files.path} - ${deploy.path.test} - ${tomcat.deploy.path} - ${email.username} - ${email.password} - ${email.server.port} - ${email.server.host} - ${admin.username} - ${admin.password} - ${wordnet.path} - ${lucene.index} - ${concept.list.url} - ${concept.types.url} - ${users.url} - debug - - + + integration-test + + + ${db.files.path} + ${deploy.path.test} + ${tomcat.deploy.path} + ${email.username} + ${email.password} + ${email.server.port} + ${email.server.host} + ${admin.username} + ${admin.password} + ${wordnet.path} + ${lucene.index} + ${concept.list.url} + ${concept.types.url} + ${users.url} + debug + + @@ -230,11 +230,11 @@ - - javax.servlet - javax.servlet-api - 3.0.1 - + + javax.servlet + javax.servlet-api + 3.0.1 + javax.servlet.jsp @@ -491,12 +491,12 @@ spring-security-web ${spring-security-version} - - - com.jayway.jsonpath - json-path - 2.1.0 - + + + com.jayway.jsonpath + json-path + 2.1.0 + @@ -526,18 +526,25 @@ 3.0.3 - - - com.fasterxml.jackson.core - jackson-databind - 2.1.0 - - - com.fasterxml.jackson.core - jackson-core - 2.1.0 - + + + com.fasterxml.jackson.core + jackson-databind + 2.1.0 + + + com.fasterxml.jackson.core + jackson-core + 2.1.0 + + + + org.apache.jena + apache-jena-libs + pom + 3.0.1 + @@ -641,86 +648,82 @@ #{0} ({1,date,yyyy-MM-dd HH:mm:ss}) - - - org.codehaus.mojo - build-helper-maven-plugin - 3.0.0 - - - - add-integration-test-sources - generate-test-sources - - add-test-source - - - - - src/integration-test/java - - - - - - add-integration-test-resources - generate-test-resources - - add-test-resource - - - - - - true - src/integration-test/resources - - - - - - - - - - org.apache.maven.plugins - maven-surefire-plugin - 2.18 - - - ${skip.unit.tests} - - - **/*IT.java - - - - - - org.apache.maven.plugins - maven-failsafe-plugin - 2.18 - - - - integration-tests - - integration-test - verify - - - - ${skip.integration.tests} - - - - + + + org.codehaus.mojo + build-helper-maven-plugin + 3.0.0 + + + + add-integration-test-sources + generate-test-sources + + add-test-source + + + + + src/integration-test/java + + + + + + add-integration-test-resources + generate-test-resources + + add-test-resource + + + + + + true + src/integration-test/resources + + + + + + + + + + org.apache.maven.plugins + maven-surefire-plugin + 2.18 + + + ${skip.unit.tests} + + + **/*IT.java + + + + + + org.apache.maven.plugins + maven-failsafe-plugin + 2.18 + + + + integration-tests + + integration-test + verify + + + + ${skip.integration.tests} + + + + @@ -730,20 +733,20 @@ **/* - - true - src/test/resources - - **/* - - - - true - src/integration-test/resources - - **/* - - + + true + src/test/resources + + **/* + + + + true + src/integration-test/resources + + **/* + + @@ -762,4 +765,4 @@ - \ No newline at end of file + diff --git a/Conceptpower+Spring/src/integration-test/java/edu/asu/conceptpower/IntegrationTest.java b/Conceptpower+Spring/src/integration-test/java/edu/asu/conceptpower/IntegrationTest.java index db6e00f19..32ddd3fc8 100644 --- a/Conceptpower+Spring/src/integration-test/java/edu/asu/conceptpower/IntegrationTest.java +++ b/Conceptpower+Spring/src/integration-test/java/edu/asu/conceptpower/IntegrationTest.java @@ -1,31 +1,21 @@ package edu.asu.conceptpower; import java.security.Principal; -import java.util.ArrayList; -import java.util.Collection; - import org.junit.Before; import org.junit.runner.RunWith; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.security.authentication.AbstractAuthenticationToken; -import org.springframework.security.authentication.AnonymousAuthenticationToken; -import org.springframework.security.core.context.SecurityContext; -import org.springframework.security.core.context.SecurityContextHolder; -import org.springframework.security.core.context.SecurityContextImpl; +import org.springframework.http.HttpStatus; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.ContextHierarchy; import org.springframework.test.context.TestPropertySource; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import org.springframework.test.context.web.WebAppConfiguration; import org.springframework.test.web.servlet.MockMvc; +import org.springframework.test.web.servlet.MvcResult; import org.springframework.test.web.servlet.request.MockMvcRequestBuilders; import org.springframework.test.web.servlet.setup.MockMvcBuilders; import org.springframework.web.context.WebApplicationContext; -import edu.asu.conceptpower.servlet.users.ConceptpowerGrantedAuthority; - @RunWith(SpringJUnit4ClassRunner.class) @TestPropertySource(locations = "classpath:/test.properties") @ContextHierarchy({ @ContextConfiguration(locations = { "classpath:/root-context-test.xml" }), @@ -34,8 +24,6 @@ @WebAppConfiguration public abstract class IntegrationTest { - private static final Logger logger = LoggerFactory.getLogger(IntegrationTest.class); - private static boolean isSetupDone = false; @Autowired @@ -51,29 +39,14 @@ public String getName() { @Before public void setup() throws Exception { - this.mockMvc = MockMvcBuilders.webAppContextSetup(this.wac).build(); if (!isSetupDone) { - setSecurityContext(); - logger.debug("Started with lucene indexing for integration tests."); this.mockMvc.perform(MockMvcRequestBuilders.post("/auth/indexConcepts").principal(principal)); + MvcResult mr = null; + do { + mr = this.mockMvc.perform(MockMvcRequestBuilders.post("/auth/getIndexerStatus")).andReturn(); + } while (mr.getResponse().getStatus() != HttpStatus.OK.value()); isSetupDone = true; - logger.debug("Completed with lucene indexing for integration tests."); } } - - private void setSecurityContext() { - logger.debug("Setting up security context"); - Collection authorities = new ArrayList<>(); - ConceptpowerGrantedAuthority grantedAuthority = new ConceptpowerGrantedAuthority("admin"); - grantedAuthority.setAuthority(ConceptpowerGrantedAuthority.ROLE_ADMIN); - authorities.add(grantedAuthority); - - AbstractAuthenticationToken auth = new AnonymousAuthenticationToken("admin", principal, authorities); - SecurityContext context = new SecurityContextImpl(); - context.setAuthentication(auth); - SecurityContextHolder.setContext(context); - logger.debug("Completed setting up security context"); - } - } diff --git a/Conceptpower+Spring/src/integration-test/java/edu/asu/conceptpower/rest/ConceptIDLookupIT.java b/Conceptpower+Spring/src/integration-test/java/edu/asu/conceptpower/rest/ConceptIDLookupIT.java index f086b175c..916ec9a56 100644 --- a/Conceptpower+Spring/src/integration-test/java/edu/asu/conceptpower/rest/ConceptIDLookupIT.java +++ b/Conceptpower+Spring/src/integration-test/java/edu/asu/conceptpower/rest/ConceptIDLookupIT.java @@ -13,11 +13,60 @@ public class ConceptIDLookupIT extends IntegrationTest { @Test + public void test_getConceptById_successForWordNetIdInJson() throws Exception { + final String output = IOUtil + .toString(this.getClass().getClassLoader().getResourceAsStream("output/wordNetConcept.json")); + this.mockMvc + .perform(MockMvcRequestBuilders.get("/Concept").param("id", "WID-02380464-N-01-polo_pony") + .accept(MediaType.APPLICATION_JSON_VALUE)) + .andExpect(content().string(output)).andExpect(status().isOk()); + + } + + @Test + public void test_getConceptById_successForGenericWordNetIdInJson() throws Exception { + final String output = IOUtil + .toString(this.getClass().getClassLoader().getResourceAsStream("output/conceptForGenericWordnet.json")); + this.mockMvc + .perform(MockMvcRequestBuilders.get("/Concept").param("id", "WID-02380464-N-??-polo_pony") + .accept(MediaType.APPLICATION_JSON_VALUE)) + .andExpect(content().string(output)).andExpect(status().isOk()); + + } + + @Test(expected = IllegalArgumentException.class) + public void test_getConceptById_invalidWordNetIdInJson() throws Exception { + this.mockMvc.perform( + MockMvcRequestBuilders.get("/Concept").param("id", null).accept(MediaType.APPLICATION_JSON_VALUE)) + .andExpect(status().isBadRequest()); + + } + + @Test + public void test_getConceptById_successForLocalConceptIdInJson() throws Exception { + final String output = IOUtil + .toString(this.getClass().getClassLoader().getResourceAsStream("output/conceptForLocalId.json")); + this.mockMvc + .perform(MockMvcRequestBuilders.get("/Concept").param("id", "CONdf62c00c-f4a9-4564-9dd6-c9b955650f3a") + .accept(MediaType.APPLICATION_JSON_VALUE)) + .andExpect(content().string(output)).andExpect(status().isOk()); + } + + @Test + public void test_getConceptById_successForConceptWrapperInJson() throws Exception { + final String output = IOUtil + .toString(this.getClass().getClassLoader().getResourceAsStream("output/conceptWrapper.json")); + this.mockMvc + .perform(MockMvcRequestBuilders.get("/Concept").param("id", "CONe7fbf694-5609-4691-bca8-916526c2ba6a") + .accept(MediaType.APPLICATION_JSON_VALUE)) + .andExpect(content().string(output)).andExpect(status().isOk()); + } + public void test_getConceptById_successForWordNetIdInXml() throws Exception { final String output = IOUtil .toString(this.getClass().getClassLoader().getResourceAsStream("output/wordNetConcept.xml")); this.mockMvc - .perform(MockMvcRequestBuilders.get("/rest/Concept").param("id", "WID-02380464-N-01-polo_pony") + .perform(MockMvcRequestBuilders.get("/Concept").param("id", "WID-02380464-N-01-polo_pony") .accept(MediaType.APPLICATION_XML_VALUE)) .andExpect(content().string(output)).andExpect(status().isOk()); @@ -36,8 +85,7 @@ public void test_getConceptById_successForLocalConceptIdInXml() throws Exception final String output = IOUtil .toString(this.getClass().getClassLoader().getResourceAsStream("output/conceptForLocalId.xml")); this.mockMvc - .perform(MockMvcRequestBuilders.get("/rest/Concept") - .param("id", "CONdf62c00c-f4a9-4564-9dd6-c9b955650f3a") + .perform(MockMvcRequestBuilders.get("/Concept").param("id", "CONdf62c00c-f4a9-4564-9dd6-c9b955650f3a") .accept(MediaType.APPLICATION_XML_VALUE)) .andExpect(content().string(output)).andExpect(status().isOk()); } @@ -47,8 +95,7 @@ public void test_getConceptById_successForConceptWrapperInXml() throws Exception final String output = IOUtil .toString(this.getClass().getClassLoader().getResourceAsStream("output/conceptWrapper.xml")); this.mockMvc - .perform(MockMvcRequestBuilders.get("/rest/Concept") - .param("id", "CONe7fbf694-5609-4691-bca8-916526c2ba6a") + .perform(MockMvcRequestBuilders.get("/Concept").param("id", "CONe7fbf694-5609-4691-bca8-916526c2ba6a") .accept(MediaType.APPLICATION_XML_VALUE)) .andExpect(content().string(output)).andExpect(status().isOk()); } diff --git a/Conceptpower+Spring/src/integration-test/java/edu/asu/conceptpower/rest/ConceptLookupIT.java b/Conceptpower+Spring/src/integration-test/java/edu/asu/conceptpower/rest/ConceptLookupIT.java index 0922f2e23..741fb3ac0 100644 --- a/Conceptpower+Spring/src/integration-test/java/edu/asu/conceptpower/rest/ConceptLookupIT.java +++ b/Conceptpower+Spring/src/integration-test/java/edu/asu/conceptpower/rest/ConceptLookupIT.java @@ -1,6 +1,8 @@ package edu.asu.conceptpower.rest; +import static org.hamcrest.core.Is.is; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; import org.apache.commons.io.IOUtil; @@ -12,12 +14,41 @@ public class ConceptLookupIT extends IntegrationTest { + @Test + public void test_getWordNetEntry_successForSingleEntryInJson() throws Exception { + final String output = IOUtil.toString( + this.getClass().getClassLoader().getResourceAsStream("output/conceptLookUpWordNetEntry.json")); + this.mockMvc + .perform(MockMvcRequestBuilders.get("/ConceptLookup/Douglas Weiner/noun") + .accept(MediaType.APPLICATION_JSON_VALUE)) + .andExpect(content().string(output)).andExpect(status().isOk()); + } + + @Test + public void test_getWordNetEntry_noResultsInJson() throws Exception { + + this.mockMvc + .perform(MockMvcRequestBuilders.get("/ConceptLookup/Gustav Robert Kirchhoff/verb") + .accept(MediaType.APPLICATION_JSON_VALUE)) + .andExpect(jsonPath("$.message", is("No concept entry found."))).andExpect(status().isOk()); + } + + @Test + public void test_getWordNetEntry_successForMultipleEntryInJson() throws Exception { + final String output = IOUtil.toString( + this.getClass().getClassLoader().getResourceAsStream("output/conceptLookUpForMultipletEntry.json")); + this.mockMvc + .perform(MockMvcRequestBuilders.get("/ConceptLookup/Douglas/noun") + .accept(MediaType.APPLICATION_JSON_VALUE)) + .andExpect(content().string(output)).andExpect(status().isOk()); + } + @Test public void test_getWordNetEntry_successForSingleEntryInXml() throws Exception { final String output = IOUtil .toString(this.getClass().getClassLoader().getResourceAsStream("output/conceptLookUpWordNetEntry.xml")); this.mockMvc - .perform(MockMvcRequestBuilders.get("/rest/ConceptLookup/Douglas Weiner/noun") + .perform(MockMvcRequestBuilders.get("/ConceptLookup/Douglas Weiner/noun") .accept(MediaType.APPLICATION_XML_VALUE)) .andExpect(content().string(output)).andExpect(status().isOk()); } @@ -27,7 +58,7 @@ public void test_getWordNetEntry_noResultsInXml() throws Exception { final String output = IOUtil .toString(this.getClass().getClassLoader().getResourceAsStream("output/conceptEntryNotFound.xml")); this.mockMvc - .perform(MockMvcRequestBuilders.get("/rest/ConceptLookup/Gustav Robert Kirchhoff/verb") + .perform(MockMvcRequestBuilders.get("/ConceptLookup/Gustav Robert Kirchhoff/verb") .accept(MediaType.APPLICATION_XML_VALUE)) .andExpect(content().string(output)).andExpect(status().isOk()); } @@ -37,7 +68,7 @@ public void test_getWordNetEntry_successForMultipleEntryInXml() throws Exception final String output = IOUtil.toString( this.getClass().getClassLoader().getResourceAsStream("output/conceptLookUpForMultipletEntry.xml")); this.mockMvc - .perform(MockMvcRequestBuilders.get("/rest/ConceptLookup/Douglas/noun") + .perform(MockMvcRequestBuilders.get("/ConceptLookup/Douglas/noun") .accept(MediaType.APPLICATION_XML_VALUE)) .andExpect(content().string(output)).andExpect(status().isOk()); } diff --git a/Conceptpower+Spring/src/integration-test/java/edu/asu/conceptpower/rest/ConceptSearchIT.java b/Conceptpower+Spring/src/integration-test/java/edu/asu/conceptpower/rest/ConceptSearchIT.java index 3ddaf5421..a07ead39f 100644 --- a/Conceptpower+Spring/src/integration-test/java/edu/asu/conceptpower/rest/ConceptSearchIT.java +++ b/Conceptpower+Spring/src/integration-test/java/edu/asu/conceptpower/rest/ConceptSearchIT.java @@ -1,6 +1,8 @@ package edu.asu.conceptpower.rest; +import static org.hamcrest.core.Is.is; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; import org.apache.commons.io.IOUtil; @@ -9,32 +11,146 @@ import org.springframework.test.web.servlet.request.MockMvcRequestBuilders; import edu.asu.conceptpower.IntegrationTest; -import edu.asu.conceptpower.servlet.rest.SearchParamters; public class ConceptSearchIT extends IntegrationTest { + @Test + public void test_searchConcept_searchWithWordAndPosInJson() throws Exception { + + final String output = IOUtil + .toString(this.getClass().getClassLoader().getResourceAsStream("output/conceptWithWordAndPos.json")); + + this.mockMvc + .perform(MockMvcRequestBuilders.get("/ConceptSearch").param("word", "einstein").param("pos", "noun") + .param("operator", SearchParamters.OP_AND).accept(MediaType.APPLICATION_JSON_VALUE)) + .andExpect(content().string(output)).andExpect(status().isOk()); + + } @Test - public void test_searchConcept_searchWithWordAndPosInXml() throws Exception { + public void test_searchConcept_successWithDefaultOperator() throws Exception { final String output = IOUtil - .toString(this.getClass().getClassLoader().getResourceAsStream("output/conceptWithWordAndPos.xml")); + .toString(this.getClass().getClassLoader().getResourceAsStream("output/conceptWithWordAndPos.json")); this.mockMvc - .perform( - MockMvcRequestBuilders.get("/rest/ConceptSearch").param("word", "einstein").param("pos", "noun") - .param("operator", SearchParamters.OP_AND).accept(MediaType.APPLICATION_XML_VALUE)) + .perform(MockMvcRequestBuilders.get("/ConceptSearch").param("word", "einstein").param("pos", "noun") + .accept(MediaType.APPLICATION_JSON_VALUE)) .andExpect(content().string(output)).andExpect(status().isOk()); + + } + + @Test + public void test_searchConcept_noResultsInJson() throws Exception { + + this.mockMvc + .perform(MockMvcRequestBuilders.get("/ConceptSearch").param("word", "Gustav Robert Kirchhoff") + .param("pos", "verb").param("concept_list", "VogonWeb Concepts") + .param("operator", SearchParamters.OP_AND).accept(MediaType.APPLICATION_JSON_VALUE)) + .andExpect(jsonPath("$.message", is("No records found for the search condition."))) + .andExpect(status().isOk()); + } @Test - public void test_searchConcept_searchWithWordAndPosAndConceptListInXml() throws Exception { + public void test_searchConcept_searchWithWordAndPosAndEqualToInJson() throws Exception { + final String output = IOUtil.toString( + this.getClass().getClassLoader().getResourceAsStream("output/conceptWithWordPosAndEqualTo.json")); + + this.mockMvc + .perform(MockMvcRequestBuilders.get("/ConceptSearch").param("word", "Abbott Henderson Thayer") + .param("pos", "noun").param("equal_to", "http://viaf.org/viaf/55043769") + .param("operator", SearchParamters.OP_AND).accept(MediaType.APPLICATION_JSON_VALUE)) + .andExpect(content().string(output)).andExpect(status().isOk()); + + } + + @Test + public void test_searchConcept_searchWithWordAndPosAndSimilarToInJson() throws Exception { + + final String output = IOUtil.toString( + this.getClass().getClassLoader().getResourceAsStream("output/conceptWithWordPosAndSimilarTo.json")); + + this.mockMvc + .perform(MockMvcRequestBuilders.get("/ConceptSearch").param("word", "Douglas Weiner") + .param("pos", "noun").param("similar_to", "http://viaf.org/viaf/248802520") + .param("operator", SearchParamters.OP_AND).accept(MediaType.APPLICATION_JSON_VALUE)) + .andExpect(content().string(output)).andExpect(status().isOk()); + } + + @Test + public void test_searchConcept_searchWithWordPosAndPaginationInJson() throws Exception { + final String output = IOUtil.toString( + this.getClass().getClassLoader().getResourceAsStream("output/conceptWithWordPosAndPagination1.json")); + + this.mockMvc + .perform(MockMvcRequestBuilders.get("/ConceptSearch").param("word", "einstein").param("pos", "noun") + .param("number_of_records_per_page", "2").param("page", "1") + .param("operator", SearchParamters.OP_AND).accept(MediaType.APPLICATION_JSON_VALUE)) + .andExpect(content().string(output)).andExpect(status().isOk()); + + final String output2 = IOUtil.toString( + this.getClass().getClassLoader().getResourceAsStream("output/conceptWithWordPosAndPagination2.json")); + + this.mockMvc + .perform(MockMvcRequestBuilders.get("/ConceptSearch").param("word", "einstein").param("pos", "noun") + .param("number_of_records_per_page", "2").param("page", "2") + .param("operator", SearchParamters.OP_AND).accept(MediaType.APPLICATION_JSON_VALUE)) + .andExpect(content().string(output2)).andExpect(status().isOk()); + + } + + @Test + public void test_searchConcept_searchWithWordPosAndTypeIdInJson() throws Exception { + final String output = IOUtil.toString( - this.getClass().getClassLoader().getResourceAsStream("output/conceptWithWordPosAndConceptList.xml")); + this.getClass().getClassLoader().getResourceAsStream("output/conceptWithWordPosAndTypeId.json")); this.mockMvc - .perform(MockMvcRequestBuilders.get("/rest/ConceptSearch").param("word", "Douglas Weiner") - .param("pos", "noun").param("concept_list", "VogonWeb Concepts") + .perform(MockMvcRequestBuilders.get("/ConceptSearch").param("word", "Almira Hart Lincoln Phelps") + .param("pos", "noun").param("type_id", "986a7cc9-c0c1-4720-b344-853f08c136ab") + .param("operator", SearchParamters.OP_AND).accept(MediaType.APPLICATION_JSON_VALUE)) + .andExpect(content().string(output)).andExpect(status().isOk()); + + } + + @Test + public void test_searchConcept_searchWithWordPosAndTypeUriInJson() throws Exception { + + final String output = IOUtil.toString( + this.getClass().getClassLoader().getResourceAsStream("output/conceptWithWordPosAndTypeUri.json")); + + this.mockMvc + .perform(MockMvcRequestBuilders.get("/ConceptSearch").param("word", "Almira Hart Lincoln Phelps") + .param("pos", "noun") + .param("type_uri", "http://www.digitalhps.org/types/TYPE_986a7cc9-c0c1-4720-b344-853f08c136ab") + .param("operator", SearchParamters.OP_AND).accept(MediaType.APPLICATION_JSON_VALUE)) + .andExpect(content().string(output)).andExpect(status().isOk()); + + } + + @Test + public void test_searchConcept_searchWithWordPosAndDescriptionInJson() throws Exception { + + final String output = IOUtil.toString( + this.getClass().getClassLoader().getResourceAsStream("output/conceptWithWordPosAndDescription.json")); + + this.mockMvc + .perform(MockMvcRequestBuilders.get("/ConceptSearch").param("word", "Douglas Weiner") + .param("pos", "noun").param("description", "American 20th century environmentalist") + .param("operator", SearchParamters.OP_AND).accept(MediaType.APPLICATION_JSON_VALUE)) + .andExpect(content().string(output)).andExpect(status().isOk()); + + } + + @Test + public void test_searchConcept_searchWithWordAndPosInXml() throws Exception { + + final String output = IOUtil + .toString(this.getClass().getClassLoader().getResourceAsStream("output/conceptWithWordAndPos.xml")); + + this.mockMvc + .perform(MockMvcRequestBuilders.get("/ConceptSearch").param("word", "einstein").param("pos", "noun") .param("operator", SearchParamters.OP_AND).accept(MediaType.APPLICATION_XML_VALUE)) .andExpect(content().string(output)).andExpect(status().isOk()); } @@ -46,7 +162,7 @@ public void test_searchConcept_noResultsInXml() throws Exception { .toString(this.getClass().getClassLoader().getResourceAsStream("output/noResults.xml")); this.mockMvc - .perform(MockMvcRequestBuilders.get("/rest/ConceptSearch").param("word", "Gustav Robert Kirchhoff") + .perform(MockMvcRequestBuilders.get("/ConceptSearch").param("word", "Gustav Robert Kirchhoff") .param("pos", "verb").param("concept_list", "VogonWeb Concepts") .param("operator", SearchParamters.OP_AND).accept(MediaType.APPLICATION_XML_VALUE)) .andExpect(content().string(output)).andExpect(status().isOk()); @@ -59,7 +175,7 @@ public void test_searchConcept_searchWithWordAndPosAndEqualToInXml() throws Exce this.getClass().getClassLoader().getResourceAsStream("output/conceptWithWordPosAndEqualTo.xml")); this.mockMvc - .perform(MockMvcRequestBuilders.get("/rest/ConceptSearch").param("word", "Abbott Henderson Thayer") + .perform(MockMvcRequestBuilders.get("/ConceptSearch").param("word", "Abbott Henderson Thayer") .param("pos", "noun").param("equal_to", "http://viaf.org/viaf/55043769") .param("operator", SearchParamters.OP_AND).accept(MediaType.APPLICATION_XML_VALUE)) .andExpect(content().string(output)).andExpect(status().isOk()); @@ -73,12 +189,34 @@ public void test_searchConcept_searchWithWordAndPosAndSimilarToInXml() throws Ex this.getClass().getClassLoader().getResourceAsStream("output/conceptWithWordPosAndSimilarTo.xml")); this.mockMvc - .perform(MockMvcRequestBuilders.get("/rest/ConceptSearch").param("word", "Douglas").param("pos", "NOUN") - .param("similar_to", "http://viaf.org/viaf/248802520") + .perform(MockMvcRequestBuilders.get("/ConceptSearch").param("word", "Douglas Weiner") + .param("pos", "noun").param("similar_to", "http://viaf.org/viaf/248802520") .param("operator", SearchParamters.OP_AND).accept(MediaType.APPLICATION_XML_VALUE)) .andExpect(content().string(output)).andExpect(status().isOk()); } + @Test + public void test_searchConcept_searchWithWordPosAndPaginationInXml() throws Exception { + final String output = IOUtil.toString( + this.getClass().getClassLoader().getResourceAsStream("output/conceptWithWordPosAndPagination1.xml")); + + this.mockMvc + .perform(MockMvcRequestBuilders.get("/ConceptSearch").param("word", "einstein").param("pos", "noun") + .param("number_of_records_per_page", "2").param("page", "1") + .param("operator", SearchParamters.OP_AND).accept(MediaType.APPLICATION_XML_VALUE)) + .andExpect(content().string(output)).andExpect(status().isOk()); + + final String output2 = IOUtil.toString( + this.getClass().getClassLoader().getResourceAsStream("output/conceptWithWordPosAndPagination2.xml")); + + this.mockMvc + .perform(MockMvcRequestBuilders.get("/ConceptSearch").param("word", "einstein").param("pos", "noun") + .param("number_of_records_per_page", "2").param("page", "2") + .param("operator", SearchParamters.OP_AND).accept(MediaType.APPLICATION_XML_VALUE)) + .andExpect(content().string(output2)).andExpect(status().isOk()); + + } + @Test public void test_searchConcept_searchWithWordPosAndTypeIdInXml() throws Exception { @@ -86,7 +224,7 @@ public void test_searchConcept_searchWithWordPosAndTypeIdInXml() throws Exceptio this.getClass().getClassLoader().getResourceAsStream("output/conceptWithWordPosAndTypeId.xml")); this.mockMvc - .perform(MockMvcRequestBuilders.get("/rest/ConceptSearch").param("word", "Almira Hart Lincoln Phelps") + .perform(MockMvcRequestBuilders.get("/ConceptSearch").param("word", "Almira Hart Lincoln Phelps") .param("pos", "noun").param("type_id", "986a7cc9-c0c1-4720-b344-853f08c136ab") .param("operator", SearchParamters.OP_AND).accept(MediaType.APPLICATION_XML_VALUE)) .andExpect(content().string(output)).andExpect(status().isOk()); @@ -100,7 +238,7 @@ public void test_searchConcept_searchWithWordPosAndTypeUriInXml() throws Excepti this.getClass().getClassLoader().getResourceAsStream("output/conceptWithWordPosAndTypeUri.xml")); this.mockMvc - .perform(MockMvcRequestBuilders.get("/rest/ConceptSearch").param("word", "Almira Hart Lincoln Phelps") + .perform(MockMvcRequestBuilders.get("/ConceptSearch").param("word", "Almira Hart Lincoln Phelps") .param("pos", "noun") .param("type_uri", "http://www.digitalhps.org/types/TYPE_986a7cc9-c0c1-4720-b344-853f08c136ab") .param("operator", SearchParamters.OP_AND).accept(MediaType.APPLICATION_XML_VALUE)) @@ -115,7 +253,7 @@ public void test_searchConcept_searchWithWordPosAndDescriptionInXml() throws Exc this.getClass().getClassLoader().getResourceAsStream("output/conceptWithWordPosAndDescription.xml")); this.mockMvc - .perform(MockMvcRequestBuilders.get("/rest/ConceptSearch").param("word", "Douglas Weiner") + .perform(MockMvcRequestBuilders.get("/ConceptSearch").param("word", "Douglas Weiner") .param("pos", "noun").param("description", "American 20th century environmentalist") .param("operator", SearchParamters.OP_AND).accept(MediaType.APPLICATION_XML_VALUE)) .andExpect(content().string(output)).andExpect(status().isOk()); diff --git a/Conceptpower+Spring/src/integration-test/java/edu/asu/conceptpower/rest/ConceptsIT.java b/Conceptpower+Spring/src/integration-test/java/edu/asu/conceptpower/rest/ConceptsIT.java index 4caed5e7a..7615e7e37 100644 --- a/Conceptpower+Spring/src/integration-test/java/edu/asu/conceptpower/rest/ConceptsIT.java +++ b/Conceptpower+Spring/src/integration-test/java/edu/asu/conceptpower/rest/ConceptsIT.java @@ -2,6 +2,7 @@ import static org.hamcrest.CoreMatchers.instanceOf; import static org.hamcrest.core.Is.is; +import static org.hamcrest.core.Is.isA; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; @@ -20,9 +21,19 @@ public void test_addConcept_success() throws Exception { final String input = IOUtil .toString(this.getClass().getClassLoader().getResourceAsStream("input/addConcept.json")); this.mockMvc - .perform(MockMvcRequestBuilders.post("/rest/concept/add").contentType(MediaType.APPLICATION_JSON_VALUE) + .perform(MockMvcRequestBuilders.post("/concept/add").contentType(MediaType.APPLICATION_JSON_VALUE) .content(input).principal(principal)) - .andExpect(jsonPath("$.id", is(instanceOf(String.class)))).andExpect(status().isOk()); + .andExpect(jsonPath("$.id", isA(String.class))).andExpect(status().isOk()); + } + + @Test + public void test_addConcept_successForConceptWrapper() throws Exception { + final String input = IOUtil + .toString(this.getClass().getClassLoader().getResourceAsStream("input/addConceptWrapper.json")); + this.mockMvc + .perform(MockMvcRequestBuilders.post("/concept/add").contentType(MediaType.APPLICATION_JSON_VALUE) + .content(input).principal(principal)) + .andExpect(jsonPath("$.id", isA(String.class))).andExpect(status().isOk()); } @Test @@ -30,11 +41,10 @@ public void test_addConcepts_success() throws Exception { final String input = IOUtil .toString(this.getClass().getClassLoader().getResourceAsStream("input/addConcepts.json")); this.mockMvc - .perform(MockMvcRequestBuilders.post("/rest/concepts/add").contentType(MediaType.APPLICATION_JSON_VALUE) + .perform(MockMvcRequestBuilders.post("/concepts/add").contentType(MediaType.APPLICATION_JSON_VALUE) .content(input).principal(principal)) .andExpect(jsonPath("$[0].id", is(instanceOf(String.class)))) - .andExpect(jsonPath("$[1].id", is(instanceOf(String.class)))) - .andExpect(status().isOk()); + .andExpect(jsonPath("$[1].id", is(instanceOf(String.class)))).andExpect(status().isOk()); } @Test @@ -42,7 +52,7 @@ public void test_addConcepts_invalidConceptList() throws Exception { final String input = IOUtil.toString( this.getClass().getClassLoader().getResourceAsStream("input/addConceptsWithInvalidConceptList.json")); this.mockMvc - .perform(MockMvcRequestBuilders.post("/rest/concepts/add").contentType(MediaType.APPLICATION_JSON_VALUE) + .perform(MockMvcRequestBuilders.post("/concepts/add").contentType(MediaType.APPLICATION_JSON_VALUE) .content(input).principal(principal)) .andExpect(jsonPath("$.[0].error_message", is("Specified dictionary does not exist in Conceptpower."))) .andExpect(jsonPath("$.[0].success", is(false))).andExpect(jsonPath("$.[0].word", is("kitty"))) @@ -55,7 +65,7 @@ public void test_addConcept_invalidConceptList() throws Exception { final String input = IOUtil.toString( this.getClass().getClassLoader().getResourceAsStream("input/addConceptWithInvalidConceptList.json")); this.mockMvc - .perform(MockMvcRequestBuilders.post("/rest/concept/add").contentType(MediaType.APPLICATION_JSON_VALUE) + .perform(MockMvcRequestBuilders.post("/concept/add").contentType(MediaType.APPLICATION_JSON_VALUE) .content(input).principal(principal)) .andExpect(content().string("Specified concept list does not exist in Conceptpower.")) .andExpect(status().isBadRequest()); @@ -66,9 +76,10 @@ public void test_addConcept_invalidPos() throws Exception { final String input = IOUtil .toString(this.getClass().getClassLoader().getResourceAsStream("input/addConceptWithInvalidPos.json")); this.mockMvc - .perform(MockMvcRequestBuilders.post("/rest/concept/add").contentType(MediaType.APPLICATION_JSON_VALUE) + .perform(MockMvcRequestBuilders.post("/concept/add").contentType(MediaType.APPLICATION_JSON_VALUE) .content(input).principal(principal)) - .andExpect(content().string("POS 'noun2' does not exist.")).andExpect(status().isBadRequest()); + .andExpect(content().string("Error parsing request: please provide a valid POS ('pos' attribute).")) + .andExpect(status().isBadRequest()); } @@ -77,7 +88,7 @@ public void test_addConcept_nullWord() throws Exception { final String input = IOUtil .toString(this.getClass().getClassLoader().getResourceAsStream("input/addConceptWithNullWord.json")); this.mockMvc - .perform(MockMvcRequestBuilders.post("/rest/concept/add").contentType(MediaType.APPLICATION_JSON_VALUE) + .perform(MockMvcRequestBuilders.post("/concept/add").contentType(MediaType.APPLICATION_JSON_VALUE) .content(input).principal(principal)) .andExpect(content() .string("Error parsing request: please provide a word for the concept ('word' attribute).")) @@ -90,10 +101,10 @@ public void test_addConcept_emptyConceptList() throws Exception { final String input = IOUtil .toString(this.getClass().getClassLoader().getResourceAsStream("input/addConceptWithEmptyList.json")); this.mockMvc - .perform(MockMvcRequestBuilders.post("/rest/concept/add").contentType(MediaType.APPLICATION_JSON_VALUE) + .perform(MockMvcRequestBuilders.post("/concept/add").contentType(MediaType.APPLICATION_JSON_VALUE) .content(input).principal(principal)) .andExpect(content() - .string("Error parsing request: please provide a concept list for the concept ('conceptlist' attribute).")) + .string("Error parsing request: please provide a list name for the concept ('list' attribute).")) .andExpect(status().isBadRequest()); } @@ -103,7 +114,7 @@ public void test_addConcept_emptyType() throws Exception { final String input = IOUtil .toString(this.getClass().getClassLoader().getResourceAsStream("input/addConceptWithEmptyType.json")); this.mockMvc - .perform(MockMvcRequestBuilders.post("/rest/concept/add").contentType(MediaType.APPLICATION_JSON_VALUE) + .perform(MockMvcRequestBuilders.post("/concept/add").contentType(MediaType.APPLICATION_JSON_VALUE) .content(input).principal(principal)) .andExpect(content() .string("Error parsing request: please provide a type for the concept ('type' attribute).")) @@ -111,4 +122,45 @@ public void test_addConcept_emptyType() throws Exception { } + @Test + public void test_addConcept_invalidWordnetIds() throws Exception { + String wordnetId = "WORDNET-123"; + final String input = IOUtil.toString( + this.getClass().getClassLoader().getResourceAsStream("input/addConceptWithInvalidWordNetIds.json")); + this.mockMvc + .perform(MockMvcRequestBuilders.post("/concept/add").contentType(MediaType.APPLICATION_JSON_VALUE) + .content(input).principal(principal)) + .andExpect(content() + .string("Error parsing request: please provide a valid list of wordnet ids seperated by commas. Wordnet id " + + wordnetId + " doesn't exist.")) + .andExpect(status().isBadRequest()); + + } + + @Test + public void test_addConcept_existingwrappedWordnetIds() throws Exception { + final String input = IOUtil + .toString(this.getClass().getClassLoader().getResourceAsStream("input/addConceptWrapper.json")); + this.mockMvc + .perform(MockMvcRequestBuilders.post("/concept/add").contentType(MediaType.APPLICATION_JSON_VALUE) + .content(input).principal(principal)) + .andExpect(content() + .string("Error parsing request: the WordNet concept you are trying to wrap is already wrapped.")) + .andExpect(status().isBadRequest()); + + } + + @Test + public void test_addConcept_posMismatch() throws Exception { + final String input = IOUtil + .toString(this.getClass().getClassLoader().getResourceAsStream("input/addConceptWithPosMisMatch.json")); + this.mockMvc + .perform(MockMvcRequestBuilders.post("/concept/add").contentType(MediaType.APPLICATION_JSON_VALUE) + .content(input).principal(principal)) + .andExpect(content() + .string("Error parsing request: please enter POS that matches with the wordnet POS NOUN")) + .andExpect(status().isBadRequest()); + + } + } diff --git a/Conceptpower+Spring/src/integration-test/java/edu/asu/conceptpower/rest/SynonymSearchIT.java b/Conceptpower+Spring/src/integration-test/java/edu/asu/conceptpower/rest/SynonymSearchIT.java index 55e64e158..e7cbb83a1 100644 --- a/Conceptpower+Spring/src/integration-test/java/edu/asu/conceptpower/rest/SynonymSearchIT.java +++ b/Conceptpower+Spring/src/integration-test/java/edu/asu/conceptpower/rest/SynonymSearchIT.java @@ -14,11 +14,45 @@ public class SynonymSearchIT extends IntegrationTest { + @Test + public void test_getSynonymsForId_successInJson() throws Exception { + final String output = IOUtil + .toString(this.getClass().getClassLoader().getResourceAsStream("output/synonym.json")); + this.mockMvc.perform(MockMvcRequestBuilders.get("/SynonymSearch").accept(MediaType.APPLICATION_JSON_VALUE) + .with(new RequestPostProcessor() { + public MockHttpServletRequest postProcessRequest(MockHttpServletRequest request) { + request.setParameter("id", "WID-02382039-N-02-Indian_pony"); + return request; + } + })).andExpect(content().string(output)).andExpect(status().isOk()); + } + + @Test + public void test_getSynonymsForId_emptySynonymIdInJson() throws Exception { + this.mockMvc.perform(MockMvcRequestBuilders.get("/SynonymSearch").accept(MediaType.APPLICATION_JSON_VALUE) + .with(new RequestPostProcessor() { + public MockHttpServletRequest postProcessRequest(MockHttpServletRequest request) { + request.setParameter("id", ""); + return request; + } + })).andExpect(status().isBadRequest()); + } + + @Test + public void test_getSynonymsForId_nullSynonymIdInJson() throws Exception { + this.mockMvc.perform(MockMvcRequestBuilders.get("/SynonymSearch").accept(MediaType.APPLICATION_JSON_VALUE) + .with(new RequestPostProcessor() { + public MockHttpServletRequest postProcessRequest(MockHttpServletRequest request) { + return request; + } + })).andExpect(status().isBadRequest()); + } + @Test public void test_getSynonymsForId_successInXml() throws Exception { final String output = IOUtil .toString(this.getClass().getClassLoader().getResourceAsStream("output/synonym.xml")); - this.mockMvc.perform(MockMvcRequestBuilders.get("/rest/SynonymSearch").accept(MediaType.APPLICATION_XML_VALUE) + this.mockMvc.perform(MockMvcRequestBuilders.get("/SynonymSearch").accept(MediaType.APPLICATION_XML_VALUE) .with(new RequestPostProcessor() { public MockHttpServletRequest postProcessRequest(MockHttpServletRequest request) { request.setParameter("id", "WID-02382039-N-02-Indian_pony"); @@ -29,7 +63,7 @@ public MockHttpServletRequest postProcessRequest(MockHttpServletRequest request) @Test public void test_getSynonymsForId_emptySynonymIdInXml() throws Exception { - this.mockMvc.perform(MockMvcRequestBuilders.get("/rest/SynonymSearch").accept(MediaType.APPLICATION_XML_VALUE) + this.mockMvc.perform(MockMvcRequestBuilders.get("/SynonymSearch").accept(MediaType.APPLICATION_XML_VALUE) .with(new RequestPostProcessor() { public MockHttpServletRequest postProcessRequest(MockHttpServletRequest request) { request.setParameter("id", ""); @@ -40,13 +74,11 @@ public MockHttpServletRequest postProcessRequest(MockHttpServletRequest request) @Test public void test_getSynonymsForId_nullSynonymIdInXml() throws Exception { - this.mockMvc.perform(MockMvcRequestBuilders.get("/rest/SynonymSearch").accept(MediaType.APPLICATION_XML_VALUE) + this.mockMvc.perform(MockMvcRequestBuilders.get("/SynonymSearch").accept(MediaType.APPLICATION_XML_VALUE) .with(new RequestPostProcessor() { public MockHttpServletRequest postProcessRequest(MockHttpServletRequest request) { return request; } })).andExpect(status().isBadRequest()); } - - } diff --git a/Conceptpower+Spring/src/integration-test/java/edu/asu/conceptpower/rest/TypeIdLookUpIT.java b/Conceptpower+Spring/src/integration-test/java/edu/asu/conceptpower/rest/TypeIdLookUpIT.java index 3d1657075..9c469f01d 100644 --- a/Conceptpower+Spring/src/integration-test/java/edu/asu/conceptpower/rest/TypeIdLookUpIT.java +++ b/Conceptpower+Spring/src/integration-test/java/edu/asu/conceptpower/rest/TypeIdLookUpIT.java @@ -11,14 +11,73 @@ import org.springframework.test.web.servlet.request.RequestPostProcessor; import edu.asu.conceptpower.IntegrationTest; -import edu.asu.conceptpower.servlet.xml.XMLConstants; +import edu.asu.conceptpower.rest.msg.xml.XMLConstants; public class TypeIdLookUpIT extends IntegrationTest { + @Test + public void test_getTypeById_successWithIdInJson() throws Exception { + final String output = IOUtil + .toString(this.getClass().getClassLoader().getResourceAsStream("output/types.json")); + this.mockMvc.perform(MockMvcRequestBuilders.get("/Type").accept(MediaType.APPLICATION_JSON_VALUE) + .with(new RequestPostProcessor() { + public MockHttpServletRequest postProcessRequest(MockHttpServletRequest request) { + request.setParameter("id", "986a7cc9-c0c1-4720-b344-853f08c136ab"); + return request; + } + })).andExpect(content().string(output)).andExpect(status().isOk()); + } + + @Test + public void test_getTypeById_successWithTypeIdInJson() throws Exception { + final String output = IOUtil + .toString(this.getClass().getClassLoader().getResourceAsStream("output/types.json")); + this.mockMvc.perform(MockMvcRequestBuilders.get("/Type").accept(MediaType.APPLICATION_JSON_VALUE) + .with(new RequestPostProcessor() { + public MockHttpServletRequest postProcessRequest(MockHttpServletRequest request) { + request.setParameter("id", XMLConstants.TYPE_PREFIX + "986a7cc9-c0c1-4720-b344-853f08c136ab"); + return request; + } + })).andExpect(content().string(output)).andExpect(status().isOk()); + } + + @Test + public void test_getTypeById_emptyResultInJson() throws Exception { + this.mockMvc.perform(MockMvcRequestBuilders.get("/Type").accept(MediaType.APPLICATION_JSON_VALUE) + .with(new RequestPostProcessor() { + public MockHttpServletRequest postProcessRequest(MockHttpServletRequest request) { + request.setParameter("id", XMLConstants.TYPE_PREFIX + "7c8745be-d06f-4feb-b749-910efa1b986e"); + return request; + } + })).andExpect(status().isNotFound()); + } + + @Test + public void test_getTypeById_nullTypeIdInJson() throws Exception { + this.mockMvc.perform(MockMvcRequestBuilders.get("/Type").accept(MediaType.APPLICATION_JSON_VALUE) + .with(new RequestPostProcessor() { + public MockHttpServletRequest postProcessRequest(MockHttpServletRequest request) { + return request; + } + })).andExpect(status().isBadRequest()); + + } + + @Test + public void test_getTypeById_emptyTypeIdInJson() throws Exception { + this.mockMvc.perform(MockMvcRequestBuilders.get("/Type").accept(MediaType.APPLICATION_JSON_VALUE) + .with(new RequestPostProcessor() { + public MockHttpServletRequest postProcessRequest(MockHttpServletRequest request) { + request.setParameter("id", ""); + return request; + } + })).andExpect(status().isNotFound()); + } + @Test public void test_getTypeById_successWithIdInXml() throws Exception { final String output = IOUtil.toString(this.getClass().getClassLoader().getResourceAsStream("output/types.xml")); - this.mockMvc.perform(MockMvcRequestBuilders.get("/rest/Type").accept(MediaType.APPLICATION_XML_VALUE) + this.mockMvc.perform(MockMvcRequestBuilders.get("/Type").accept(MediaType.APPLICATION_XML_VALUE) .with(new RequestPostProcessor() { public MockHttpServletRequest postProcessRequest(MockHttpServletRequest request) { request.setParameter("id", "c7d2e910-1ba9-4ee5-a05e-cfe74029b25f"); @@ -30,7 +89,7 @@ public MockHttpServletRequest postProcessRequest(MockHttpServletRequest request) @Test public void test_getTypeById_successWithTypeIdInXml() throws Exception { final String output = IOUtil.toString(this.getClass().getClassLoader().getResourceAsStream("output/types.xml")); - this.mockMvc.perform(MockMvcRequestBuilders.get("/rest/Type").accept(MediaType.APPLICATION_XML_VALUE) + this.mockMvc.perform(MockMvcRequestBuilders.get("/Type").accept(MediaType.APPLICATION_XML_VALUE) .with(new RequestPostProcessor() { public MockHttpServletRequest postProcessRequest(MockHttpServletRequest request) { request.setParameter("id", XMLConstants.TYPE_PREFIX + "c7d2e910-1ba9-4ee5-a05e-cfe74029b25f"); @@ -41,7 +100,7 @@ public MockHttpServletRequest postProcessRequest(MockHttpServletRequest request) @Test public void test_getTypeById_emptyResultInXml() throws Exception { - this.mockMvc.perform(MockMvcRequestBuilders.get("/rest/Type").accept(MediaType.APPLICATION_XML_VALUE) + this.mockMvc.perform(MockMvcRequestBuilders.get("/Type").accept(MediaType.APPLICATION_XML_VALUE) .with(new RequestPostProcessor() { public MockHttpServletRequest postProcessRequest(MockHttpServletRequest request) { request.setParameter("id", XMLConstants.TYPE_PREFIX + "7c8745be-d06f-4feb-b749-910efa1b986e"); @@ -52,7 +111,7 @@ public MockHttpServletRequest postProcessRequest(MockHttpServletRequest request) @Test public void test_getTypeById_nullTypeIdInXml() throws Exception { - this.mockMvc.perform(MockMvcRequestBuilders.get("/rest/Type").accept(MediaType.APPLICATION_XML_VALUE) + this.mockMvc.perform(MockMvcRequestBuilders.get("/Type").accept(MediaType.APPLICATION_XML_VALUE) .with(new RequestPostProcessor() { public MockHttpServletRequest postProcessRequest(MockHttpServletRequest request) { return request; @@ -63,7 +122,7 @@ public MockHttpServletRequest postProcessRequest(MockHttpServletRequest request) @Test public void test_getTypeById_emptyTypeIdInXml() throws Exception { - this.mockMvc.perform(MockMvcRequestBuilders.get("/rest/Type").accept(MediaType.APPLICATION_XML_VALUE) + this.mockMvc.perform(MockMvcRequestBuilders.get("/Type").accept(MediaType.APPLICATION_XML_VALUE) .with(new RequestPostProcessor() { public MockHttpServletRequest postProcessRequest(MockHttpServletRequest request) { request.setParameter("id", ""); diff --git a/Conceptpower+Spring/src/integration-test/resources/input/addConceptWithEmptyList.json b/Conceptpower+Spring/src/integration-test/resources/input/addConceptWithEmptyList.json index 0b033870c..7d6ee213c 100644 --- a/Conceptpower+Spring/src/integration-test/resources/input/addConceptWithEmptyList.json +++ b/Conceptpower+Spring/src/integration-test/resources/input/addConceptWithEmptyList.json @@ -1 +1,2 @@ -{ "word": "kitty", "pos": "noun", "description": "Soft kitty, sleepy kitty, little ball of fur.", "type": "986a7cc9-c0c1-4720-b344-853f08c136ab"} \ No newline at end of file +{ "word": "kitty", "pos": "noun", "description": "Soft kitty, sleepy kitty, little ball of fur.", "type": "7c8745be-d06f-4feb-b749-910efa1b986d"} + diff --git a/Conceptpower+Spring/src/integration-test/resources/input/addConceptWithInvalidWordNetIds.json b/Conceptpower+Spring/src/integration-test/resources/input/addConceptWithInvalidWordNetIds.json new file mode 100644 index 000000000..39394a2cc --- /dev/null +++ b/Conceptpower+Spring/src/integration-test/resources/input/addConceptWithInvalidWordNetIds.json @@ -0,0 +1 @@ +{ "word": "kitty", "pos": "noun", "conceptlist": "TestList", "description": "Soft kitty, sleepy kitty, little ball of fur.", "type": "7c8745be-d06f-4feb-b749-910efa1b986d","wordnetIds":"WORDNET-123,WORDNET-456"} \ No newline at end of file diff --git a/Conceptpower+Spring/src/integration-test/resources/input/addConceptWithPosMisMatch.json b/Conceptpower+Spring/src/integration-test/resources/input/addConceptWithPosMisMatch.json new file mode 100644 index 000000000..1dfb5339f --- /dev/null +++ b/Conceptpower+Spring/src/integration-test/resources/input/addConceptWithPosMisMatch.json @@ -0,0 +1 @@ +{ "word": "pony", "pos": "verb", "conceptlist": "TestList", "description": "Soft kitty, sleepy kitty, little ball of fur.", "type": "7c8745be-d06f-4feb-b749-910efa1b986d","wordnetIds": "WID-02380335-N-01-pony"} \ No newline at end of file diff --git a/Conceptpower+Spring/src/integration-test/resources/input/addConceptWrapper.json b/Conceptpower+Spring/src/integration-test/resources/input/addConceptWrapper.json new file mode 100644 index 000000000..276de19f6 --- /dev/null +++ b/Conceptpower+Spring/src/integration-test/resources/input/addConceptWrapper.json @@ -0,0 +1 @@ +{ "word": "pony", "pos": "noun", "conceptlist": "VogonWeb Concepts", "description": "Wrapped concept of pony.", "type": "986a7cc9-c0c1-4720-b344-853f08c136ab","wordnetIds":"WID-02380335-N-01-pony"} \ No newline at end of file diff --git a/Conceptpower+Spring/src/integration-test/resources/input/addConceptsWithInvalidConceptList.json b/Conceptpower+Spring/src/integration-test/resources/input/addConceptsWithInvalidConceptList.json index c821bd6f1..c7582b95f 100644 --- a/Conceptpower+Spring/src/integration-test/resources/input/addConceptsWithInvalidConceptList.json +++ b/Conceptpower+Spring/src/integration-test/resources/input/addConceptsWithInvalidConceptList.json @@ -1 +1,2 @@ -[{ "word": "kitty", "pos": "noun", "conceptlist": "ConceptListInvalid", "description": "Soft kitty, sleepy kitty, little ball of fur.", "type": "986a7cc9-c0c1-4720-b344-853f08c136ab"},{ "word": "kitty-2", "pos": "noun", "conceptlist": "ConceptListInvalid", "description": "Soft kitty, sleepy kitty, little ball of fur.", "type": "986a7cc9-c0c1-4720-b344-853f08c136ab"}] \ No newline at end of file +[{ "word": "kitty", "pos": "noun", "conceptlist": "ConceptListInvalid", "description": "Soft kitty, sleepy kitty, little ball of fur.", "type": "7c8745be-d06f-4feb-b749-910efa1b986d"},{ "word": "kitty-2", "pos": "noun", "conceptlist": "ConceptListInvalid", "description": "Soft kitty, sleepy kitty, little ball of fur.", "type": "7c8745be-d06f-4feb-b749-910efa1b986d"}] + diff --git a/Conceptpower+Spring/src/integration-test/resources/output/conceptForGenericWordnet.json b/Conceptpower+Spring/src/integration-test/resources/output/conceptForGenericWordnet.json new file mode 100644 index 000000000..92202bc91 --- /dev/null +++ b/Conceptpower+Spring/src/integration-test/resources/output/conceptForGenericWordnet.json @@ -0,0 +1 @@ +{"conceptEntries":[{"id":"WID-02380464-N-01-polo_pony","lemma":"polo pony","pos":"NOUN","description":"a small agile horse specially bred and trained for playing polo","conceptList":"WordNet","deleted":false,"alternativeIds":[{"concept_id":"WID-02380464-N-??-polo_pony","concept_uri":"http://www.digitalhps.org/concepts/WID-02380464-N-??-polo_pony"},{"concept_id":"WID-02380464-N-01-polo_pony","concept_uri":"http://www.digitalhps.org/concepts/WID-02380464-N-01-polo_pony"}],"concept_uri":"http://www.digitalhps.org/concepts/WID-02380464-N-01-polo_pony","creator_id":"","equal_to":"","modified_by":"","similar_to":"","synonym_ids":"","wordnet_id":"WID-02380464-N-01-polo_pony"}],"pagination":null} \ No newline at end of file diff --git a/Conceptpower+Spring/src/integration-test/resources/output/conceptForGenericWordnet.xml b/Conceptpower+Spring/src/integration-test/resources/output/conceptForGenericWordnet.xml new file mode 100644 index 000000000..4e669ecd8 --- /dev/null +++ b/Conceptpower+Spring/src/integration-test/resources/output/conceptForGenericWordnet.xml @@ -0,0 +1 @@ +http://www.digitalhps.org/concepts/WID-02380464-N-01-polo_ponypolo ponyNOUNa small agile horse specially bred and trained for playing poloWordNetfalseWID-02380464-N-01-polo_ponyhttp://www.digitalhps.org/concepts/WID-02380464-N-??-polo_ponyhttp://www.digitalhps.org/concepts/WID-02380464-N-01-polo_pony \ No newline at end of file diff --git a/Conceptpower+Spring/src/integration-test/resources/output/conceptForLocalId.json b/Conceptpower+Spring/src/integration-test/resources/output/conceptForLocalId.json new file mode 100644 index 000000000..48df92116 --- /dev/null +++ b/Conceptpower+Spring/src/integration-test/resources/output/conceptForLocalId.json @@ -0,0 +1 @@ +{"conceptEntries":[{"id":"CONdf62c00c-f4a9-4564-9dd6-c9b955650f3a","lemma":"Abbott Henderson Thayer","pos":"noun","description":"American artist, naturalist and teacher. As a painter of portraits, figures, animals and landscapes, he enjoyed a certain prominence during his lifetime, and his paintings are represented in the major American art collections. He is perhaps best known for his 'angel' paintings, some of which use his children as models.","conceptList":"VogonWeb Concepts","deleted":false,"alternativeIds":[{"concept_id":"","concept_uri":"http://www.digitalhps.org/concepts/"},{"concept_id":"CONdf62c00c-f4a9-4564-9dd6-c9b955650f3a","concept_uri":"http://www.digitalhps.org/concepts/CONdf62c00c-f4a9-4564-9dd6-c9b955650f3a"}],"concept_uri":"http://www.digitalhps.org/concepts/CONdf62c00c-f4a9-4564-9dd6-c9b955650f3a","creator_id":"admin","equal_to":"http://viaf.org/viaf/55043769","modified_by":"admin","similar_to":"","synonym_ids":"[],","wordnet_id":""}],"pagination":null} \ No newline at end of file diff --git a/Conceptpower+Spring/src/integration-test/resources/output/conceptForLocalId.xml b/Conceptpower+Spring/src/integration-test/resources/output/conceptForLocalId.xml index 4c1ae2ae6..88de908ee 100644 --- a/Conceptpower+Spring/src/integration-test/resources/output/conceptForLocalId.xml +++ b/Conceptpower+Spring/src/integration-test/resources/output/conceptForLocalId.xml @@ -1 +1,2 @@ -http://www.digitalhps.org/concepts/CONdf62c00c-f4a9-4564-9dd6-c9b955650f3aAbbott Henderson ThayernounAmerican artist, naturalist and teacher. As a painter of portraits, figures, animals and landscapes, he enjoyed a certain prominence during his lifetime, and his paintings are represented in the major American art collections. He is perhaps best known for his 'angel' paintings, some of which use his children as models.VogonWeb Conceptstesthttp://viaf.org/viaf/55043769admin[],false \ No newline at end of file +http://www.digitalhps.org/concepts/CONdf62c00c-f4a9-4564-9dd6-c9b955650f3aAbbott Henderson ThayernounAmerican artist, naturalist and teacher. As a painter of portraits, figures, animals and landscapes, he enjoyed a certain prominence during his lifetime, and his paintings are represented in the major American art collections. He is perhaps best known for his 'angel' paintings, some of which use his children as models.VogonWeb Conceptsadminhttp://viaf.org/viaf/55043769admin[],falsehttp://www.digitalhps.org/concepts/http://www.digitalhps.org/concepts/CONdf62c00c-f4a9-4564-9dd6-c9b955650f3a + diff --git a/Conceptpower+Spring/src/integration-test/resources/output/conceptLookUpForMultipletEntry.json b/Conceptpower+Spring/src/integration-test/resources/output/conceptLookUpForMultipletEntry.json new file mode 100644 index 000000000..24ec5d944 --- /dev/null +++ b/Conceptpower+Spring/src/integration-test/resources/output/conceptLookUpForMultipletEntry.json @@ -0,0 +1 @@ +{"conceptEntries":[{"id":"CON0252cf48-4233-495d-94ae-42480b0fd82b","lemma":"Douglas","pos":"NOUN","description":"Similar to concept","conceptList":"VogonWeb Concepts","type":{"type_id":"986a7cc9-c0c1-4720-b344-853f08c136ab","type_uri":"http://www.digitalhps.org/types/TYPE_986a7cc9-c0c1-4720-b344-853f08c136ab","type_name":"E21 Person"},"deleted":false,"alternativeIds":[{"concept_id":"CON0252cf48-4233-495d-94ae-42480b0fd82b","concept_uri":"http://www.digitalhps.org/concepts/CON0252cf48-4233-495d-94ae-42480b0fd82b"},{"concept_id":"WID-10941206-N-01-Douglas","concept_uri":"http://www.digitalhps.org/concepts/WID-10941206-N-01-Douglas"}],"concept_uri":"http://www.digitalhps.org/concepts/CON0252cf48-4233-495d-94ae-42480b0fd82b","creator_id":"admin","equal_to":"","modified_by":"","similar_to":"http://viaf.org/viaf/248802520","synonym_ids":"","wordnet_id":"WID-10941206-N-01-Douglas"},{"id":"WID-10808886-N-02-Edgar_Douglas_Adrian","lemma":"edgar douglas adrian","pos":"noun","description":"English physiologist who conducted research into the function of neurons; 1st baron of Cambridge (1889-1997)","conceptList":"WordNet","deleted":false,"alternativeIds":[{"concept_id":"WID-10808886-N-02-Edgar_Douglas_Adrian","concept_uri":"http://www.digitalhps.org/concepts/WID-10808886-N-02-Edgar_Douglas_Adrian"}],"concept_uri":"http://www.digitalhps.org/concepts/WID-10808886-N-02-Edgar_Douglas_Adrian","creator_id":"","equal_to":"","modified_by":"","similar_to":"","synonym_ids":"WID-10808886-N-01-Adrian,WID-10808886-N-03-Baron_Adrian,","wordnet_id":"WID-10808886-N-02-Edgar_Douglas_Adrian"},{"id":"WID-10965361-N-02-Douglas_Fairbanks","lemma":"douglas fairbanks","pos":"noun","description":"United States film actor noted for his swashbuckling roles (1883-1939)","conceptList":"WordNet","deleted":false,"alternativeIds":[{"concept_id":"WID-10965361-N-02-Douglas_Fairbanks","concept_uri":"http://www.digitalhps.org/concepts/WID-10965361-N-02-Douglas_Fairbanks"}],"concept_uri":"http://www.digitalhps.org/concepts/WID-10965361-N-02-Douglas_Fairbanks","creator_id":"","equal_to":"","modified_by":"","similar_to":"","synonym_ids":"WID-10965361-N-01-Fairbanks,WID-10965361-N-03-Douglas_Elton_Fairbanks,WID-10965361-N-04-Julius_Ullman,","wordnet_id":"WID-10965361-N-02-Douglas_Fairbanks"},{"id":"WID-11629047-N-02-big-cone_douglas_fir","lemma":"big-cone douglas fir","pos":"noun","description":"douglas fir of California having cones 4-8 inches long","conceptList":"WordNet","deleted":false,"alternativeIds":[{"concept_id":"WID-11629047-N-02-big-cone_douglas_fir","concept_uri":"http://www.digitalhps.org/concepts/WID-11629047-N-02-big-cone_douglas_fir"}],"concept_uri":"http://www.digitalhps.org/concepts/WID-11629047-N-02-big-cone_douglas_fir","creator_id":"","equal_to":"","modified_by":"","similar_to":"","synonym_ids":"WID-11629047-N-01-big-cone_spruce,WID-11629047-N-03-Pseudotsuga_macrocarpa,","wordnet_id":"WID-11629047-N-02-big-cone_douglas_fir"},{"id":"WID-11192533-N-03-James_Douglas_Morrison","lemma":"james douglas morrison","pos":"noun","description":"United States rock singer (1943-1971)","conceptList":"WordNet","deleted":false,"alternativeIds":[{"concept_id":"WID-11192533-N-03-James_Douglas_Morrison","concept_uri":"http://www.digitalhps.org/concepts/WID-11192533-N-03-James_Douglas_Morrison"}],"concept_uri":"http://www.digitalhps.org/concepts/WID-11192533-N-03-James_Douglas_Morrison","creator_id":"","equal_to":"","modified_by":"","similar_to":"","synonym_ids":"WID-11192533-N-01-Morrison,WID-11192533-N-02-Jim_Morrison,","wordnet_id":"WID-11192533-N-03-James_Douglas_Morrison"},{"id":"WID-10903918-N-03-Sir_John_Douglas_Cockcroft","lemma":"sir john douglas cockcroft","pos":"noun","description":"British physicist who (with Ernest Walton in 1931) first split an atom (1897-1967)","conceptList":"WordNet","deleted":false,"alternativeIds":[{"concept_id":"WID-10903918-N-03-Sir_John_Douglas_Cockcroft","concept_uri":"http://www.digitalhps.org/concepts/WID-10903918-N-03-Sir_John_Douglas_Cockcroft"}],"concept_uri":"http://www.digitalhps.org/concepts/WID-10903918-N-03-Sir_John_Douglas_Cockcroft","creator_id":"","equal_to":"","modified_by":"","similar_to":"","synonym_ids":"WID-10903918-N-01-Cockcroft,WID-10903918-N-02-Sir_John_Cockcroft,","wordnet_id":"WID-10903918-N-03-Sir_John_Douglas_Cockcroft"},{"id":"WID-11384291-N-04-Edward_Douglas_White_Jr.","lemma":"edward douglas white jr.","pos":"noun","description":"United States jurist appointed chief justice of the United States Supreme Court in 1910 by President Taft; noted for his work on antitrust legislation (1845-1921)","conceptList":"WordNet","deleted":false,"alternativeIds":[{"concept_id":"WID-11384291-N-04-Edward_Douglas_White_Jr.","concept_uri":"http://www.digitalhps.org/concepts/WID-11384291-N-04-Edward_Douglas_White_Jr."}],"concept_uri":"http://www.digitalhps.org/concepts/WID-11384291-N-04-Edward_Douglas_White_Jr.","creator_id":"","equal_to":"","modified_by":"","similar_to":"","synonym_ids":"WID-11384291-N-01-White,WID-11384291-N-02-Edward_White,WID-11384291-N-03-Edward_D._White,","wordnet_id":"WID-11384291-N-04-Edward_Douglas_White_Jr."},{"id":"WID-11628456-N-01-douglas_fir","lemma":"douglas fir","pos":"noun","description":"tall evergreen timber tree of western North America having resinous wood and short needles","conceptList":"WordNet","deleted":false,"alternativeIds":[{"concept_id":"WID-11628456-N-01-douglas_fir","concept_uri":"http://www.digitalhps.org/concepts/WID-11628456-N-01-douglas_fir"}],"concept_uri":"http://www.digitalhps.org/concepts/WID-11628456-N-01-douglas_fir","creator_id":"","equal_to":"","modified_by":"","similar_to":"","synonym_ids":"","wordnet_id":"WID-11628456-N-01-douglas_fir"},{"id":"WID-10965550-N-02-Douglas_Fairbanks_Jr.","lemma":"douglas fairbanks jr.","pos":"noun","description":"United States film actor; son of Douglas Elton Fairbanks, (1909-2000)","conceptList":"WordNet","deleted":false,"alternativeIds":[{"concept_id":"WID-10965550-N-02-Douglas_Fairbanks_Jr.","concept_uri":"http://www.digitalhps.org/concepts/WID-10965550-N-02-Douglas_Fairbanks_Jr."}],"concept_uri":"http://www.digitalhps.org/concepts/WID-10965550-N-02-Douglas_Fairbanks_Jr.","creator_id":"","equal_to":"","modified_by":"","similar_to":"","synonym_ids":"WID-10965550-N-01-Fairbanks,","wordnet_id":"WID-10965550-N-02-Douglas_Fairbanks_Jr."},{"id":"WID-11146670-N-02-Douglas_MacArthur","lemma":"douglas macarthur","pos":"noun","description":"United States general who served as chief of staff and commanded Allied forces in the South Pacific during World War II; he accepted the surrender of Japan (1880-1964)","conceptList":"WordNet","deleted":false,"alternativeIds":[{"concept_id":"WID-11146670-N-02-Douglas_MacArthur","concept_uri":"http://www.digitalhps.org/concepts/WID-11146670-N-02-Douglas_MacArthur"}],"concept_uri":"http://www.digitalhps.org/concepts/WID-11146670-N-02-Douglas_MacArthur","creator_id":"","equal_to":"","modified_by":"","similar_to":"","synonym_ids":"WID-11146670-N-01-MacArthur,","wordnet_id":"WID-11146670-N-02-Douglas_MacArthur"},{"id":"WID-11628678-N-01-douglas_fir","lemma":"douglas fir","pos":"noun","description":"strong durable timber of a douglas fir","conceptList":"WordNet","deleted":false,"alternativeIds":[{"concept_id":"WID-11628678-N-01-douglas_fir","concept_uri":"http://www.digitalhps.org/concepts/WID-11628678-N-01-douglas_fir"}],"concept_uri":"http://www.digitalhps.org/concepts/WID-11628678-N-01-douglas_fir","creator_id":"","equal_to":"","modified_by":"","similar_to":"","synonym_ids":"","wordnet_id":"WID-11628678-N-01-douglas_fir"},{"id":"WID-11628793-N-02-douglas_spruce","lemma":"douglas spruce","pos":"noun","description":"lofty douglas fir of northwestern North America having short needles and egg-shaped cones","conceptList":"WordNet","deleted":false,"alternativeIds":[{"concept_id":"WID-11628793-N-02-douglas_spruce","concept_uri":"http://www.digitalhps.org/concepts/WID-11628793-N-02-douglas_spruce"}],"concept_uri":"http://www.digitalhps.org/concepts/WID-11628793-N-02-douglas_spruce","creator_id":"","equal_to":"","modified_by":"","similar_to":"","synonym_ids":"WID-11628793-N-01-green_douglas_fir,WID-11628793-N-03-douglas_pine,WID-11628793-N-04-douglas_hemlock,WID-11628793-N-05-Oregon_fir,WID-11628793-N-06-Oregon_pine,WID-11628793-N-07-Pseudotsuga_menziesii,","wordnet_id":"WID-11628793-N-02-douglas_spruce"},{"id":"WID-10965361-N-03-Douglas_Elton_Fairbanks","lemma":"douglas elton fairbanks","pos":"noun","description":"United States film actor noted for his swashbuckling roles (1883-1939)","conceptList":"WordNet","deleted":false,"alternativeIds":[{"concept_id":"WID-10965361-N-03-Douglas_Elton_Fairbanks","concept_uri":"http://www.digitalhps.org/concepts/WID-10965361-N-03-Douglas_Elton_Fairbanks"}],"concept_uri":"http://www.digitalhps.org/concepts/WID-10965361-N-03-Douglas_Elton_Fairbanks","creator_id":"","equal_to":"","modified_by":"","similar_to":"","synonym_ids":"WID-10965361-N-01-Fairbanks,WID-10965361-N-02-Douglas_Fairbanks,WID-10965361-N-04-Julius_Ullman,","wordnet_id":"WID-10965361-N-03-Douglas_Elton_Fairbanks"},{"id":"WID-11628793-N-01-green_douglas_fir","lemma":"green douglas fir","pos":"noun","description":"lofty douglas fir of northwestern North America having short needles and egg-shaped cones","conceptList":"WordNet","deleted":false,"alternativeIds":[{"concept_id":"WID-11628793-N-01-green_douglas_fir","concept_uri":"http://www.digitalhps.org/concepts/WID-11628793-N-01-green_douglas_fir"}],"concept_uri":"http://www.digitalhps.org/concepts/WID-11628793-N-01-green_douglas_fir","creator_id":"","equal_to":"","modified_by":"","similar_to":"","synonym_ids":"WID-11628793-N-02-douglas_spruce,WID-11628793-N-03-douglas_pine,WID-11628793-N-04-douglas_hemlock,WID-11628793-N-05-Oregon_fir,WID-11628793-N-06-Oregon_pine,WID-11628793-N-07-Pseudotsuga_menziesii,","wordnet_id":"WID-11628793-N-01-green_douglas_fir"},{"id":"WID-10941206-N-02-Stephen_A._Douglas","lemma":"stephen a. douglas","pos":"noun","description":"United States politician who proposed that individual territories be allowed to decide whether they would have slavery; he engaged in a famous series of debates with Abraham Lincoln (1813-1861)","conceptList":"WordNet","deleted":false,"alternativeIds":[{"concept_id":"WID-10941206-N-02-Stephen_A._Douglas","concept_uri":"http://www.digitalhps.org/concepts/WID-10941206-N-02-Stephen_A._Douglas"}],"concept_uri":"http://www.digitalhps.org/concepts/WID-10941206-N-02-Stephen_A._Douglas","creator_id":"","equal_to":"","modified_by":"","similar_to":"","synonym_ids":"WID-10941206-N-01-Douglas,WID-10941206-N-03-Stephen_Arnold_Douglas,WID-10941206-N-04-Little_Giant,","wordnet_id":"WID-10941206-N-02-Stephen_A._Douglas"},{"id":"WID-10860444-N-03-Ray_Douglas_Bradbury","lemma":"ray douglas bradbury","pos":"noun","description":"United States writer of science fiction (born 1920)","conceptList":"WordNet","deleted":false,"alternativeIds":[{"concept_id":"WID-10860444-N-03-Ray_Douglas_Bradbury","concept_uri":"http://www.digitalhps.org/concepts/WID-10860444-N-03-Ray_Douglas_Bradbury"}],"concept_uri":"http://www.digitalhps.org/concepts/WID-10860444-N-03-Ray_Douglas_Bradbury","creator_id":"","equal_to":"","modified_by":"","similar_to":"","synonym_ids":"WID-10860444-N-01-Bradbury,WID-10860444-N-02-Ray_Bradbury,","wordnet_id":"WID-10860444-N-03-Ray_Douglas_Bradbury"},{"id":"WID-11628793-N-04-douglas_hemlock","lemma":"douglas hemlock","pos":"noun","description":"lofty douglas fir of northwestern North America having short needles and egg-shaped cones","conceptList":"WordNet","deleted":false,"alternativeIds":[{"concept_id":"WID-11628793-N-04-douglas_hemlock","concept_uri":"http://www.digitalhps.org/concepts/WID-11628793-N-04-douglas_hemlock"}],"concept_uri":"http://www.digitalhps.org/concepts/WID-11628793-N-04-douglas_hemlock","creator_id":"","equal_to":"","modified_by":"","similar_to":"","synonym_ids":"WID-11628793-N-01-green_douglas_fir,WID-11628793-N-02-douglas_spruce,WID-11628793-N-03-douglas_pine,WID-11628793-N-05-Oregon_fir,WID-11628793-N-06-Oregon_pine,WID-11628793-N-07-Pseudotsuga_menziesii,","wordnet_id":"WID-11628793-N-04-douglas_hemlock"},{"id":"WID-11306297-N-03-Ian_Douglas_Smith","lemma":"ian douglas smith","pos":"noun","description":"Rhodesian statesman who declared independence of Zimbabwe from Great Britain (born in 1919)","conceptList":"WordNet","deleted":false,"alternativeIds":[{"concept_id":"WID-11306297-N-03-Ian_Douglas_Smith","concept_uri":"http://www.digitalhps.org/concepts/WID-11306297-N-03-Ian_Douglas_Smith"}],"concept_uri":"http://www.digitalhps.org/concepts/WID-11306297-N-03-Ian_Douglas_Smith","creator_id":"","equal_to":"","modified_by":"","similar_to":"","synonym_ids":"WID-11306297-N-01-Smith,WID-11306297-N-02-Ian_Smith,","wordnet_id":"WID-11306297-N-03-Ian_Douglas_Smith"},{"id":"CONe40a6b36-dbaa-46c7-96ea-2c6a1cb080a4","lemma":"Douglas Weiner","pos":"noun","description":"American 20th century environmentalist","conceptList":"VogonWeb Concepts","deleted":false,"alternativeIds":[{"concept_id":"","concept_uri":"http://www.digitalhps.org/concepts/"},{"concept_id":"CONe40a6b36-dbaa-46c7-96ea-2c6a1cb080a4","concept_uri":"http://www.digitalhps.org/concepts/CONe40a6b36-dbaa-46c7-96ea-2c6a1cb080a4"}],"concept_uri":"http://www.digitalhps.org/concepts/CONe40a6b36-dbaa-46c7-96ea-2c6a1cb080a4","creator_id":"test","equal_to":"http://viaf.org/viaf/283748929","modified_by":"admin","similar_to":"http://viaf.org/viaf/248802520","synonym_ids":"[]","wordnet_id":""},{"id":"WID-02357585-N-02-Douglas_squirrel","lemma":"douglas squirrel","pos":"noun","description":"far western United States counterpart of the red squirrel","conceptList":"WordNet","deleted":false,"alternativeIds":[{"concept_id":"WID-02357585-N-02-Douglas_squirrel","concept_uri":"http://www.digitalhps.org/concepts/WID-02357585-N-02-Douglas_squirrel"}],"concept_uri":"http://www.digitalhps.org/concepts/WID-02357585-N-02-Douglas_squirrel","creator_id":"","equal_to":"","modified_by":"","similar_to":"","synonym_ids":"WID-02357585-N-01-chickeree,WID-02357585-N-03-Tamiasciurus_douglasi,","wordnet_id":"WID-02357585-N-02-Douglas_squirrel"},{"id":"WID-11190024-N-02-Douglas_Moore","lemma":"douglas moore","pos":"noun","description":"United States composer of works noted for their use of the American vernacular (1893-1969)","conceptList":"WordNet","deleted":false,"alternativeIds":[{"concept_id":"WID-11190024-N-02-Douglas_Moore","concept_uri":"http://www.digitalhps.org/concepts/WID-11190024-N-02-Douglas_Moore"}],"concept_uri":"http://www.digitalhps.org/concepts/WID-11190024-N-02-Douglas_Moore","creator_id":"","equal_to":"","modified_by":"","similar_to":"","synonym_ids":"WID-11190024-N-01-Moore,","wordnet_id":"WID-11190024-N-02-Douglas_Moore"},{"id":"WID-11628793-N-03-douglas_pine","lemma":"douglas pine","pos":"noun","description":"lofty douglas fir of northwestern North America having short needles and egg-shaped cones","conceptList":"WordNet","deleted":false,"alternativeIds":[{"concept_id":"WID-11628793-N-03-douglas_pine","concept_uri":"http://www.digitalhps.org/concepts/WID-11628793-N-03-douglas_pine"}],"concept_uri":"http://www.digitalhps.org/concepts/WID-11628793-N-03-douglas_pine","creator_id":"","equal_to":"","modified_by":"","similar_to":"","synonym_ids":"WID-11628793-N-01-green_douglas_fir,WID-11628793-N-02-douglas_spruce,WID-11628793-N-04-douglas_hemlock,WID-11628793-N-05-Oregon_fir,WID-11628793-N-06-Oregon_pine,WID-11628793-N-07-Pseudotsuga_menziesii,","wordnet_id":"WID-11628793-N-03-douglas_pine"},{"id":"WID-10941206-N-03-Stephen_Arnold_Douglas","lemma":"stephen arnold douglas","pos":"noun","description":"United States politician who proposed that individual territories be allowed to decide whether they would have slavery; he engaged in a famous series of debates with Abraham Lincoln (1813-1861)","conceptList":"WordNet","deleted":false,"alternativeIds":[{"concept_id":"WID-10941206-N-03-Stephen_Arnold_Douglas","concept_uri":"http://www.digitalhps.org/concepts/WID-10941206-N-03-Stephen_Arnold_Douglas"}],"concept_uri":"http://www.digitalhps.org/concepts/WID-10941206-N-03-Stephen_Arnold_Douglas","creator_id":"","equal_to":"","modified_by":"","similar_to":"","synonym_ids":"WID-10941206-N-01-Douglas,WID-10941206-N-02-Stephen_A._Douglas,WID-10941206-N-04-Little_Giant,","wordnet_id":"WID-10941206-N-03-Stephen_Arnold_Douglas"},{"id":"WID-11121876-N-03-Mary_Douglas_Leakey","lemma":"mary douglas leakey","pos":"noun","description":"English paleontologist (the wife of Louis Leakey) who discovered the Zinjanthropus skull that was 1,750,000 years old (1913-1996)","conceptList":"WordNet","deleted":false,"alternativeIds":[{"concept_id":"WID-11121876-N-03-Mary_Douglas_Leakey","concept_uri":"http://www.digitalhps.org/concepts/WID-11121876-N-03-Mary_Douglas_Leakey"}],"concept_uri":"http://www.digitalhps.org/concepts/WID-11121876-N-03-Mary_Douglas_Leakey","creator_id":"","equal_to":"","modified_by":"","similar_to":"","synonym_ids":"WID-11121876-N-01-Leakey,WID-11121876-N-02-Mary_Leakey,","wordnet_id":"WID-11121876-N-03-Mary_Douglas_Leakey"}],"pagination":null} \ No newline at end of file diff --git a/Conceptpower+Spring/src/integration-test/resources/output/conceptLookUpForMultipletEntry.xml b/Conceptpower+Spring/src/integration-test/resources/output/conceptLookUpForMultipletEntry.xml index baf1d6270..58454d877 100644 --- a/Conceptpower+Spring/src/integration-test/resources/output/conceptLookUpForMultipletEntry.xml +++ b/Conceptpower+Spring/src/integration-test/resources/output/conceptLookUpForMultipletEntry.xml @@ -1 +1,2 @@ -http://www.digitalhps.org/concepts/CON0252cf48-4233-495d-94ae-42480b0fd82bDouglasNOUNSimilar to conceptVogonWeb Conceptsadminhttp://viaf.org/viaf/248802520E21 PersonfalseWID-10941206-N-01-Douglas,http://www.digitalhps.org/concepts/WID-10965361-N-02-Douglas_Fairbanksdouglas fairbanksnounUnited States film actor noted for his swashbuckling roles (1883-1939)WordNetWID-10965361-N-01-Fairbanks,WID-10965361-N-03-Douglas_Elton_Fairbanks,WID-10965361-N-04-Julius_Ullman,falseWID-10965361-N-02-Douglas_Fairbankshttp://www.digitalhps.org/concepts/WID-11628793-N-04-douglas_hemlockdouglas hemlocknounlofty douglas fir of northwestern North America having short needles and egg-shaped conesWordNetWID-11628793-N-01-green_douglas_fir,WID-11628793-N-02-douglas_spruce,WID-11628793-N-03-douglas_pine,WID-11628793-N-05-Oregon_fir,WID-11628793-N-06-Oregon_pine,WID-11628793-N-07-Pseudotsuga_menziesii,falseWID-11628793-N-04-douglas_hemlockhttp://www.digitalhps.org/concepts/WID-11628456-N-01-douglas_firdouglas firnountall evergreen timber tree of western North America having resinous wood and short needlesWordNetfalseWID-11628456-N-01-douglas_firhttp://www.digitalhps.org/concepts/WID-02357585-N-02-Douglas_squirreldouglas squirrelnounfar western United States counterpart of the red squirrelWordNetWID-02357585-N-01-chickeree,WID-02357585-N-03-Tamiasciurus_douglasi,falseWID-02357585-N-02-Douglas_squirrelhttp://www.digitalhps.org/concepts/WID-11146670-N-02-Douglas_MacArthurdouglas macarthurnounUnited States general who served as chief of staff and commanded Allied forces in the South Pacific during World War II; he accepted the surrender of Japan (1880-1964)WordNetWID-11146670-N-01-MacArthur,falseWID-11146670-N-02-Douglas_MacArthurhttp://www.digitalhps.org/concepts/WID-11190024-N-02-Douglas_Mooredouglas moorenounUnited States composer of works noted for their use of the American vernacular (1893-1969)WordNetWID-11190024-N-01-Moore,falseWID-11190024-N-02-Douglas_Moorehttp://www.digitalhps.org/concepts/WID-11628793-N-03-douglas_pinedouglas pinenounlofty douglas fir of northwestern North America having short needles and egg-shaped conesWordNetWID-11628793-N-01-green_douglas_fir,WID-11628793-N-02-douglas_spruce,WID-11628793-N-04-douglas_hemlock,WID-11628793-N-05-Oregon_fir,WID-11628793-N-06-Oregon_pine,WID-11628793-N-07-Pseudotsuga_menziesii,falseWID-11628793-N-03-douglas_pinehttp://www.digitalhps.org/concepts/WID-11628678-N-01-douglas_firdouglas firnounstrong durable timber of a douglas firWordNetfalseWID-11628678-N-01-douglas_firhttp://www.digitalhps.org/concepts/WID-11628793-N-02-douglas_sprucedouglas sprucenounlofty douglas fir of northwestern North America having short needles and egg-shaped conesWordNetWID-11628793-N-01-green_douglas_fir,WID-11628793-N-03-douglas_pine,WID-11628793-N-04-douglas_hemlock,WID-11628793-N-05-Oregon_fir,WID-11628793-N-06-Oregon_pine,WID-11628793-N-07-Pseudotsuga_menziesii,falseWID-11628793-N-02-douglas_spruce \ No newline at end of file +http://www.digitalhps.org/concepts/CON0252cf48-4233-495d-94ae-42480b0fd82bDouglasNOUNSimilar to conceptVogonWeb Conceptsadminhttp://viaf.org/viaf/248802520E21 PersonfalseWID-10941206-N-01-Douglashttp://www.digitalhps.org/concepts/CON0252cf48-4233-495d-94ae-42480b0fd82bhttp://www.digitalhps.org/concepts/WID-10941206-N-01-Douglashttp://www.digitalhps.org/concepts/WID-10808886-N-02-Edgar_Douglas_Adrianedgar douglas adriannounEnglish physiologist who conducted research into the function of neurons; 1st baron of Cambridge (1889-1997)WordNetWID-10808886-N-01-Adrian,WID-10808886-N-03-Baron_Adrian,falseWID-10808886-N-02-Edgar_Douglas_Adrianhttp://www.digitalhps.org/concepts/WID-10808886-N-02-Edgar_Douglas_Adrianhttp://www.digitalhps.org/concepts/WID-10965361-N-02-Douglas_Fairbanksdouglas fairbanksnounUnited States film actor noted for his swashbuckling roles (1883-1939)WordNetWID-10965361-N-01-Fairbanks,WID-10965361-N-03-Douglas_Elton_Fairbanks,WID-10965361-N-04-Julius_Ullman,falseWID-10965361-N-02-Douglas_Fairbankshttp://www.digitalhps.org/concepts/WID-10965361-N-02-Douglas_Fairbankshttp://www.digitalhps.org/concepts/WID-11629047-N-02-big-cone_douglas_firbig-cone douglas firnoundouglas fir of California having cones 4-8 inches longWordNetWID-11629047-N-01-big-cone_spruce,WID-11629047-N-03-Pseudotsuga_macrocarpa,falseWID-11629047-N-02-big-cone_douglas_firhttp://www.digitalhps.org/concepts/WID-11629047-N-02-big-cone_douglas_firhttp://www.digitalhps.org/concepts/WID-11192533-N-03-James_Douglas_Morrisonjames douglas morrisonnounUnited States rock singer (1943-1971)WordNetWID-11192533-N-01-Morrison,WID-11192533-N-02-Jim_Morrison,falseWID-11192533-N-03-James_Douglas_Morrisonhttp://www.digitalhps.org/concepts/WID-11192533-N-03-James_Douglas_Morrisonhttp://www.digitalhps.org/concepts/WID-10903918-N-03-Sir_John_Douglas_Cockcroftsir john douglas cockcroftnounBritish physicist who (with Ernest Walton in 1931) first split an atom (1897-1967)WordNetWID-10903918-N-01-Cockcroft,WID-10903918-N-02-Sir_John_Cockcroft,falseWID-10903918-N-03-Sir_John_Douglas_Cockcrofthttp://www.digitalhps.org/concepts/WID-10903918-N-03-Sir_John_Douglas_Cockcrofthttp://www.digitalhps.org/concepts/WID-11384291-N-04-Edward_Douglas_White_Jr.edward douglas white jr.nounUnited States jurist appointed chief justice of the United States Supreme Court in 1910 by President Taft; noted for his work on antitrust legislation (1845-1921)WordNetWID-11384291-N-01-White,WID-11384291-N-02-Edward_White,WID-11384291-N-03-Edward_D._White,falseWID-11384291-N-04-Edward_Douglas_White_Jr.http://www.digitalhps.org/concepts/WID-11384291-N-04-Edward_Douglas_White_Jr.http://www.digitalhps.org/concepts/WID-11628456-N-01-douglas_firdouglas firnountall evergreen timber tree of western North America having resinous wood and short needlesWordNetfalseWID-11628456-N-01-douglas_firhttp://www.digitalhps.org/concepts/WID-11628456-N-01-douglas_firhttp://www.digitalhps.org/concepts/WID-10965550-N-02-Douglas_Fairbanks_Jr.douglas fairbanks jr.nounUnited States film actor; son of Douglas Elton Fairbanks, (1909-2000)WordNetWID-10965550-N-01-Fairbanks,falseWID-10965550-N-02-Douglas_Fairbanks_Jr.http://www.digitalhps.org/concepts/WID-10965550-N-02-Douglas_Fairbanks_Jr.http://www.digitalhps.org/concepts/WID-11146670-N-02-Douglas_MacArthurdouglas macarthurnounUnited States general who served as chief of staff and commanded Allied forces in the South Pacific during World War II; he accepted the surrender of Japan (1880-1964)WordNetWID-11146670-N-01-MacArthur,falseWID-11146670-N-02-Douglas_MacArthurhttp://www.digitalhps.org/concepts/WID-11146670-N-02-Douglas_MacArthurhttp://www.digitalhps.org/concepts/WID-11628678-N-01-douglas_firdouglas firnounstrong durable timber of a douglas firWordNetfalseWID-11628678-N-01-douglas_firhttp://www.digitalhps.org/concepts/WID-11628678-N-01-douglas_firhttp://www.digitalhps.org/concepts/WID-11628793-N-02-douglas_sprucedouglas sprucenounlofty douglas fir of northwestern North America having short needles and egg-shaped conesWordNetWID-11628793-N-01-green_douglas_fir,WID-11628793-N-03-douglas_pine,WID-11628793-N-04-douglas_hemlock,WID-11628793-N-05-Oregon_fir,WID-11628793-N-06-Oregon_pine,WID-11628793-N-07-Pseudotsuga_menziesii,falseWID-11628793-N-02-douglas_sprucehttp://www.digitalhps.org/concepts/WID-11628793-N-02-douglas_sprucehttp://www.digitalhps.org/concepts/WID-10965361-N-03-Douglas_Elton_Fairbanksdouglas elton fairbanksnounUnited States film actor noted for his swashbuckling roles (1883-1939)WordNetWID-10965361-N-01-Fairbanks,WID-10965361-N-02-Douglas_Fairbanks,WID-10965361-N-04-Julius_Ullman,falseWID-10965361-N-03-Douglas_Elton_Fairbankshttp://www.digitalhps.org/concepts/WID-10965361-N-03-Douglas_Elton_Fairbankshttp://www.digitalhps.org/concepts/WID-11628793-N-01-green_douglas_firgreen douglas firnounlofty douglas fir of northwestern North America having short needles and egg-shaped conesWordNetWID-11628793-N-02-douglas_spruce,WID-11628793-N-03-douglas_pine,WID-11628793-N-04-douglas_hemlock,WID-11628793-N-05-Oregon_fir,WID-11628793-N-06-Oregon_pine,WID-11628793-N-07-Pseudotsuga_menziesii,falseWID-11628793-N-01-green_douglas_firhttp://www.digitalhps.org/concepts/WID-11628793-N-01-green_douglas_firhttp://www.digitalhps.org/concepts/WID-10941206-N-02-Stephen_A._Douglasstephen a. douglasnounUnited States politician who proposed that individual territories be allowed to decide whether they would have slavery; he engaged in a famous series of debates with Abraham Lincoln (1813-1861)WordNetWID-10941206-N-01-Douglas,WID-10941206-N-03-Stephen_Arnold_Douglas,WID-10941206-N-04-Little_Giant,falseWID-10941206-N-02-Stephen_A._Douglashttp://www.digitalhps.org/concepts/WID-10941206-N-02-Stephen_A._Douglashttp://www.digitalhps.org/concepts/WID-10860444-N-03-Ray_Douglas_Bradburyray douglas bradburynounUnited States writer of science fiction (born 1920)WordNetWID-10860444-N-01-Bradbury,WID-10860444-N-02-Ray_Bradbury,falseWID-10860444-N-03-Ray_Douglas_Bradburyhttp://www.digitalhps.org/concepts/WID-10860444-N-03-Ray_Douglas_Bradburyhttp://www.digitalhps.org/concepts/WID-11628793-N-04-douglas_hemlockdouglas hemlocknounlofty douglas fir of northwestern North America having short needles and egg-shaped conesWordNetWID-11628793-N-01-green_douglas_fir,WID-11628793-N-02-douglas_spruce,WID-11628793-N-03-douglas_pine,WID-11628793-N-05-Oregon_fir,WID-11628793-N-06-Oregon_pine,WID-11628793-N-07-Pseudotsuga_menziesii,falseWID-11628793-N-04-douglas_hemlockhttp://www.digitalhps.org/concepts/WID-11628793-N-04-douglas_hemlockhttp://www.digitalhps.org/concepts/WID-11306297-N-03-Ian_Douglas_Smithian douglas smithnounRhodesian statesman who declared independence of Zimbabwe from Great Britain (born in 1919)WordNetWID-11306297-N-01-Smith,WID-11306297-N-02-Ian_Smith,falseWID-11306297-N-03-Ian_Douglas_Smithhttp://www.digitalhps.org/concepts/WID-11306297-N-03-Ian_Douglas_Smithhttp://www.digitalhps.org/concepts/CONe40a6b36-dbaa-46c7-96ea-2c6a1cb080a4Douglas WeinernounAmerican 20th century environmentalistVogonWeb Conceptstesthttp://viaf.org/viaf/283748929adminhttp://viaf.org/viaf/248802520[]falsehttp://www.digitalhps.org/concepts/http://www.digitalhps.org/concepts/CONe40a6b36-dbaa-46c7-96ea-2c6a1cb080a4http://www.digitalhps.org/concepts/WID-02357585-N-02-Douglas_squirreldouglas squirrelnounfar western United States counterpart of the red squirrelWordNetWID-02357585-N-01-chickeree,WID-02357585-N-03-Tamiasciurus_douglasi,falseWID-02357585-N-02-Douglas_squirrelhttp://www.digitalhps.org/concepts/WID-02357585-N-02-Douglas_squirrelhttp://www.digitalhps.org/concepts/WID-11190024-N-02-Douglas_Mooredouglas moorenounUnited States composer of works noted for their use of the American vernacular (1893-1969)WordNetWID-11190024-N-01-Moore,falseWID-11190024-N-02-Douglas_Moorehttp://www.digitalhps.org/concepts/WID-11190024-N-02-Douglas_Moorehttp://www.digitalhps.org/concepts/WID-11628793-N-03-douglas_pinedouglas pinenounlofty douglas fir of northwestern North America having short needles and egg-shaped conesWordNetWID-11628793-N-01-green_douglas_fir,WID-11628793-N-02-douglas_spruce,WID-11628793-N-04-douglas_hemlock,WID-11628793-N-05-Oregon_fir,WID-11628793-N-06-Oregon_pine,WID-11628793-N-07-Pseudotsuga_menziesii,falseWID-11628793-N-03-douglas_pinehttp://www.digitalhps.org/concepts/WID-11628793-N-03-douglas_pinehttp://www.digitalhps.org/concepts/WID-10941206-N-03-Stephen_Arnold_Douglasstephen arnold douglasnounUnited States politician who proposed that individual territories be allowed to decide whether they would have slavery; he engaged in a famous series of debates with Abraham Lincoln (1813-1861)WordNetWID-10941206-N-01-Douglas,WID-10941206-N-02-Stephen_A._Douglas,WID-10941206-N-04-Little_Giant,falseWID-10941206-N-03-Stephen_Arnold_Douglashttp://www.digitalhps.org/concepts/WID-10941206-N-03-Stephen_Arnold_Douglashttp://www.digitalhps.org/concepts/WID-11121876-N-03-Mary_Douglas_Leakeymary douglas leakeynounEnglish paleontologist (the wife of Louis Leakey) who discovered the Zinjanthropus skull that was 1,750,000 years old (1913-1996)WordNetWID-11121876-N-01-Leakey,WID-11121876-N-02-Mary_Leakey,falseWID-11121876-N-03-Mary_Douglas_Leakeyhttp://www.digitalhps.org/concepts/WID-11121876-N-03-Mary_Douglas_Leakey + diff --git a/Conceptpower+Spring/src/integration-test/resources/output/conceptLookUpWordNetEntry.json b/Conceptpower+Spring/src/integration-test/resources/output/conceptLookUpWordNetEntry.json new file mode 100644 index 000000000..d300a4253 --- /dev/null +++ b/Conceptpower+Spring/src/integration-test/resources/output/conceptLookUpWordNetEntry.json @@ -0,0 +1 @@ +{"conceptEntries":[{"id":"CONe40a6b36-dbaa-46c7-96ea-2c6a1cb080a4","lemma":"Douglas Weiner","pos":"noun","description":"American 20th century environmentalist","conceptList":"VogonWeb Concepts","deleted":false,"alternativeIds":[{"concept_id":"","concept_uri":"http://www.digitalhps.org/concepts/"},{"concept_id":"CONe40a6b36-dbaa-46c7-96ea-2c6a1cb080a4","concept_uri":"http://www.digitalhps.org/concepts/CONe40a6b36-dbaa-46c7-96ea-2c6a1cb080a4"}],"concept_uri":"http://www.digitalhps.org/concepts/CONe40a6b36-dbaa-46c7-96ea-2c6a1cb080a4","creator_id":"test","equal_to":"http://viaf.org/viaf/283748929","modified_by":"admin","similar_to":"http://viaf.org/viaf/248802520","synonym_ids":"[]","wordnet_id":""}],"pagination":null} \ No newline at end of file diff --git a/Conceptpower+Spring/src/integration-test/resources/output/conceptLookUpWordNetEntry.xml b/Conceptpower+Spring/src/integration-test/resources/output/conceptLookUpWordNetEntry.xml index 7fb1374e0..9f4d4ef0b 100644 --- a/Conceptpower+Spring/src/integration-test/resources/output/conceptLookUpWordNetEntry.xml +++ b/Conceptpower+Spring/src/integration-test/resources/output/conceptLookUpWordNetEntry.xml @@ -1 +1,2 @@ -http://www.digitalhps.org/concepts/CONe40a6b36-dbaa-46c7-96ea-2c6a1cb080a4Douglas WeinernounAmerican 20th century environmentalistVogonWeb Conceptstesthttp://viaf.org/viaf/283748929adminhttp://viaf.org/viaf/248802520[]false \ No newline at end of file +http://www.digitalhps.org/concepts/CONe40a6b36-dbaa-46c7-96ea-2c6a1cb080a4Douglas WeinernounAmerican 20th century environmentalistVogonWeb Conceptstesthttp://viaf.org/viaf/283748929adminhttp://viaf.org/viaf/248802520[]falsehttp://www.digitalhps.org/concepts/http://www.digitalhps.org/concepts/CONe40a6b36-dbaa-46c7-96ea-2c6a1cb080a4 + diff --git a/Conceptpower+Spring/src/integration-test/resources/output/conceptWithWordAndPos.json b/Conceptpower+Spring/src/integration-test/resources/output/conceptWithWordAndPos.json new file mode 100644 index 000000000..0260a7903 --- /dev/null +++ b/Conceptpower+Spring/src/integration-test/resources/output/conceptWithWordAndPos.json @@ -0,0 +1 @@ +{"conceptEntries":[{"id":"WID-10954498-N-01-Einstein","lemma":"einstein","pos":"noun","description":"physicist born in Germany who formulated the special theory of relativity and the general theory of relativity; Einstein also proposed that light consists of discrete quantized bundles of energy (later called photons) (1879-1955)","conceptList":"WordNet","deleted":false,"alternativeIds":[{"concept_id":"WID-10954498-N-01-Einstein","concept_uri":"http://www.digitalhps.org/concepts/WID-10954498-N-01-Einstein"}],"concept_uri":"http://www.digitalhps.org/concepts/WID-10954498-N-01-Einstein","creator_id":"","equal_to":"","modified_by":"","similar_to":"","synonym_ids":"WID-10954498-N-02-Albert_Einstein,","wordnet_id":"WID-10954498-N-01-Einstein"},{"id":"WID-10126926-N-05-Einstein","lemma":"einstein","pos":"noun","description":"someone who has exceptional intellectual ability and originality; \"Mozart was a child genius\"; \"he's smart but he's no Einstein\"","conceptList":"WordNet","deleted":false,"alternativeIds":[{"concept_id":"WID-10126926-N-05-Einstein","concept_uri":"http://www.digitalhps.org/concepts/WID-10126926-N-05-Einstein"}],"concept_uri":"http://www.digitalhps.org/concepts/WID-10126926-N-05-Einstein","creator_id":"","equal_to":"","modified_by":"","similar_to":"","synonym_ids":"WID-10126926-N-01-genius,WID-10126926-N-02-mastermind,WID-10126926-N-03-brain,WID-10126926-N-04-brainiac,","wordnet_id":"WID-10126926-N-05-Einstein"}],"pagination":{"pageNumber":1,"totalNumberOfRecords":4}} \ No newline at end of file diff --git a/Conceptpower+Spring/src/integration-test/resources/output/conceptWithWordAndPos.xml b/Conceptpower+Spring/src/integration-test/resources/output/conceptWithWordAndPos.xml index f81d5d1d4..fccc3628b 100644 --- a/Conceptpower+Spring/src/integration-test/resources/output/conceptWithWordAndPos.xml +++ b/Conceptpower+Spring/src/integration-test/resources/output/conceptWithWordAndPos.xml @@ -1 +1,2 @@ -http://www.digitalhps.org/concepts/WID-10954498-N-02-Albert_Einsteinalbert einsteinnounphysicist born in Germany who formulated the special theory of relativity and the general theory of relativity; Einstein also proposed that light consists of discrete quantized bundles of energy (later called photons) (1879-1955)WordNetWID-10954498-N-01-Einstein,falseWID-10954498-N-02-Albert_Einsteinhttp://www.digitalhps.org/concepts/WID-10954498-N-01-Einsteineinsteinnounphysicist born in Germany who formulated the special theory of relativity and the general theory of relativity; Einstein also proposed that light consists of discrete quantized bundles of energy (later called photons) (1879-1955)WordNetWID-10954498-N-02-Albert_Einstein,falseWID-10954498-N-01-Einsteinhttp://www.digitalhps.org/concepts/WID-05875723-N-01-Bose-Einstein_statisticsbose-einstein statisticsnoun(physics) statistical law obeyed by a system of particles whose wave function is not changed when two particles are interchanged (the Pauli exclusion principle does not apply)WordNetfalseWID-05875723-N-01-Bose-Einstein_statisticshttp://www.digitalhps.org/concepts/WID-10126926-N-05-Einsteineinsteinnounsomeone who has exceptional intellectual ability and originality; "Mozart was a child genius"; "he's smart but he's no Einstein"WordNetWID-10126926-N-01-genius,WID-10126926-N-02-mastermind,WID-10126926-N-03-brain,WID-10126926-N-04-brainiac,falseWID-10126926-N-05-Einstein \ No newline at end of file +http://www.digitalhps.org/concepts/WID-10954498-N-01-Einsteineinsteinnounphysicist born in Germany who formulated the special theory of relativity and the general theory of relativity; Einstein also proposed that light consists of discrete quantized bundles of energy (later called photons) (1879-1955)WordNetWID-10954498-N-02-Albert_Einstein,falseWID-10954498-N-01-Einsteinhttp://www.digitalhps.org/concepts/WID-10954498-N-01-Einsteinhttp://www.digitalhps.org/concepts/WID-10126926-N-05-Einsteineinsteinnounsomeone who has exceptional intellectual ability and originality; "Mozart was a child genius"; "he's smart but he's no Einstein"WordNetWID-10126926-N-01-genius,WID-10126926-N-02-mastermind,WID-10126926-N-03-brain,WID-10126926-N-04-brainiac,falseWID-10126926-N-05-Einsteinhttp://www.digitalhps.org/concepts/WID-10126926-N-05-Einstein + diff --git a/Conceptpower+Spring/src/integration-test/resources/output/conceptWithWordPosAndConceptList.json b/Conceptpower+Spring/src/integration-test/resources/output/conceptWithWordPosAndConceptList.json new file mode 100644 index 000000000..a2255d16d --- /dev/null +++ b/Conceptpower+Spring/src/integration-test/resources/output/conceptWithWordPosAndConceptList.json @@ -0,0 +1 @@ +{"conceptEntries":[{"id":"CONe40a6b36-dbaa-46c7-96ea-2c6a1cb080a4","lemma":"Douglas Weiner","pos":"noun","description":"American 20th century environmentalist","conceptList":"VogonWeb Concepts","deleted":false,"alternativeIds":[{"concept_id":"","concept_uri":"http://www.digitalhps.org/concepts/"},{"concept_id":"CONe40a6b36-dbaa-46c7-96ea-2c6a1cb080a4","concept_uri":"http://www.digitalhps.org/concepts/CONe40a6b36-dbaa-46c7-96ea-2c6a1cb080a4"}],"concept_uri":"http://www.digitalhps.org/concepts/CONe40a6b36-dbaa-46c7-96ea-2c6a1cb080a4","creator_id":"test","equal_to":"http://viaf.org/viaf/283748929","modified_by":"admin","similar_to":"http://viaf.org/viaf/248802520","synonym_ids":"[]","wordnet_id":""}],"pagination":{"pageNumber":1,"totalNumberOfRecords":1}} \ No newline at end of file diff --git a/Conceptpower+Spring/src/integration-test/resources/output/conceptWithWordPosAndDescription.json b/Conceptpower+Spring/src/integration-test/resources/output/conceptWithWordPosAndDescription.json new file mode 100644 index 000000000..a2255d16d --- /dev/null +++ b/Conceptpower+Spring/src/integration-test/resources/output/conceptWithWordPosAndDescription.json @@ -0,0 +1 @@ +{"conceptEntries":[{"id":"CONe40a6b36-dbaa-46c7-96ea-2c6a1cb080a4","lemma":"Douglas Weiner","pos":"noun","description":"American 20th century environmentalist","conceptList":"VogonWeb Concepts","deleted":false,"alternativeIds":[{"concept_id":"","concept_uri":"http://www.digitalhps.org/concepts/"},{"concept_id":"CONe40a6b36-dbaa-46c7-96ea-2c6a1cb080a4","concept_uri":"http://www.digitalhps.org/concepts/CONe40a6b36-dbaa-46c7-96ea-2c6a1cb080a4"}],"concept_uri":"http://www.digitalhps.org/concepts/CONe40a6b36-dbaa-46c7-96ea-2c6a1cb080a4","creator_id":"test","equal_to":"http://viaf.org/viaf/283748929","modified_by":"admin","similar_to":"http://viaf.org/viaf/248802520","synonym_ids":"[]","wordnet_id":""}],"pagination":{"pageNumber":1,"totalNumberOfRecords":1}} \ No newline at end of file diff --git a/Conceptpower+Spring/src/integration-test/resources/output/conceptWithWordPosAndDescription.xml b/Conceptpower+Spring/src/integration-test/resources/output/conceptWithWordPosAndDescription.xml index 7fb1374e0..318302591 100644 --- a/Conceptpower+Spring/src/integration-test/resources/output/conceptWithWordPosAndDescription.xml +++ b/Conceptpower+Spring/src/integration-test/resources/output/conceptWithWordPosAndDescription.xml @@ -1 +1,2 @@ -http://www.digitalhps.org/concepts/CONe40a6b36-dbaa-46c7-96ea-2c6a1cb080a4Douglas WeinernounAmerican 20th century environmentalistVogonWeb Conceptstesthttp://viaf.org/viaf/283748929adminhttp://viaf.org/viaf/248802520[]false \ No newline at end of file +http://www.digitalhps.org/concepts/CONe40a6b36-dbaa-46c7-96ea-2c6a1cb080a4Douglas WeinernounAmerican 20th century environmentalistVogonWeb Conceptstesthttp://viaf.org/viaf/283748929adminhttp://viaf.org/viaf/248802520[]falsehttp://www.digitalhps.org/concepts/http://www.digitalhps.org/concepts/CONe40a6b36-dbaa-46c7-96ea-2c6a1cb080a4 + diff --git a/Conceptpower+Spring/src/integration-test/resources/output/conceptWithWordPosAndEqualTo.json b/Conceptpower+Spring/src/integration-test/resources/output/conceptWithWordPosAndEqualTo.json new file mode 100644 index 000000000..0f58a52d0 --- /dev/null +++ b/Conceptpower+Spring/src/integration-test/resources/output/conceptWithWordPosAndEqualTo.json @@ -0,0 +1 @@ +{"conceptEntries":[{"id":"CONdf62c00c-f4a9-4564-9dd6-c9b955650f3a","lemma":"Abbott Henderson Thayer","pos":"noun","description":"American artist, naturalist and teacher. As a painter of portraits, figures, animals and landscapes, he enjoyed a certain prominence during his lifetime, and his paintings are represented in the major American art collections. He is perhaps best known for his 'angel' paintings, some of which use his children as models.","conceptList":"VogonWeb Concepts","deleted":false,"alternativeIds":[{"concept_id":"","concept_uri":"http://www.digitalhps.org/concepts/"},{"concept_id":"CONdf62c00c-f4a9-4564-9dd6-c9b955650f3a","concept_uri":"http://www.digitalhps.org/concepts/CONdf62c00c-f4a9-4564-9dd6-c9b955650f3a"}],"concept_uri":"http://www.digitalhps.org/concepts/CONdf62c00c-f4a9-4564-9dd6-c9b955650f3a","creator_id":"test","equal_to":"http://viaf.org/viaf/55043769","modified_by":"admin","similar_to":"","synonym_ids":"[]","wordnet_id":""}],"pagination":{"pageNumber":1,"totalNumberOfRecords":1}} \ No newline at end of file diff --git a/Conceptpower+Spring/src/integration-test/resources/output/conceptWithWordPosAndEqualTo.xml b/Conceptpower+Spring/src/integration-test/resources/output/conceptWithWordPosAndEqualTo.xml index e8ff15650..69e337628 100644 --- a/Conceptpower+Spring/src/integration-test/resources/output/conceptWithWordPosAndEqualTo.xml +++ b/Conceptpower+Spring/src/integration-test/resources/output/conceptWithWordPosAndEqualTo.xml @@ -1 +1,2 @@ -http://www.digitalhps.org/concepts/CONdf62c00c-f4a9-4564-9dd6-c9b955650f3aAbbott Henderson ThayernounAmerican artist, naturalist and teacher. As a painter of portraits, figures, animals and landscapes, he enjoyed a certain prominence during his lifetime, and his paintings are represented in the major American art collections. He is perhaps best known for his 'angel' paintings, some of which use his children as models.VogonWeb Conceptstesthttp://viaf.org/viaf/55043769admin[]false \ No newline at end of file +http://www.digitalhps.org/concepts/CONdf62c00c-f4a9-4564-9dd6-c9b955650f3aAbbott Henderson ThayernounAmerican artist, naturalist and teacher. As a painter of portraits, figures, animals and landscapes, he enjoyed a certain prominence during his lifetime, and his paintings are represented in the major American art collections. He is perhaps best known for his 'angel' paintings, some of which use his children as models.VogonWeb Conceptstesthttp://viaf.org/viaf/55043769admin[]falsehttp://www.digitalhps.org/concepts/http://www.digitalhps.org/concepts/CONdf62c00c-f4a9-4564-9dd6-c9b955650f3a + diff --git a/Conceptpower+Spring/src/integration-test/resources/output/conceptWithWordPosAndPagination1.json b/Conceptpower+Spring/src/integration-test/resources/output/conceptWithWordPosAndPagination1.json new file mode 100644 index 000000000..0260a7903 --- /dev/null +++ b/Conceptpower+Spring/src/integration-test/resources/output/conceptWithWordPosAndPagination1.json @@ -0,0 +1 @@ +{"conceptEntries":[{"id":"WID-10954498-N-01-Einstein","lemma":"einstein","pos":"noun","description":"physicist born in Germany who formulated the special theory of relativity and the general theory of relativity; Einstein also proposed that light consists of discrete quantized bundles of energy (later called photons) (1879-1955)","conceptList":"WordNet","deleted":false,"alternativeIds":[{"concept_id":"WID-10954498-N-01-Einstein","concept_uri":"http://www.digitalhps.org/concepts/WID-10954498-N-01-Einstein"}],"concept_uri":"http://www.digitalhps.org/concepts/WID-10954498-N-01-Einstein","creator_id":"","equal_to":"","modified_by":"","similar_to":"","synonym_ids":"WID-10954498-N-02-Albert_Einstein,","wordnet_id":"WID-10954498-N-01-Einstein"},{"id":"WID-10126926-N-05-Einstein","lemma":"einstein","pos":"noun","description":"someone who has exceptional intellectual ability and originality; \"Mozart was a child genius\"; \"he's smart but he's no Einstein\"","conceptList":"WordNet","deleted":false,"alternativeIds":[{"concept_id":"WID-10126926-N-05-Einstein","concept_uri":"http://www.digitalhps.org/concepts/WID-10126926-N-05-Einstein"}],"concept_uri":"http://www.digitalhps.org/concepts/WID-10126926-N-05-Einstein","creator_id":"","equal_to":"","modified_by":"","similar_to":"","synonym_ids":"WID-10126926-N-01-genius,WID-10126926-N-02-mastermind,WID-10126926-N-03-brain,WID-10126926-N-04-brainiac,","wordnet_id":"WID-10126926-N-05-Einstein"}],"pagination":{"pageNumber":1,"totalNumberOfRecords":4}} \ No newline at end of file diff --git a/Conceptpower+Spring/src/integration-test/resources/output/conceptWithWordPosAndPagination1.xml b/Conceptpower+Spring/src/integration-test/resources/output/conceptWithWordPosAndPagination1.xml new file mode 100644 index 000000000..3b9b199f8 --- /dev/null +++ b/Conceptpower+Spring/src/integration-test/resources/output/conceptWithWordPosAndPagination1.xml @@ -0,0 +1 @@ +http://www.digitalhps.org/concepts/WID-10954498-N-01-Einsteineinsteinnounphysicist born in Germany who formulated the special theory of relativity and the general theory of relativity; Einstein also proposed that light consists of discrete quantized bundles of energy (later called photons) (1879-1955)WordNetWID-10954498-N-02-Albert_Einstein,falseWID-10954498-N-01-Einsteinhttp://www.digitalhps.org/concepts/WID-10954498-N-01-Einsteinhttp://www.digitalhps.org/concepts/WID-10126926-N-05-Einsteineinsteinnounsomeone who has exceptional intellectual ability and originality; "Mozart was a child genius"; "he's smart but he's no Einstein"WordNetWID-10126926-N-01-genius,WID-10126926-N-02-mastermind,WID-10126926-N-03-brain,WID-10126926-N-04-brainiac,falseWID-10126926-N-05-Einsteinhttp://www.digitalhps.org/concepts/WID-10126926-N-05-Einstein \ No newline at end of file diff --git a/Conceptpower+Spring/src/integration-test/resources/output/conceptWithWordPosAndPagination2.json b/Conceptpower+Spring/src/integration-test/resources/output/conceptWithWordPosAndPagination2.json new file mode 100644 index 000000000..71afb64c4 --- /dev/null +++ b/Conceptpower+Spring/src/integration-test/resources/output/conceptWithWordPosAndPagination2.json @@ -0,0 +1 @@ +{"conceptEntries":[{"id":"WID-10954498-N-02-Albert_Einstein","lemma":"albert einstein","pos":"noun","description":"physicist born in Germany who formulated the special theory of relativity and the general theory of relativity; Einstein also proposed that light consists of discrete quantized bundles of energy (later called photons) (1879-1955)","conceptList":"WordNet","deleted":false,"alternativeIds":[{"concept_id":"WID-10954498-N-02-Albert_Einstein","concept_uri":"http://www.digitalhps.org/concepts/WID-10954498-N-02-Albert_Einstein"}],"concept_uri":"http://www.digitalhps.org/concepts/WID-10954498-N-02-Albert_Einstein","creator_id":"","equal_to":"","modified_by":"","similar_to":"","synonym_ids":"WID-10954498-N-01-Einstein,","wordnet_id":"WID-10954498-N-02-Albert_Einstein"},{"id":"WID-05875723-N-01-Bose-Einstein_statistics","lemma":"bose-einstein statistics","pos":"noun","description":"(physics) statistical law obeyed by a system of particles whose wave function is not changed when two particles are interchanged (the Pauli exclusion principle does not apply)","conceptList":"WordNet","deleted":false,"alternativeIds":[{"concept_id":"WID-05875723-N-01-Bose-Einstein_statistics","concept_uri":"http://www.digitalhps.org/concepts/WID-05875723-N-01-Bose-Einstein_statistics"}],"concept_uri":"http://www.digitalhps.org/concepts/WID-05875723-N-01-Bose-Einstein_statistics","creator_id":"","equal_to":"","modified_by":"","similar_to":"","synonym_ids":"","wordnet_id":"WID-05875723-N-01-Bose-Einstein_statistics"}],"pagination":{"pageNumber":2,"totalNumberOfRecords":4}} \ No newline at end of file diff --git a/Conceptpower+Spring/src/integration-test/resources/output/conceptWithWordPosAndPagination2.xml b/Conceptpower+Spring/src/integration-test/resources/output/conceptWithWordPosAndPagination2.xml new file mode 100644 index 000000000..dc2e32e8d --- /dev/null +++ b/Conceptpower+Spring/src/integration-test/resources/output/conceptWithWordPosAndPagination2.xml @@ -0,0 +1 @@ +http://www.digitalhps.org/concepts/WID-10954498-N-02-Albert_Einsteinalbert einsteinnounphysicist born in Germany who formulated the special theory of relativity and the general theory of relativity; Einstein also proposed that light consists of discrete quantized bundles of energy (later called photons) (1879-1955)WordNetWID-10954498-N-01-Einstein,falseWID-10954498-N-02-Albert_Einsteinhttp://www.digitalhps.org/concepts/WID-10954498-N-02-Albert_Einsteinhttp://www.digitalhps.org/concepts/WID-05875723-N-01-Bose-Einstein_statisticsbose-einstein statisticsnoun(physics) statistical law obeyed by a system of particles whose wave function is not changed when two particles are interchanged (the Pauli exclusion principle does not apply)WordNetfalseWID-05875723-N-01-Bose-Einstein_statisticshttp://www.digitalhps.org/concepts/WID-05875723-N-01-Bose-Einstein_statistics \ No newline at end of file diff --git a/Conceptpower+Spring/src/integration-test/resources/output/conceptWithWordPosAndSimilarTo.json b/Conceptpower+Spring/src/integration-test/resources/output/conceptWithWordPosAndSimilarTo.json new file mode 100644 index 000000000..a2255d16d --- /dev/null +++ b/Conceptpower+Spring/src/integration-test/resources/output/conceptWithWordPosAndSimilarTo.json @@ -0,0 +1 @@ +{"conceptEntries":[{"id":"CONe40a6b36-dbaa-46c7-96ea-2c6a1cb080a4","lemma":"Douglas Weiner","pos":"noun","description":"American 20th century environmentalist","conceptList":"VogonWeb Concepts","deleted":false,"alternativeIds":[{"concept_id":"","concept_uri":"http://www.digitalhps.org/concepts/"},{"concept_id":"CONe40a6b36-dbaa-46c7-96ea-2c6a1cb080a4","concept_uri":"http://www.digitalhps.org/concepts/CONe40a6b36-dbaa-46c7-96ea-2c6a1cb080a4"}],"concept_uri":"http://www.digitalhps.org/concepts/CONe40a6b36-dbaa-46c7-96ea-2c6a1cb080a4","creator_id":"test","equal_to":"http://viaf.org/viaf/283748929","modified_by":"admin","similar_to":"http://viaf.org/viaf/248802520","synonym_ids":"[]","wordnet_id":""}],"pagination":{"pageNumber":1,"totalNumberOfRecords":1}} \ No newline at end of file diff --git a/Conceptpower+Spring/src/integration-test/resources/output/conceptWithWordPosAndSimilarTo.xml b/Conceptpower+Spring/src/integration-test/resources/output/conceptWithWordPosAndSimilarTo.xml index a340ee186..318302591 100644 --- a/Conceptpower+Spring/src/integration-test/resources/output/conceptWithWordPosAndSimilarTo.xml +++ b/Conceptpower+Spring/src/integration-test/resources/output/conceptWithWordPosAndSimilarTo.xml @@ -1 +1,2 @@ -http://www.digitalhps.org/concepts/CONe40a6b36-dbaa-46c7-96ea-2c6a1cb080a4DouglasNOUNAmerican 20th century environmentalistVogonWeb Conceptsadminadminhttp://viaf.org/viaf/248802520[]E21 Personfalse \ No newline at end of file +http://www.digitalhps.org/concepts/CONe40a6b36-dbaa-46c7-96ea-2c6a1cb080a4Douglas WeinernounAmerican 20th century environmentalistVogonWeb Conceptstesthttp://viaf.org/viaf/283748929adminhttp://viaf.org/viaf/248802520[]falsehttp://www.digitalhps.org/concepts/http://www.digitalhps.org/concepts/CONe40a6b36-dbaa-46c7-96ea-2c6a1cb080a4 + diff --git a/Conceptpower+Spring/src/integration-test/resources/output/conceptWithWordPosAndTypeId.json b/Conceptpower+Spring/src/integration-test/resources/output/conceptWithWordPosAndTypeId.json new file mode 100644 index 000000000..5343da19b --- /dev/null +++ b/Conceptpower+Spring/src/integration-test/resources/output/conceptWithWordPosAndTypeId.json @@ -0,0 +1 @@ +{"conceptEntries":[{"id":"CONf1b4b733-3994-458d-bea0-3fbc2110dc69","lemma":"Almira Hart Lincoln Phelps","pos":"noun","description":"American educator and author, particularly in the fields of botany, chemistry, and geology (1793-1884)","conceptList":"VogonWeb Concepts","type":{"type_id":"986a7cc9-c0c1-4720-b344-853f08c136ab","type_uri":"http://www.digitalhps.org/types/TYPE_986a7cc9-c0c1-4720-b344-853f08c136ab","type_name":"E21 Person"},"deleted":false,"alternativeIds":[{"concept_id":"","concept_uri":"http://www.digitalhps.org/concepts/"},{"concept_id":"CONf1b4b733-3994-458d-bea0-3fbc2110dc69","concept_uri":"http://www.digitalhps.org/concepts/CONf1b4b733-3994-458d-bea0-3fbc2110dc69"}],"concept_uri":"http://www.digitalhps.org/concepts/CONf1b4b733-3994-458d-bea0-3fbc2110dc69","creator_id":"test","equal_to":"","modified_by":"admin","similar_to":"","synonym_ids":"[]","wordnet_id":""}],"pagination":{"pageNumber":1,"totalNumberOfRecords":1}} \ No newline at end of file diff --git a/Conceptpower+Spring/src/integration-test/resources/output/conceptWithWordPosAndTypeId.xml b/Conceptpower+Spring/src/integration-test/resources/output/conceptWithWordPosAndTypeId.xml index 0e0d91417..826ac42e3 100644 --- a/Conceptpower+Spring/src/integration-test/resources/output/conceptWithWordPosAndTypeId.xml +++ b/Conceptpower+Spring/src/integration-test/resources/output/conceptWithWordPosAndTypeId.xml @@ -1 +1,2 @@ -http://www.digitalhps.org/concepts/CONf1b4b733-3994-458d-bea0-3fbc2110dc69Almira Hart Lincoln PhelpsnounAmerican educator and author, particularly in the fields of botany, chemistry, and geology (1793-1884)VogonWeb Conceptstestadmin[]E21 Personfalse \ No newline at end of file +http://www.digitalhps.org/concepts/CONf1b4b733-3994-458d-bea0-3fbc2110dc69Almira Hart Lincoln PhelpsnounAmerican educator and author, particularly in the fields of botany, chemistry, and geology (1793-1884)VogonWeb Conceptstestadmin[]E21 Personfalsehttp://www.digitalhps.org/concepts/http://www.digitalhps.org/concepts/CONf1b4b733-3994-458d-bea0-3fbc2110dc69 + diff --git a/Conceptpower+Spring/src/integration-test/resources/output/conceptWithWordPosAndTypeUri.json b/Conceptpower+Spring/src/integration-test/resources/output/conceptWithWordPosAndTypeUri.json new file mode 100644 index 000000000..5343da19b --- /dev/null +++ b/Conceptpower+Spring/src/integration-test/resources/output/conceptWithWordPosAndTypeUri.json @@ -0,0 +1 @@ +{"conceptEntries":[{"id":"CONf1b4b733-3994-458d-bea0-3fbc2110dc69","lemma":"Almira Hart Lincoln Phelps","pos":"noun","description":"American educator and author, particularly in the fields of botany, chemistry, and geology (1793-1884)","conceptList":"VogonWeb Concepts","type":{"type_id":"986a7cc9-c0c1-4720-b344-853f08c136ab","type_uri":"http://www.digitalhps.org/types/TYPE_986a7cc9-c0c1-4720-b344-853f08c136ab","type_name":"E21 Person"},"deleted":false,"alternativeIds":[{"concept_id":"","concept_uri":"http://www.digitalhps.org/concepts/"},{"concept_id":"CONf1b4b733-3994-458d-bea0-3fbc2110dc69","concept_uri":"http://www.digitalhps.org/concepts/CONf1b4b733-3994-458d-bea0-3fbc2110dc69"}],"concept_uri":"http://www.digitalhps.org/concepts/CONf1b4b733-3994-458d-bea0-3fbc2110dc69","creator_id":"test","equal_to":"","modified_by":"admin","similar_to":"","synonym_ids":"[]","wordnet_id":""}],"pagination":{"pageNumber":1,"totalNumberOfRecords":1}} \ No newline at end of file diff --git a/Conceptpower+Spring/src/integration-test/resources/output/conceptWithWordPosAndTypeUri.xml b/Conceptpower+Spring/src/integration-test/resources/output/conceptWithWordPosAndTypeUri.xml index 1bc30facf..826ac42e3 100644 --- a/Conceptpower+Spring/src/integration-test/resources/output/conceptWithWordPosAndTypeUri.xml +++ b/Conceptpower+Spring/src/integration-test/resources/output/conceptWithWordPosAndTypeUri.xml @@ -1 +1,2 @@ -http://www.digitalhps.org/concepts/WID-13750415-N-02-100100nounten 10sWordNetWID-13750415-N-01-hundred,WID-13750415-N-03-C,WID-13750415-N-04-century,WID-13750415-N-05-one_C,falseWID-13750415-N-02-100http://www.digitalhps.org/concepts/WID-08641944-N-01-'hood'hoodnoun(slang) a neighborhoodWordNetfalseWID-08641944-N-01-'hoodhttp://www.digitalhps.org/concepts/WID-13742358-N-02-00nouna mathematical element that when added to another number yields the same numberWordNetWID-13742358-N-01-zero,WID-13742358-N-03-nought,WID-13742358-N-04-cipher,WID-13742358-N-05-cypher,falseWID-13742358-N-02-0http://www.digitalhps.org/concepts/WID-13742573-N-02-11nounthe smallest whole number or a numeral representing this number; "he has the one but will need a two and three to go with it"; "they had lunch at one"WordNetWID-13742573-N-01-one,WID-13742573-N-03-I,WID-13742573-N-04-ace,WID-13742573-N-05-single,WID-13742573-N-06-unity,falseWID-13742573-N-02-1http://www.digitalhps.org/concepts/WID-08950407-N-02-'s_Gravenhage's gravenhagenounthe site of the royal residence and the de facto capital in the western part of the Netherlands; seat of the International Court of JusticeWordNetWID-08950407-N-01-The_Hague,WID-08950407-N-03-Den_Haag,falseWID-08950407-N-02-'s_Gravenhagehttp://www.digitalhps.org/concepts/WID-13746512-N-02-1010nounthe cardinal number that is the sum of nine and one; the base of the decimal systemWordNetWID-13746512-N-01-ten,WID-13746512-N-03-X,WID-13746512-N-04-tenner,WID-13746512-N-05-decade,falseWID-13746512-N-02-10http://www.digitalhps.org/concepts/WID-14930670-N-02-1-dodecanol1-dodecanolnouna colorless insoluble solid alcohol used to make detergents and pharmaceuticalsWordNetWID-14930670-N-01-lauryl_alcohol,falseWID-14930670-N-02-1-dodecanolhttp://www.digitalhps.org/concepts/WID-04502851-N-02-.22.22nouna .22 caliber firearm (pistol or rifle)WordNetWID-04502851-N-01-twenty-two,falseWID-04502851-N-02-.22http://www.digitalhps.org/concepts/CONf1b4b733-3994-458d-bea0-3fbc2110dc69Almira Hart Lincoln PhelpsnounAmerican educator and author, particularly in the fields of botany, chemistry, and geology (1793-1884)VogonWeb Conceptstestadmin[]E21 Personfalsehttp://www.digitalhps.org/concepts/WID-00475142-N-02-1-hitter1-hitternouna game in which a pitcher allows the opposing team only one hitWordNetWID-00475142-N-01-one-hitter,falseWID-00475142-N-02-1-hitter \ No newline at end of file +http://www.digitalhps.org/concepts/CONf1b4b733-3994-458d-bea0-3fbc2110dc69Almira Hart Lincoln PhelpsnounAmerican educator and author, particularly in the fields of botany, chemistry, and geology (1793-1884)VogonWeb Conceptstestadmin[]E21 Personfalsehttp://www.digitalhps.org/concepts/http://www.digitalhps.org/concepts/CONf1b4b733-3994-458d-bea0-3fbc2110dc69 + diff --git a/Conceptpower+Spring/src/integration-test/resources/output/conceptWrapper.json b/Conceptpower+Spring/src/integration-test/resources/output/conceptWrapper.json new file mode 100644 index 000000000..a19ef3843 --- /dev/null +++ b/Conceptpower+Spring/src/integration-test/resources/output/conceptWrapper.json @@ -0,0 +1 @@ +{"conceptEntries":[{"id":"CONe7fbf694-5609-4691-bca8-916526c2ba6a","lemma":"Alfred Benninghoff","pos":"noun","description":"German anatomist (1890-1953)","conceptList":"VogonWeb Concepts","deleted":false,"alternativeIds":[{"concept_id":"","concept_uri":"http://www.digitalhps.org/concepts/"},{"concept_id":"CONe7fbf694-5609-4691-bca8-916526c2ba6a","concept_uri":"http://www.digitalhps.org/concepts/CONe7fbf694-5609-4691-bca8-916526c2ba6a"}],"concept_uri":"http://www.digitalhps.org/concepts/CONe7fbf694-5609-4691-bca8-916526c2ba6a","creator_id":"admin","equal_to":"","modified_by":"admin","similar_to":"","synonym_ids":"[],","wordnet_id":""}],"pagination":null} \ No newline at end of file diff --git a/Conceptpower+Spring/src/integration-test/resources/output/conceptWrapper.xml b/Conceptpower+Spring/src/integration-test/resources/output/conceptWrapper.xml index a6b8752e6..950909b3c 100644 --- a/Conceptpower+Spring/src/integration-test/resources/output/conceptWrapper.xml +++ b/Conceptpower+Spring/src/integration-test/resources/output/conceptWrapper.xml @@ -1 +1,2 @@ -http://www.digitalhps.org/concepts/CONe7fbf694-5609-4691-bca8-916526c2ba6aAlfred BenninghoffnounGerman anatomist (1890-1953)VogonWeb Conceptstestadmin[],false \ No newline at end of file +http://www.digitalhps.org/concepts/CONe7fbf694-5609-4691-bca8-916526c2ba6aAlfred BenninghoffnounGerman anatomist (1890-1953)VogonWeb Conceptsadminadmin[],falsehttp://www.digitalhps.org/concepts/http://www.digitalhps.org/concepts/CONe7fbf694-5609-4691-bca8-916526c2ba6a + diff --git a/Conceptpower+Spring/src/integration-test/resources/output/noResults.xml b/Conceptpower+Spring/src/integration-test/resources/output/noResults.xml index fcf35af83..f86afb069 100644 --- a/Conceptpower+Spring/src/integration-test/resources/output/noResults.xml +++ b/Conceptpower+Spring/src/integration-test/resources/output/noResults.xml @@ -1 +1,2 @@ -http://www.digitalhps.org/concepts/CONda6f194d-8f01-4e5e-9e8e-6bb1949375b0Adolf MeyernounGerman psychiatrist, first psychiatrist-in-chief at Johns Hopkins Hospital (1866-1950)VogonWeb Conceptstest[][][]E21 Personfalsehttp://www.digitalhps.org/concepts/CONb7030bb1-4e78-4770-8e10-23cc2a19d027Askania-NovanounA biosphere reserve located in Kherson Oblast, UkraineVogonWeb Conceptstest[][][]E53 Placefalsehttp://www.digitalhps.org/concepts/CONcb2d55e0-30d7-43b6-bbc6-f44ec4b7fb50Adam SmithnounScottish writer and philosopher (1723-1790)VogonWeb Conceptstest[][][]E21 Personfalsehttp://www.digitalhps.org/concepts/CON1727a923-8fef-4f7d-a004-542c843dd257Adolf NaefnounSwiss zoologist and paleontologist (1883-1949)VogonWeb Conceptstest[][][]E21 Personfalsehttp://www.digitalhps.org/concepts/CONcd762d4b-1aef-43d0-87af-ec33945e3d13Abd Allah ibn al-TayyibnounPersian doctor, philosopher, and monk (980-1043)VogonWeb Conceptstest[][][]E21 Personfalsehttp://www.digitalhps.org/concepts/CONe9616377-7fa1-4c01-8b62-0978c6d551bcAskania-NovanounA biosphere reserve located in Kherson Oblast, UkraineVogonWeb Conceptstest[][][]E53 Placefalsehttp://www.digitalhps.org/concepts/CON481d0042-6906-4b50-85f3-079357379d11Adolf RemanenounGerman zoologist (1898-1976)VogonWeb Conceptstest[][][]E21 Personfalsehttp://www.digitalhps.org/concepts/CONa52a3bef-fab5-4e17-99cf-78c4b993291aAdelaide LewisnounMother of embryologist Warren Harmon LewisVogonWeb Conceptstest[][][]E21 Personfalsehttp://www.digitalhps.org/concepts/CON27334c60-a844-43f2-84a9-f29eab0088c2Adolf LorenznounAustrian orthopedic surgeon (1854-1946)VogonWeb Conceptstest[][][]E21 Personfalsehttp://www.digitalhps.org/concepts/WID-11105945-N-03-Gustav_Robert_Kirchhoffgustav robert kirchhoffnounGerman physicist who with Bunsen pioneered spectrum analysis and formulated two laws governing electric networks (1824-1887)WordNetWID-11105945-N-01-Kirchhoff,WID-11105945-N-02-G._R._Kirchhoff,falseWID-11105945-N-03-Gustav_Robert_Kirchhoff \ No newline at end of file + + diff --git a/Conceptpower+Spring/src/integration-test/resources/output/synonym.json b/Conceptpower+Spring/src/integration-test/resources/output/synonym.json new file mode 100644 index 000000000..c280f6b8d --- /dev/null +++ b/Conceptpower+Spring/src/integration-test/resources/output/synonym.json @@ -0,0 +1 @@ +{"conceptEntries":[{"id":"WID-02382039-N-01-cayuse","lemma":"cayuse","pos":"NOUN","description":"a small native range horse","conceptList":"WordNet","deleted":false,"alternativeIds":[{"concept_id":"WID-02382039-N-01-cayuse","concept_uri":"http://www.digitalhps.org/concepts/WID-02382039-N-01-cayuse"}],"concept_uri":"http://www.digitalhps.org/concepts/WID-02382039-N-01-cayuse","creator_id":"","equal_to":"","modified_by":"","similar_to":"","synonym_ids":"WID-02382039-N-02-Indian_pony,","wordnet_id":"WID-02382039-N-01-cayuse"}],"pagination":null} \ No newline at end of file diff --git a/Conceptpower+Spring/src/integration-test/resources/output/synonym.xml b/Conceptpower+Spring/src/integration-test/resources/output/synonym.xml index ab1955d2b..b971961c5 100644 --- a/Conceptpower+Spring/src/integration-test/resources/output/synonym.xml +++ b/Conceptpower+Spring/src/integration-test/resources/output/synonym.xml @@ -1 +1,2 @@ -http://www.digitalhps.org/concepts/WID-02382039-N-01-cayusecayuseNOUNa small native range horseWordNetWID-02382039-N-02-Indian_pony,falseWID-02382039-N-01-cayuse \ No newline at end of file +http://www.digitalhps.org/concepts/WID-02382039-N-01-cayusecayuseNOUNa small native range horseWordNetWID-02382039-N-02-Indian_pony,falseWID-02382039-N-01-cayusehttp://www.digitalhps.org/concepts/WID-02382039-N-01-cayuse + diff --git a/Conceptpower+Spring/src/integration-test/resources/output/types.json b/Conceptpower+Spring/src/integration-test/resources/output/types.json new file mode 100644 index 000000000..0aea07137 --- /dev/null +++ b/Conceptpower+Spring/src/integration-test/resources/output/types.json @@ -0,0 +1 @@ +{"description":"This class comprises real persons who live or are assumed to have lived. \r\nLegendary figures that may have existed, such as Ulysses and King Arthur, fall into this class \r\nif the documentation refers to them as historical figures. In cases where doubt exists as to \r\nwhether several persons are in fact identical, multiple instances can be created and linked to \r\nindicate their relationship. The CRM does not propose a specific form to support reasoning \r\nabout possible identity. \r\nExamples: \r\nƒ Tut-Ankh-Amun \r\nƒ Nelson Mandela","matches":"http://purl.org/NET/cidoc-crm/core#E21_Person","superType":{"type_id":"01054126-b6ec-4d31-9b7f-7bc6738eb79a","type_uri":"http://www.digitalhps.org/types/TYPE_01054126-b6ec-4d31-9b7f-7bc6738eb79a","type_name":"E20 Biological Object"},"type_id":"986a7cc9-c0c1-4720-b344-853f08c136ab","type_uri":"http://www.digitalhps.org/types/TYPE_986a7cc9-c0c1-4720-b344-853f08c136ab","creator_id":"jdamerow","modified_by":""} \ No newline at end of file diff --git a/Conceptpower+Spring/src/integration-test/resources/output/wordNetConcept.json b/Conceptpower+Spring/src/integration-test/resources/output/wordNetConcept.json new file mode 100644 index 000000000..82e9f6bf7 --- /dev/null +++ b/Conceptpower+Spring/src/integration-test/resources/output/wordNetConcept.json @@ -0,0 +1 @@ +{"conceptEntries":[{"id":"WID-02380464-N-01-polo_pony","lemma":"polo pony","pos":"NOUN","description":"a small agile horse specially bred and trained for playing polo","conceptList":"WordNet","deleted":false,"alternativeIds":[{"concept_id":"WID-02380464-N-01-polo_pony","concept_uri":"http://www.digitalhps.org/concepts/WID-02380464-N-01-polo_pony"}],"concept_uri":"http://www.digitalhps.org/concepts/WID-02380464-N-01-polo_pony","creator_id":"","equal_to":"","modified_by":"","similar_to":"","synonym_ids":"","wordnet_id":"WID-02380464-N-01-polo_pony"}],"pagination":null} \ No newline at end of file diff --git a/Conceptpower+Spring/src/integration-test/resources/output/wordNetConcept.xml b/Conceptpower+Spring/src/integration-test/resources/output/wordNetConcept.xml index 23d2ec5e5..ed9806b01 100644 --- a/Conceptpower+Spring/src/integration-test/resources/output/wordNetConcept.xml +++ b/Conceptpower+Spring/src/integration-test/resources/output/wordNetConcept.xml @@ -1 +1,2 @@ -http://www.digitalhps.org/concepts/WID-02380464-N-01-polo_ponypolo_ponyNOUNa small agile horse specially bred and trained for playing poloWordNetfalseWID-02380464-N-01-polo_pony \ No newline at end of file +http://www.digitalhps.org/concepts/WID-02380464-N-01-polo_ponypolo ponyNOUNa small agile horse specially bred and trained for playing poloWordNetfalseWID-02380464-N-01-polo_ponyhttp://www.digitalhps.org/concepts/WID-02380464-N-01-polo_pony + diff --git a/Conceptpower+Spring/src/integration-test/resources/test.properties b/Conceptpower+Spring/src/integration-test/resources/test.properties index d9ef4076d..86cb56e5d 100644 --- a/Conceptpower+Spring/src/integration-test/resources/test.properties +++ b/Conceptpower+Spring/src/integration-test/resources/test.properties @@ -1,4 +1,3 @@ -#lucenePath=/Users/karthikeyanmohan/Software/conceptpower-test/indexFiles lucenePath=${lucene.path} dbTestPath=${db.path} wordnetPath=${wordnet.install.path} diff --git a/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/bean/ConceptEditBean.java b/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/app/bean/ConceptEditBean.java similarity index 94% rename from Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/bean/ConceptEditBean.java rename to Conceptpower+Spring/src/main/java/edu/asu/conceptpower/app/bean/ConceptEditBean.java index 1d66508fa..15c146037 100644 --- a/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/bean/ConceptEditBean.java +++ b/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/app/bean/ConceptEditBean.java @@ -1,4 +1,4 @@ -package edu.asu.conceptpower.servlet.bean; +package edu.asu.conceptpower.app.bean; import java.util.LinkedHashMap; import java.util.List; @@ -6,8 +6,8 @@ import org.springframework.stereotype.Component; +import edu.asu.conceptpower.app.core.POS; import edu.asu.conceptpower.core.ConceptType; -import edu.asu.conceptpower.servlet.core.POS; @Component public class ConceptEditBean { @@ -32,6 +32,7 @@ public class ConceptEditBean { private List conceptEntryList; private boolean fromHomeScreen; private String luceneError; + private String wordnetIds; public String getConcept() { return concept; @@ -196,4 +197,12 @@ public String getLuceneError() { public void setLuceneError(String luceneError) { this.luceneError = luceneError; } + + public String getWordnetIds() { + return wordnetIds; + } + + public void setWordnetIds(String wordnetIds) { + this.wordnetIds = wordnetIds; + } } diff --git a/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/app/bean/ConceptsMergeBean.java b/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/app/bean/ConceptsMergeBean.java new file mode 100644 index 000000000..5b9beaf1a --- /dev/null +++ b/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/app/bean/ConceptsMergeBean.java @@ -0,0 +1,143 @@ +package edu.asu.conceptpower.app.bean; + +import java.util.ArrayList; +import java.util.HashSet; +import java.util.List; +import java.util.Set; + +import edu.asu.conceptpower.app.error.CPError; + +public class ConceptsMergeBean { + + private String selectedPosValue; + private String selectedListName; + private String selectedTypeId; + private String selectedTypeName; + private String selectedConceptId; + private List descriptions = new ArrayList<>(); + private Set synonymsids = new HashSet<>(); + private Set equalsValues = new HashSet<>(); + private Set similarValues = new HashSet<>(); + private Set mergeIds = new HashSet<>(); + private String word; + private List errorMessages = new ArrayList<>(); + private Set alternativeIds = new HashSet<>(); + + public String getSelectedPosValue() { + return selectedPosValue; + } + + public void setSelectedPosValue(String selectedPosValue) { + this.selectedPosValue = selectedPosValue; + } + + public String getSelectedListName() { + return selectedListName; + } + + public void setSelectedListName(String selectedListName) { + this.selectedListName = selectedListName; + } + + public String getSelectedTypeId() { + return selectedTypeId; + } + + public void setSelectedTypeId(String selectedTypeId) { + this.selectedTypeId = selectedTypeId; + } + + public String getSelectedTypeName() { + return selectedTypeName; + } + + public void setSelectedTypeName(String selectedTypeName) { + this.selectedTypeName = selectedTypeName; + } + + public String getSelectedConceptId() { + if (selectedConceptId == null) { + return ""; + } + return selectedConceptId; + } + + public void setSelectedConceptId(String selectedConceptId) { + this.selectedConceptId = selectedConceptId; + } + + public Set getSynonymsids() { + return synonymsids; + } + + public void setSynonymsids(Set synonymsids) { + this.synonymsids = synonymsids; + } + + + public Set getEqualsValues() { + return equalsValues; + } + + public void setEqualsValues(Set equalsValues) { + this.equalsValues = equalsValues; + } + + public Set getSimilarValues() { + return similarValues; + } + + public void setSimilarValues(Set similarValues) { + this.similarValues = similarValues; + } + + public String getWord() { + return word; + } + + public void setWord(String word) { + this.word = word; + } + + public void clear() { + this.getSynonymsids().clear(); + this.getEqualsValues().clear(); + this.getSimilarValues().clear(); + this.mergeIds.clear(); + this.errorMessages.clear(); + this.alternativeIds.clear(); + } + + public List getDescriptions() { + return descriptions; + } + + public void setDescriptions(List descriptions) { + this.descriptions = descriptions; + } + + public Set getMergeIds() { + return mergeIds; + } + + public void setMergeIds(Set mergeIds) { + this.mergeIds = mergeIds; + } + + public List getErrorMessages() { + return errorMessages; + } + + public void setErrorMessages(List errorMessages) { + this.errorMessages = errorMessages; + } + + public Set getAlternativeIds() { + return alternativeIds; + } + + public void setAlternativeIds(Set alternativeIds) { + this.alternativeIds = alternativeIds; + } + +} diff --git a/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/root/XMLConfig.java b/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/app/config/XMLConfig.java similarity index 90% rename from Conceptpower+Spring/src/main/java/edu/asu/conceptpower/root/XMLConfig.java rename to Conceptpower+Spring/src/main/java/edu/asu/conceptpower/app/config/XMLConfig.java index 772c4b706..430977184 100644 --- a/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/root/XMLConfig.java +++ b/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/app/config/XMLConfig.java @@ -1,4 +1,4 @@ -package edu.asu.conceptpower.root; +package edu.asu.conceptpower.app.config; public class XMLConfig { diff --git a/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/app/constants/LuceneFieldNames.java b/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/app/constants/LuceneFieldNames.java new file mode 100644 index 000000000..8009ffef6 --- /dev/null +++ b/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/app/constants/LuceneFieldNames.java @@ -0,0 +1,19 @@ +package edu.asu.conceptpower.app.constants; + +public interface LuceneFieldNames { + + public final static String EQUALS_TO = "equalTo"; + public final static String SIMILAR_TO = "similar"; + public final static String DESCRIPTION = "description"; + public final static String WORD = "word"; + public final static String POS = "pos"; + public final static String CONCEPT_LIST = "listName"; + public final static String TYPE_ID = "types"; + public final static String CREATOR = "creatorId"; + public final static String MODIFIED = "modifiedId"; + public final static String SYNONYMID = "synonymId"; + public final static String ID = "id"; + public final static String WORDNETID = "wordnetid"; + public final static String CONCEPTTYPE = "conceptType"; + public final static String MERGED_IDS = "mergedIds"; +} diff --git a/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/app/constants/SearchFieldNames.java b/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/app/constants/SearchFieldNames.java new file mode 100644 index 000000000..62969b184 --- /dev/null +++ b/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/app/constants/SearchFieldNames.java @@ -0,0 +1,20 @@ +package edu.asu.conceptpower.app.constants; + +public interface SearchFieldNames { + public final static String EQUAL_TO = "equal_to"; + public final static String SIMILAR_TO = "similar_to"; + public final static String DESCRIPTION = "description"; + public final static String WORD = "word"; + public final static String POS = "pos"; + public final static String CONCEPT_LIST = "concept_list"; + public final static String TYPE_ID = "type_id"; + public final static String CREATOR = "creator"; + public final static String MODIFIED = "modified_by"; + public final static String WORDNETID = "wordnetid"; + public final static String ID = "id"; + public final static String ISCHECKED = "isChecked"; + public final static String TYPE_URI = "type_uri"; + public final static String SYNONYM_ID = "synonymId"; + public final static String PAGE = "page"; + public final static String MERGED_IDS = "mergedIds"; +} diff --git a/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/app/core/Constants.java b/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/app/core/Constants.java new file mode 100644 index 000000000..6e093a9b1 --- /dev/null +++ b/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/app/core/Constants.java @@ -0,0 +1,9 @@ +package edu.asu.conceptpower.app.core; + +public interface Constants { + + public final static String SYNONYM_SEPARATOR = ","; + public final static String CONCEPT_SEPARATOR = ","; + public final static String WORDNET_DICTIONARY = "WordNet"; + public final static String CONCEPT_PREFIX = "CON"; +} diff --git a/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/app/core/IAlternativeIdService.java b/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/app/core/IAlternativeIdService.java new file mode 100644 index 000000000..e7ed70900 --- /dev/null +++ b/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/app/core/IAlternativeIdService.java @@ -0,0 +1,41 @@ +package edu.asu.conceptpower.app.core; + +import java.util.Collection; + +import edu.asu.conceptpower.core.ConceptEntry; + +public interface IAlternativeIdService { + + /** + * This method adds all alternative ids to the given concept entry. + * + * Alternative ids comprise queriedId, if the queriedId is of + * GENERIC_WORDNET_CONCEPT_ID type, specific wordnet ids from the worndet id + * field of the concept, the id of the concept itself, if the id is of type + * LOCAL_CONCEPT_ID type and the merged ids. + * + * @param queriedId + * - Id with which the concept entry is queried by the user. + * @param entry + * - ConceptEntry corresponding to that id. + */ + public void addAlternativeIds(String queriedId, ConceptEntry entry); + + /** + * This method adds the alternative ids to each of the concept entry in the + * Collection object which is passed as a method parameter. + * + * @param conceptEntries + * - Collection of concept entry. + */ + public void addAlternativeIds(Collection conceptEntries); + + /** + * This method adds the alternative ids to each of the concept entry in the + * Concept entry array which is passed as a method parameter. + * + * @param conceptEntries + * - Array of concept entry. + */ + public void addAlternativeIds(ConceptEntry[] conceptEntries); +} diff --git a/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/core/IConceptListManager.java b/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/app/core/IConceptListManager.java similarity index 92% rename from Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/core/IConceptListManager.java rename to Conceptpower+Spring/src/main/java/edu/asu/conceptpower/app/core/IConceptListManager.java index 105c15ba3..aee3a06a1 100644 --- a/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/core/IConceptListManager.java +++ b/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/app/core/IConceptListManager.java @@ -1,9 +1,9 @@ -package edu.asu.conceptpower.servlet.core; +package edu.asu.conceptpower.app.core; import java.util.List; +import edu.asu.conceptpower.app.exceptions.DictionaryExistsException; import edu.asu.conceptpower.core.ConceptList; -import edu.asu.conceptpower.servlet.exceptions.DictionaryExistsException; public interface IConceptListManager { diff --git a/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/app/core/IConceptManager.java b/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/app/core/IConceptManager.java new file mode 100644 index 000000000..88f098ee9 --- /dev/null +++ b/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/app/core/IConceptManager.java @@ -0,0 +1,171 @@ +package edu.asu.conceptpower.app.core; + +import java.util.List; +import java.util.Map; + +import edu.asu.conceptpower.app.exceptions.DictionaryDoesNotExistException; +import edu.asu.conceptpower.app.exceptions.DictionaryEntryExistsException; +import edu.asu.conceptpower.app.exceptions.DictionaryModifyException; +import edu.asu.conceptpower.app.exceptions.IndexerRunningException; +import edu.asu.conceptpower.app.exceptions.LuceneException; +import edu.asu.conceptpower.core.ConceptEntry; + +public interface IConceptManager { + + public final static String DEFAULT_PAGE_SIZE = "default_page_size"; + + /** + * Return entry given its ID. First the additional concepts are queried, + * then WordNet. + * + * @param id + * of entry + * @return Entry for ID or null. + */ + public abstract ConceptEntry getConceptEntry(String id); + + /** + * Get an entry from WordNet given its WordNet ID. + * + * @param wordnetId + * Id of concept in WordNet. + * @return concept for ID or null + */ + public abstract ConceptEntry getWordnetConceptEntry(String wordnetId) throws LuceneException; + + /** + * Get all entries for a word and its POS. + * + * @param word + * Word looked for. Additional concepts will be queried with + * "contains", WordNet concepts will be queried using + * "equals exactly". + * @param pos + * Part of speech of word (noun, verb, adjective, adverb). + * @return matching concepts + */ + public abstract ConceptEntry[] getConceptListEntriesForWordPOS(String word, String pos, + String conceptList) throws LuceneException, IllegalAccessException, IndexerRunningException; + + /** + * Searches in all additional concepts for in the given fields for the given + * values. The results for each field/value pair are joined with "or". + * + * @param fieldMap + * map of field/value pairs + * @return matching concepts + */ + public abstract ConceptEntry[] searchForConceptsConnectedByOr(Map fieldMap) throws LuceneException; + + /** + * Searches in all additional concepts for in the given fields for the given + * values. The results for each field/value pair are joined with "and". + * + * @param fieldMap + * map of field/value pairs + * @return matching concepts + */ + public abstract ConceptEntry[] searchForConceptsConnectedByAnd(Map fieldMap) throws LuceneException; + + /** + * Given a concept id this method returns an array of concepts that are + * listed as synonyms for the concept with the given id. + * + * @param id + * The id of the concept that synonyms should be retrieved for. + * @return An array of concept entries that are synonyms for the concept + * with the given id. This method will never return null only filled + * or empty arrays. + */ + public abstract ConceptEntry[] getSynonymsForConcept(String id) throws LuceneException; + + /** + * This method returns an array of concept entries that have words that + * contain the given word. E.g. if the given word is "horse" this method + * would return concepts such as "horse" or "horseback riding". + * + * @param word + * The word that should be contained in the word field of a + * concept. + * @return An array list with matching concepts. This method never returns + * null only empty or filled arrays. + */ + public abstract ConceptEntry[] getConceptListEntriesForWord(String word) + throws LuceneException, IllegalAccessException, IndexerRunningException; + + public abstract List getConceptListEntries(String conceptList, int pageNo, int pageSize, + String sortBy, int sortDirection) throws LuceneException; + + public abstract void addConceptListEntry(String word, String pos, String description, String conceptListName, + String typeId, String equalTo, String similarTo, String synonymIds, String synsetIds, String narrows, + String broadens) + throws DictionaryDoesNotExistException, DictionaryModifyException, DictionaryEntryExistsException; + + /** + * Stores the given entry in the database and return the new id that was + * generated for the entry. + * + * @param entry + * the {@link ConceptEntry} to be stored. + * @return Id of stored entry. + * @throws DictionaryDoesNotExistException + * If the entry has a concept list specified that doesn't exist. + * @throws DictionaryModifyException + * If the specified concept list in the concept is the Wordnet + * list. + */ + public abstract String addConceptListEntry(ConceptEntry entry, String userName) + throws DictionaryDoesNotExistException, DictionaryModifyException, LuceneException, IllegalAccessException, + IndexerRunningException; + + public abstract void storeModifiedConcept(ConceptEntry entry, String userName) + throws LuceneException, IllegalAccessException, IndexerRunningException; + + public abstract void deleteConcept(String id, String userName) throws LuceneException, IndexerRunningException; + + /** + * Fetches the concept wrapped entries based on the wordnet id + * + * @param wordNetID + * @return + */ + public ConceptEntry getConceptWrappedEntryByWordNetId(String wordNetID) + throws IllegalAccessException, LuceneException, IndexerRunningException; + + public int getPageCount(String conceptListName); + + /** + * Gets all the concept entries for the specified typeid + * + * @param typeId + * @return + */ + public List getConceptEntryByTypeId(String typeId); + + /** + * Gets all the concept entry for the specified concept list name + * + * @param conceptListName + * @return + */ + public List getConceptEntriedByConceptListName(String conceptListName); + + /** + * This method fetches the concept entry details based on word, pos and + * concept list values. This method also accepts parameters for pagination + * + * @param word + * @param pos + * @param conceptList + * @param page + * @param numberOfRecordsPerPage + * @return + * @throws LuceneException + * @throws IllegalAccessException + * @throws IndexerRunningException + */ + public ConceptEntry[] getConceptListEntriesForWordPOS(String word, String pos, String conceptList, + int page, int numberOfRecordsPerPage) + throws LuceneException, IllegalAccessException, IndexerRunningException; + +} diff --git a/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/app/core/IConceptTypeManger.java b/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/app/core/IConceptTypeManger.java new file mode 100644 index 000000000..780a11bbc --- /dev/null +++ b/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/app/core/IConceptTypeManger.java @@ -0,0 +1,56 @@ +package edu.asu.conceptpower.app.core; + +import java.util.List; + +import edu.asu.conceptpower.core.ConceptType; + +/** + * This class is the manager class for concept types. It provides methods for + * adding, updating, deleting, and retrieving concepts. + * + * @author jdamerow + * + */ +public interface IConceptTypeManger { + + public void addConceptType(ConceptType type); + + public void storeModifiedConceptType(ConceptType type); + + public ConceptType[] getAllTypes(); + + /** + * This method retrieves a type by the provided type ID. Returns null if + * there is not such type. + * + * @param id + * ID of the type to be retrieved. + * @return The corresponding type or null if there is no type for th ID. + */ + public ConceptType getType(String id); + + public void deleteType(String id); + + /** + * Returns the total number of pages based on the default page size. + * + * @return + */ + public int getPageCount(); + + /** + * Returns the concept types based on the page number, page size, sortBy + * column and sort direction. + * + * @param pageNo + * @param pageSize + * @param sortBy + * @param sortDirection + * @return + * @throws NoSuchFieldException + * @throws SecurityException + */ + public List getConceptTypes(int pageNo, int pageSize, String sortBy, int sortDirection) + throws NoSuchFieldException, SecurityException; + +} diff --git a/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/app/core/IConceptTypesService.java b/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/app/core/IConceptTypesService.java new file mode 100644 index 000000000..15671d1ea --- /dev/null +++ b/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/app/core/IConceptTypesService.java @@ -0,0 +1,32 @@ +package edu.asu.conceptpower.app.core; + + +public interface IConceptTypesService { + + /** + * This enum contains the list of valid concept types. + * + * @author karthikeyanmohan + */ + public enum IdType { + GENERIC_WORDNET_CONCEPT_ID, SPECIFIC_WORDNET_CONCEPT_ID, LOCAL_CONCEPT_ID + } + + /** + * This method returns the concept type based on the id parameter. + * + * The different IdTypes that are returned by this method are + * + * 1) GENERIC_WORDNET_CONCEPT_ID -> This id usually contains '??'. + * + * 2) SPECIFIC_WORDNET_CONCEPT_ID -> This id usually starts with WID and + * does not contain any ??. + * + * 3) LOCAL_CONCEPT_ID -> This is usually the concept id local to concept + * power. + * + * @param id + * @return IdType + */ + public IdType getConceptTypeByConceptId(String id); +} diff --git a/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/app/core/IIndexService.java b/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/app/core/IIndexService.java new file mode 100644 index 000000000..8dda380fc --- /dev/null +++ b/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/app/core/IIndexService.java @@ -0,0 +1,39 @@ +package edu.asu.conceptpower.app.core; + +import java.util.Map; + +import edu.asu.conceptpower.app.exceptions.IndexerRunningException; +import edu.asu.conceptpower.app.exceptions.LuceneException; +import edu.asu.conceptpower.core.ConceptEntry; +import edu.asu.conceptpower.core.IndexingEvent; + +public interface IIndexService { + + public ConceptEntry[] searchForConcepts(Map fieldMap, String operator) + throws LuceneException, IllegalAccessException,IndexerRunningException; + + public void insertConcept(ConceptEntry entry, String userName) + throws IllegalAccessException, LuceneException, IndexerRunningException; + + public void deleteById(String id, String userName) throws LuceneException, IndexerRunningException; + + public void deleteIndexes(String userName) throws LuceneException, IndexerRunningException; + + public void indexConcepts(String userName) + throws LuceneException, IllegalArgumentException, IllegalAccessException, IndexerRunningException; + + public boolean isIndexerRunning(); + + public IndexingEvent getTotalNumberOfWordsIndexed(); + + public void updateConceptEntry(ConceptEntry entry, String userName) + throws LuceneException, IndexerRunningException, IllegalAccessException; + + public ConceptEntry[] searchForConceptByPageNumberAndFieldMap(Map fieldMap, + String operator, int pageNumber, int numberOfRecordsPerPage) + throws LuceneException, IllegalAccessException, IndexerRunningException; + + public int getTotalNumberOfRecordsForSearch(Map fieldMap, String operator) + throws LuceneException, IllegalAccessException, IndexerRunningException; + +} diff --git a/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/app/core/POS.java b/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/app/core/POS.java new file mode 100644 index 000000000..5d6bbe6ef --- /dev/null +++ b/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/app/core/POS.java @@ -0,0 +1,17 @@ +package edu.asu.conceptpower.app.core; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +public interface POS { + + public final static String NOUN = "noun"; + public final static String VERB = "verb"; + public final static String ADVERB = "adverb"; + public final static String ADJECTIVE = "adjective"; + public final static String OTHER = "other"; + + public final static List posValues = new ArrayList( + Arrays.asList(new String[] { POS.NOUN, POS.VERB, POS.ADVERB, POS.ADJECTIVE, POS.OTHER })); +} diff --git a/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/app/core/impl/AlternativeIdService.java b/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/app/core/impl/AlternativeIdService.java new file mode 100644 index 000000000..fec80f962 --- /dev/null +++ b/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/app/core/impl/AlternativeIdService.java @@ -0,0 +1,83 @@ +package edu.asu.conceptpower.app.core.impl; + +import java.util.Collection; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import edu.asu.conceptpower.app.core.IAlternativeIdService; +import edu.asu.conceptpower.app.core.IConceptTypesService; +import edu.asu.conceptpower.app.core.IConceptTypesService.IdType; +import edu.asu.conceptpower.core.ConceptEntry; + +/** + * This helper class is used for adding alternative ids to the concept entry. + * + * @author karthikeyanmohan + * + */ +@Service +public class AlternativeIdService implements IAlternativeIdService { + + @Autowired + private IConceptTypesService conceptTypesService; + + /** + * If id or concept entry passed to the method is null, then method just + * returns and no changes are made. + * + * @param queriedId + * @param entry + */ + public void addAlternativeIds(String queriedId, ConceptEntry entry) { + + if (entry == null) { + return; + } + + if (conceptTypesService.getConceptTypeByConceptId(queriedId) == IdType.GENERIC_WORDNET_CONCEPT_ID) { + entry.getAlternativeIds().add(queriedId); + } + // Specific Wordnet id is added irrespective of what is queried for + if (entry.getWordnetId() != null) { + String[] wordNetIds = entry.getWordnetId().split(","); + for (String wordNetId : wordNetIds) { + entry.getAlternativeIds().add(wordNetId.trim()); + } + } + // This has been added to make sure local concept id is added. + entry.getAlternativeIds().add(entry.getId()); + + // Added the merged ids of the concepts to alternative id + if (entry.getMergedIds() != null) { + String[] mergedIds = entry.getMergedIds().split(","); + for (String mergedId : mergedIds) { + entry.getAlternativeIds().add(mergedId.trim()); + } + } + } + + /** + * This method adds the alternative ids to each of the concept entry in the + * Collection which is passed as a parameter. + * + * @param conceptEntries + */ + public void addAlternativeIds(Collection conceptEntries) { + for (ConceptEntry entry : conceptEntries) { + addAlternativeIds(entry.getId(), entry); + } + } + + /** + * This method adds the alternative ids to each of the concept entry in the + * ConceptEntry[] which is passed as a parameter. + * + * @param conceptEntries + */ + public void addAlternativeIds(ConceptEntry[] conceptEntries) { + for (ConceptEntry entry : conceptEntries) { + addAlternativeIds(entry.getId(), entry); + } + } +} diff --git a/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/core/impl/ConceptListManager.java b/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/app/core/impl/ConceptListManager.java similarity index 93% rename from Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/core/impl/ConceptListManager.java rename to Conceptpower+Spring/src/main/java/edu/asu/conceptpower/app/core/impl/ConceptListManager.java index db62d1876..d9ce2cc43 100644 --- a/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/core/impl/ConceptListManager.java +++ b/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/app/core/impl/ConceptListManager.java @@ -1,4 +1,4 @@ -package edu.asu.conceptpower.servlet.core.impl; +package edu.asu.conceptpower.app.core.impl; import java.util.List; import java.util.UUID; @@ -6,10 +6,10 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; +import edu.asu.conceptpower.app.core.IConceptListManager; +import edu.asu.conceptpower.app.db4o.DBNames; +import edu.asu.conceptpower.app.db4o.IConceptDBManager; import edu.asu.conceptpower.core.ConceptList; -import edu.asu.conceptpower.servlet.core.IConceptListManager; -import edu.asu.conceptpower.servlet.db4o.DBNames; -import edu.asu.conceptpower.servlet.db4o.IConceptDBManager; /** * Manager class for concept lists. diff --git a/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/core/impl/ConceptManager.java b/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/app/core/impl/ConceptManager.java similarity index 61% rename from Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/core/impl/ConceptManager.java rename to Conceptpower+Spring/src/main/java/edu/asu/conceptpower/app/core/impl/ConceptManager.java index ca94ccad1..ca8edffae 100644 --- a/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/core/impl/ConceptManager.java +++ b/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/app/core/impl/ConceptManager.java @@ -1,4 +1,4 @@ -package edu.asu.conceptpower.servlet.core.impl; +package edu.asu.conceptpower.app.core.impl; import java.util.ArrayList; import java.util.Collections; @@ -7,26 +7,30 @@ import java.util.HashMap; import java.util.List; import java.util.Map; -import java.util.UUID; +import java.util.Random; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.context.annotation.PropertySource; import org.springframework.stereotype.Service; +import edu.asu.conceptpower.app.constants.SearchFieldNames; +import edu.asu.conceptpower.app.core.IAlternativeIdService; +import edu.asu.conceptpower.app.core.IConceptManager; +import edu.asu.conceptpower.app.core.IIndexService; +import edu.asu.conceptpower.app.db4o.DBNames; +import edu.asu.conceptpower.app.db4o.IConceptDBManager; +import edu.asu.conceptpower.app.exceptions.DictionaryDoesNotExistException; +import edu.asu.conceptpower.app.exceptions.DictionaryEntryExistsException; +import edu.asu.conceptpower.app.exceptions.DictionaryModifyException; +import edu.asu.conceptpower.app.exceptions.IndexerRunningException; +import edu.asu.conceptpower.app.exceptions.LuceneException; +import edu.asu.conceptpower.app.wordnet.Constants; +import edu.asu.conceptpower.app.wordnet.WordNetManager; import edu.asu.conceptpower.core.ConceptEntry; import edu.asu.conceptpower.core.ConceptList; -import edu.asu.conceptpower.servlet.core.IConceptManager; -import edu.asu.conceptpower.servlet.core.IIndexService; -import edu.asu.conceptpower.servlet.db4o.DBNames; -import edu.asu.conceptpower.servlet.db4o.IConceptDBManager; -import edu.asu.conceptpower.servlet.exceptions.DictionaryDoesNotExistException; -import edu.asu.conceptpower.servlet.exceptions.DictionaryEntryExistsException; -import edu.asu.conceptpower.servlet.exceptions.DictionaryModifyException; -import edu.asu.conceptpower.servlet.exceptions.IndexerRunningException; -import edu.asu.conceptpower.servlet.exceptions.LuceneException; -import edu.asu.conceptpower.servlet.rest.LuceneFieldNames; -import edu.asu.conceptpower.servlet.rest.SearchFieldNames; -import edu.asu.conceptpower.servlet.wordnet.Constants; -import edu.asu.conceptpower.servlet.wordnet.WordNetManager; +import edu.asu.conceptpower.servlet.core.ChangeEvent; +import edu.asu.conceptpower.servlet.core.ChangeEvent.ChangeEventTypes; /** * This class handles concepts in general. It uses a DB4O client that contains @@ -37,6 +41,7 @@ * */ @Service +@PropertySource("classpath:config.properties") public class ConceptManager implements IConceptManager { @Autowired @@ -50,6 +55,12 @@ public class ConceptManager implements IConceptManager { protected final String CONCEPT_PREFIX = "CON"; + @Value("${default_page_size}") + private Integer defaultPageSize; + + @Autowired + private IAlternativeIdService alternativeIdService; + /* * (non-Javadoc) * @@ -61,12 +72,14 @@ public ConceptEntry getConceptEntry(String id) { ConceptEntry entry = client.getEntry(id); if (entry != null) { fillConceptEntry(entry); + alternativeIdService.addAlternativeIds(id, entry); return entry; } entry = wordnetManager.getConcept(id); if (entry != null) { // client.store(entry, DBNames.WORDNET_CACHE); + alternativeIdService.addAlternativeIds(id, entry); return entry; } @@ -94,15 +107,31 @@ public ConceptEntry getWordnetConceptEntry(String wordnetId) throws LuceneExcept * java.lang.String, java.lang.String) */ @Override - public ConceptEntry[] getConceptListEntriesForWord(String word, String pos, String conceptList) + public ConceptEntry[] getConceptListEntriesForWordPOS(String word, String pos, String conceptList) + throws LuceneException, IllegalAccessException, IndexerRunningException { + return getConceptListEntriesForWordPOS(word, pos, conceptList, -1, -1); + } + + /* + * This method fetches the concepts based on word, pos and concept list + * details. This method also accepts parameters for pagination + * + * @see + * edu.asu.conceptpower.core.IConceptManager#getConceptListEntriesForWord( + * java.lang.String, java.lang.String) + */ + @Override + public ConceptEntry[] getConceptListEntriesForWordPOS(String word, String pos, String conceptList, + int page, int numberOfRecordsPerPage) throws LuceneException, IllegalAccessException, IndexerRunningException { if (pos == null) return null; - Map fieldMap = new HashMap(); + + Map fieldMap = new HashMap(); fieldMap.put(SearchFieldNames.WORD, word); fieldMap.put(SearchFieldNames.POS, pos); - fieldMap.put(LuceneFieldNames.CONCEPT_LIST, conceptList); - return indexService.searchForConcepts(fieldMap,null); + fieldMap.put(SearchFieldNames.CONCEPT_LIST, conceptList); + return indexService.searchForConceptByPageNumberAndFieldMap(fieldMap, null, page, numberOfRecordsPerPage); } /** @@ -182,7 +211,7 @@ public ConceptEntry[] searchForConceptsConnectedByOr(Map fieldMa } } } - + alternativeIdService.addAlternativeIds(results); return results.toArray(new ConceptEntry[results.size()]); } @@ -225,7 +254,7 @@ public ConceptEntry[] searchForConceptsConnectedByAnd(Map fieldM } results = filteredResults; } - + alternativeIdService.addAlternativeIds(results); return results.toArray(new ConceptEntry[results.size()]); } @@ -285,7 +314,9 @@ public ConceptEntry[] getSynonymsForConcept(String id) throws LuceneException { public ConceptEntry[] getConceptListEntriesForWord(String word) throws LuceneException, IllegalAccessException, IndexerRunningException { Map fieldMap = new HashMap(); fieldMap.put(SearchFieldNames.WORD, word); - return indexService.searchForConcepts(fieldMap, null); + ConceptEntry[] entries = indexService.searchForConcepts(fieldMap, null); + alternativeIdService.addAlternativeIds(entries); + return entries; } /* @@ -296,9 +327,22 @@ public ConceptEntry[] getConceptListEntriesForWord(String word) throws LuceneExc * .String) */ @Override - public List getConceptListEntries(String conceptList) throws LuceneException { + public List getConceptListEntries(String conceptList, int page, int pageSize, String sortBy, + int sortDirection) throws LuceneException { + + if (pageSize == -1) { + pageSize = defaultPageSize; + } + if (page < 1) { + page = 1; + } + int pageCount = getConceptsCountForConceptList(conceptList); + pageCount = pageCount > 0 ? pageCount : 1; + if (page > pageCount) { + page = pageCount; + } - List entries = client.getAllEntriesFromList(conceptList); + List entries = client.getAllEntriesFromList(conceptList, page, pageSize, sortBy, sortDirection); Collections.sort(entries, new Comparator() { public int compare(ConceptEntry o1, ConceptEntry o2) { @@ -321,6 +365,7 @@ public int compare(ConceptEntry o1, ConceptEntry o2) { notDeletedEntries.add(entry); } } + alternativeIdService.addAlternativeIds(notDeletedEntries); return notDeletedEntries; } @@ -371,30 +416,35 @@ public void addConceptListEntry(String word, String pos, String description, Str * conceptpower.core.ConceptEntry) */ @Override - public String addConceptListEntry(ConceptEntry entry) - throws DictionaryDoesNotExistException, DictionaryModifyException, LuceneException, IllegalAccessException, IndexerRunningException { - ConceptList dict = client.getConceptList(entry.getConceptList()); - if (dict == null) - throw new DictionaryDoesNotExistException(); - - if (entry.getConceptList().equals(Constants.WORDNET_DICTIONARY)) { - throw new DictionaryModifyException(); - } - - String id = generateId(CONCEPT_PREFIX); - entry.setId(id); - client.store(entry, DBNames.DICTIONARY_DB); - if (entry.getWordnetId() != null) { - String wordnetId = entry.getWordnetId(); - if (wordnetId.endsWith(",")) { - wordnetId = wordnetId.substring(0, wordnetId.length()-1); - } - indexService.deleteById(wordnetId); - } - indexService.insertConcept(entry); - return id; + public String addConceptListEntry(ConceptEntry entry, String userName) throws DictionaryDoesNotExistException, + DictionaryModifyException, LuceneException, IllegalAccessException, IndexerRunningException { + ConceptList dict = client.getConceptList(entry.getConceptList()); + if (dict == null) + throw new DictionaryDoesNotExistException(); - } + if (entry.getConceptList().equals(Constants.WORDNET_DICTIONARY)) { + throw new DictionaryModifyException(); + } + + // Creating the first change event + ChangeEvent changeEvent = new ChangeEvent(userName, new Date(), ChangeEventTypes.CREATION); + entry.addNewChangeEvent(changeEvent); + String id = generateId(CONCEPT_PREFIX); + entry.setId(id); + entry.getAlternativeIds().add(id); + client.store(entry, DBNames.DICTIONARY_DB); + if (entry.getWordnetId() != null) { + String[] wordnetIds = entry.getWordnetId().split(","); + for (String wordnetId : wordnetIds) { + if (!wordnetId.trim().equalsIgnoreCase("")) { + indexService.deleteById(wordnetId, userName); + } + } + + } + indexService.insertConcept(entry, userName); + return id; + } /* @@ -405,39 +455,103 @@ public String addConceptListEntry(ConceptEntry entry) * conceptpower.core.ConceptEntry) */ @Override - public void storeModifiedConcept(ConceptEntry entry) throws LuceneException, IllegalAccessException, IndexerRunningException { - String modified = entry.getModified() != null ? entry.getModified() : ""; - if (!modified.trim().isEmpty()) - modified += ", "; - entry.setModified(modified + entry.getModifiedUser() + "@" + (new Date()).toString()); - - indexService.deleteById(entry.getId()); - indexService.insertConcept(entry); - client.update(entry, DBNames.DICTIONARY_DB); - } + public void storeModifiedConcept(ConceptEntry entry, String userName) + throws LuceneException, IllegalAccessException, IndexerRunningException { + ChangeEvent changeEvent = new ChangeEvent(); + changeEvent.setDate(new Date()); + changeEvent.setUserName(userName); + changeEvent.setType(ChangeEventTypes.MODIFICATION); + entry.addNewChangeEvent(changeEvent); - protected String generateId(String prefix) { - String id = prefix + UUID.randomUUID().toString(); + indexService.updateConceptEntry(entry, userName); + client.update(entry, DBNames.DICTIONARY_DB); + } + + protected String generateId(String prefix) { while (true) { - ConceptEntry example = null; - example = new ConceptEntry(); + String id = prefix + generateUniqueId(); + + ConceptEntry example = new ConceptEntry(); example.setId(id); // if there doesn't exist an object with this id return id List results = client.queryByExample(example); if (results == null || results.size() == 0) return id; + } + } + + /** + * This methods generates a new 12 character long id. Note that this method + * does not assure that the id isn't in use yet. + * + * Adapted from + * http://stackoverflow.com/questions/9543715/generating-human-readable + * -usable-short-but-unique-ids + * + * @return 12 character id + */ + private String generateUniqueId() { + char[] chars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz".toCharArray(); - // try other id - id = prefix + UUID.randomUUID().toString(); + Random random = new Random(); + StringBuilder builder = new StringBuilder(); + for (int i = 0; i < 12; i++) { + builder.append(chars[random.nextInt(62)]); } + + return builder.toString(); } @Override - public void deleteConcept(String id) throws LuceneException, IndexerRunningException { + public void deleteConcept(String id, String userName) throws LuceneException, IndexerRunningException { ConceptEntry concept = getConceptEntry(id); concept.setDeleted(true); + ChangeEvent changeEvent = new ChangeEvent(); + changeEvent.setType(ChangeEventTypes.DELETION); + changeEvent.setDate(new Date()); + changeEvent.setUserName(userName); + concept.addNewChangeEvent(changeEvent); client.update(concept, DBNames.DICTIONARY_DB); - indexService.deleteById(concept.getId()); + indexService.deleteById(concept.getId(), userName); + } + + @Override + public ConceptEntry getConceptWrappedEntryByWordNetId(String wordNetID) + throws IllegalAccessException, LuceneException, IndexerRunningException { + List conceptEntries = client.getConceptByWordnetId(wordNetID); + for (ConceptEntry entry : conceptEntries) { + // Wordnet is also added because lucene doesn't do an exact search + // on fields + if (entry.getId().contains(CONCEPT_PREFIX) && entry.getWordnetId().contains(wordNetID)) { + return entry; + } + } + // No concept wrapper found for wordnet id + return null; + } + + public int getPageCount(String conceptListName) { + int totalUploads = getConceptsCountForConceptList(conceptListName); + return (int) Math.ceil(new Double(totalUploads) / new Double(defaultPageSize)); + } + + private int getConceptsCountForConceptList(String listName) { + List allEntries = client.getAllEntriesFromList(listName); + return allEntries.size(); + } + + @Override + public List getConceptEntryByTypeId(String typeId) { + List conceptEntries = client.getAllEntriesByTypeId(typeId); + alternativeIdService.addAlternativeIds(conceptEntries); + return conceptEntries; + } + + @Override + public List getConceptEntriedByConceptListName(String conceptListName) { + List conceptEntries = client.getAllEntriesFromList(conceptListName); + alternativeIdService.addAlternativeIds(conceptEntries); + return conceptEntries; } } diff --git a/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/app/core/impl/ConceptTypesManager.java b/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/app/core/impl/ConceptTypesManager.java new file mode 100644 index 000000000..75c7a111a --- /dev/null +++ b/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/app/core/impl/ConceptTypesManager.java @@ -0,0 +1,135 @@ +package edu.asu.conceptpower.app.core.impl; + +import java.util.List; +import java.util.UUID; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.stereotype.Service; + +import edu.asu.conceptpower.app.core.IConceptTypeManger; +import edu.asu.conceptpower.app.db.TypeDatabaseClient; +import edu.asu.conceptpower.core.ConceptType; + +@Service +public class ConceptTypesManager implements IConceptTypeManger { + + @Autowired + private TypeDatabaseClient client; + + @Value("${default_page_size}") + private Integer defaultPageSize; + + /* + * (non-Javadoc) + * + * @see edu.asu.conceptpower.core.IConceptTypeManger#addConceptType(edu.asu. + * conceptpower.core.ConceptType) + */ + @Override + public void addConceptType(ConceptType type) { + + String id = null; + while (true) { + id = UUID.randomUUID().toString(); + ConceptType exist = client.getType(id); + if (exist == null) + break; + } + + type.setTypeId(id); + + client.addType(type); + } + + /* + * (non-Javadoc) + * + * @see + * edu.asu.conceptpower.core.IConceptTypeManger#storeModifiedConceptType(edu + * .asu.conceptpower.core.ConceptType) + */ + @Override + public void storeModifiedConceptType(ConceptType type) { + client.update(type); + } + + /* + * (non-Javadoc) + * + * @see edu.asu.conceptpower.core.IConceptTypeManger#getAllTypes() + */ + @Override + public ConceptType[] getAllTypes() { + return client.getAllTypes(); + } + + /* + * (non-Javadoc) + * + * @see + * edu.asu.conceptpower.core.IConceptTypeManger#getType(java.lang.String) + */ + @Override + public ConceptType getType(String id) { + return client.getType(id); + } + + /* + * (non-Javadoc) + * + * @see + * edu.asu.conceptpower.core.IConceptTypeManger#deleteType(java.lang.String) + */ + @Override + public void deleteType(String id) { + client.deleteType(id); + } + + @Override + public int getPageCount() { + ConceptType[] types = getAllTypes(); + return (int) Math.ceil(new Double(types.length) / new Double(defaultPageSize)); + } + + /** + * Returns the concept types based on page number, page size, sort by column + * and sort direction. + * + * If page size is -1 then default page size is set as page size. + * + * If page number is less than 1 or null, then page number is set as 1. + * + * @param pageNo + * @param pageSize + * @param sortBy + * @param sortDirection + * @return + * @throws NoSuchFieldException + * @throws SecurityException + */ + @Override + public List getConceptTypes(int page, int pageSize, String sortBy, int sortDirection) + throws NoSuchFieldException, SecurityException { + + if (pageSize == -1) { + pageSize = defaultPageSize; + } + if (page < 1) { + page = 1; + } + int pageCount = getTotalNumberOfConceptTypes(); + pageCount = pageCount > 0 ? pageCount : 1; + if (page > pageCount) { + page = pageCount; + } + + return client.getAllTypes(page, pageSize, sortBy, sortDirection); + } + + private int getTotalNumberOfConceptTypes() { + ConceptType[] types = client.getAllTypes(); + return types.length; + } + +} diff --git a/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/app/core/impl/ConceptTypesService.java b/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/app/core/impl/ConceptTypesService.java new file mode 100644 index 000000000..983a5a119 --- /dev/null +++ b/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/app/core/impl/ConceptTypesService.java @@ -0,0 +1,46 @@ +package edu.asu.conceptpower.app.core.impl; + +import org.springframework.stereotype.Service; + +import edu.asu.conceptpower.app.core.IConceptTypesService; + +/** + * This helper class is used for identifying the concept type based on the + * concept id. + * + * @author karthikeyanmohan + * + */ +@Service +public class ConceptTypesService implements IConceptTypesService { + + /** + * This method returns the concept types based on the id. If id is null then + * null value is returned by the method. + * + * Concept Type is determined based on the type of id. + * + * If id contains ??, then that concept is a generic wordnet concept. + * + * If id starts with WID, then that concept is a specifc wordnet concept. + * + * If both of the above condition is not met, then the concept is local CCP + * concept. + * + * @param id + * @return IdType + */ + public IdType getConceptTypeByConceptId(String id) { + if (id == null) { + return null; + } + if (id.contains("??")) { + return IdType.GENERIC_WORDNET_CONCEPT_ID; + } + if (id.startsWith("WID")) { + return IdType.SPECIFIC_WORDNET_CONCEPT_ID; + } + return IdType.LOCAL_CONCEPT_ID; + } + +} diff --git a/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/app/core/impl/IndexService.java b/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/app/core/impl/IndexService.java new file mode 100644 index 000000000..28e4946e0 --- /dev/null +++ b/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/app/core/impl/IndexService.java @@ -0,0 +1,172 @@ +package edu.asu.conceptpower.app.core.impl; + +import java.util.Map; +import java.util.concurrent.atomic.AtomicBoolean; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.scheduling.annotation.Async; +import org.springframework.stereotype.Service; + +import edu.asu.conceptpower.app.core.IAlternativeIdService; +import edu.asu.conceptpower.app.core.IIndexService; +import edu.asu.conceptpower.app.exceptions.IndexerRunningException; +import edu.asu.conceptpower.app.exceptions.LuceneException; +import edu.asu.conceptpower.app.lucene.ILuceneDAO; +import edu.asu.conceptpower.app.lucene.ILuceneUtility; +import edu.asu.conceptpower.core.ConceptEntry; +import edu.asu.conceptpower.core.IndexingEvent; + +/** + * This class acts as a single point of access to lucene. This class performs + * searching, insertion, deletion and indexing in lucene + * + * @author karthikeyanmohan + * + */ +@Service +public class IndexService implements IIndexService { + + @Autowired + private ILuceneUtility luceneUtility; + + @Autowired + @Qualifier("luceneDAO") + private ILuceneDAO dao; + + @Value("#{messages['INDEXER_RUNNING']}") + private String indexerRunning; + + @Autowired + private IAlternativeIdService alternativeIdService; + + /** + * This field makes sure indexer runs only once when two different admins + * gives index command at same time + */ + private AtomicBoolean indexerRunningFlag = new AtomicBoolean(false); + + /** + * This method searches in lucene on a particular condition fed through + * fieldMap + */ + @Override + public ConceptEntry[] searchForConcepts(Map fieldMap, String operator) + throws LuceneException, IllegalAccessException, IndexerRunningException { + + if (indexerRunningFlag.get()) { + throw new IndexerRunningException(indexerRunning); + } + // Fetches all the pages + return luceneUtility.queryIndex(fieldMap, operator, 0, -1); + } + + /** + * This method searches in lucene on a particular condition fed through + * fieldMap + */ + @Override + public ConceptEntry[] searchForConceptByPageNumberAndFieldMap(Map fieldMap, String operator, + int pageNumber, int numberOfRecordsPerPage) + throws LuceneException, IllegalAccessException, IndexerRunningException { + + if (indexerRunningFlag.get()) { + throw new IndexerRunningException(indexerRunning); + } + + ConceptEntry[] entries = luceneUtility.queryIndex(fieldMap, operator, pageNumber, numberOfRecordsPerPage); + alternativeIdService.addAlternativeIds(entries); + return entries; + } + + /** + * This method inserts concepts into lucene + * + * @throws IndexerRunningException + */ + @Override + public void insertConcept(ConceptEntry entry, String userName) + throws IllegalAccessException, LuceneException, IndexerRunningException { + if (indexerRunningFlag.get()) { + throw new IndexerRunningException(indexerRunning); + + } + luceneUtility.insertConcept(entry, userName); + } + + /** + * This method deletes the concept in lucene index based on id of the + * concept + */ + @Override + public void deleteById(String id, String userName) throws LuceneException, IndexerRunningException { + if (indexerRunningFlag.get()) { + throw new IndexerRunningException(indexerRunning); + } + luceneUtility.deleteById(id, userName); + + } + + /** + * This method deletes the index in lucene + */ + @Override + public void deleteIndexes(String userName) throws LuceneException, IndexerRunningException { + if (!indexerRunningFlag.compareAndSet(false, true)) { + throw new IndexerRunningException(indexerRunning); + } + luceneUtility.deleteIndexes(userName); + indexerRunningFlag.set(false); + } + + /** + * This method indexes concepts in lucene and runs indexer only once + */ + @Override + @Async("indexExecutor") + public void indexConcepts(String userName) + throws LuceneException, IllegalArgumentException, IllegalAccessException, IndexerRunningException { + if (!indexerRunningFlag.compareAndSet(false, true)) { + throw new IndexerRunningException(indexerRunning); + } + try { + luceneUtility.indexConcepts(userName); + } finally { + indexerRunningFlag.set(false); + } + } + + @Override + public boolean isIndexerRunning() { + return indexerRunningFlag.get(); + } + + @Override + public IndexingEvent getTotalNumberOfWordsIndexed() { + return dao.getTotalNumberOfWordsIndexed(); + } + + /** + * This method updates the concept in lucene index by deleting the concept + * entry based on the id and inserting the concept entry + * + * @throws IllegalAccessException + */ + @Override + public void updateConceptEntry(ConceptEntry entry, String userName) + throws LuceneException, IndexerRunningException, IllegalAccessException { + if (indexerRunningFlag.get()) { + throw new IndexerRunningException(indexerRunning); + } + luceneUtility.deleteById(entry.getId(), userName); + luceneUtility.insertConcept(entry, userName); + } + + @Override + public int getTotalNumberOfRecordsForSearch(Map fieldMap, String operator) + throws LuceneException, IllegalAccessException, IndexerRunningException { + return searchForConcepts(fieldMap, operator).length; + } + +} diff --git a/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/root/DatabaseClient.java b/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/app/db/DatabaseClient.java similarity index 75% rename from Conceptpower+Spring/src/main/java/edu/asu/conceptpower/root/DatabaseClient.java rename to Conceptpower+Spring/src/main/java/edu/asu/conceptpower/app/db/DatabaseClient.java index 1359657a9..37bf1382f 100644 --- a/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/root/DatabaseClient.java +++ b/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/app/db/DatabaseClient.java @@ -1,11 +1,14 @@ -package edu.asu.conceptpower.root; +package edu.asu.conceptpower.app.db; import java.lang.reflect.Field; import java.util.ArrayList; +import java.util.Comparator; import java.util.List; import javax.annotation.PostConstruct; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.stereotype.Component; @@ -13,23 +16,20 @@ import com.db4o.ObjectContainer; import com.db4o.ObjectSet; import com.db4o.query.Predicate; +import com.db4o.query.Query; +import edu.asu.conceptpower.app.db4o.DBNames; +import edu.asu.conceptpower.app.db4o.IConceptDBManager; +import edu.asu.conceptpower.app.reflect.SearchField; import edu.asu.conceptpower.core.ConceptEntry; import edu.asu.conceptpower.core.ConceptList; -import edu.asu.conceptpower.servlet.db4o.DBNames; -import edu.asu.conceptpower.servlet.db4o.IConceptDBManager; -import edu.asu.conceptpower.servlet.reflect.SearchField; -import edu.asu.conceptpower.servlet.web.ConceptAddController; +import edu.asu.conceptpower.servlet.core.ChangeEvent; @Component public class DatabaseClient implements IConceptDBManager { - ObjectContainer wordnetCacheClient; - ObjectContainer dictionaryClient; - - @Autowired - @Qualifier("wordnetCacheDatabaseManager") - private DatabaseManager wordnetCache; + private ObjectContainer dictionaryClient; + private final Logger logger = LoggerFactory.getLogger(getClass()); @Autowired @Qualifier("conceptDatabaseManager") @@ -37,7 +37,6 @@ public class DatabaseClient implements IConceptDBManager { @PostConstruct public void init() { - this.wordnetCacheClient = wordnetCache.getClient(); this.dictionaryClient = dictionary.getClient(); } @@ -65,19 +64,11 @@ public ConceptEntry getEntry(String id) { exampleEntry.setId(id); exampleEntry.setWordnetId(null); - /* - * check if there is a concept in the wordnet cache - */ - ObjectSet results = wordnetCacheClient.queryByExample(exampleEntry); - - // there should only be exactly one object with this id - if (results.size() == 1) - return results.get(0); /* * check if there is a concept with this id */ - results = dictionaryClient.queryByExample(exampleEntry); + ObjectSet results = dictionaryClient.queryByExample(exampleEntry); // there should only be exactly one object with this id if (results.size() == 1) return results.get(0); @@ -88,7 +79,7 @@ public ConceptEntry getEntry(String id) { @Override public List getConceptByWordnetId(String wordnetId) { ConceptEntry entry = new ConceptEntry(); - entry.setWordnetId(wordnetId + ","); + entry.setWordnetId(wordnetId); ObjectSet entries = dictionaryClient.queryByExample(entry); return entries; @@ -103,20 +94,7 @@ public List getConceptByWordnetId(String wordnetId) { */ @Override public List queryByExample(Object example) { - ObjectSet results = wordnetCacheClient.queryByExample(example); - ObjectSet results2 = dictionaryClient.queryByExample(example); - - List allResults = new ArrayList(); - for (Object r : results) { - allResults.add(r); - } - - for (Object r : results2) { - allResults.add(r); - } - - return allResults; - + return dictionaryClient.queryByExample(example); } /* @@ -281,12 +259,7 @@ public boolean match(ConceptList dict) { */ @Override public List getAllElementsOfType(Class clazz) { - List results = wordnetCacheClient.query(clazz); - List dictResults = dictionaryClient.query(clazz); - List allResults = new ArrayList(); - allResults.addAll(results); - allResults.addAll(dictResults); - return allResults; + return dictionaryClient.query(clazz); } /* @@ -297,17 +270,80 @@ public List getAllElementsOfType(Class clazz) { * lang.String) */ @Override - public List getAllEntriesFromList(String listname) { + public List getAllEntriesFromList(String listname, int page, int pageSize, final String sortBy, + final int sortDirection) { ConceptEntry entry = new ConceptEntry(); entry.setConceptList(listname); - List results = wordnetCacheClient.queryByExample(entry); - List dictResults = dictionaryClient.queryByExample(entry); + Query dictQuery = dictionaryClient.query(); + dictQuery.constrain(ConceptEntry.class); + dictQuery.descend("conceptList").constrain(listname); + + try { + final Field sortField = ConceptEntry.class.getDeclaredField(sortBy); + sortField.setAccessible(true); + + Comparator conceptEntryComparator = new Comparator() { + + @Override + public int compare(ConceptEntry o1, ConceptEntry o2) { + Object o1FieldContent; + Object o2FieldContent; + try { + if (sortDirection == IConceptDBManager.ASCENDING) { + o1FieldContent = sortField.get(o1); + o2FieldContent = sortField.get(o2); + } else { + o2FieldContent = sortField.get(o1); + o1FieldContent = sortField.get(o2); + } + } catch (IllegalArgumentException | IllegalAccessException e) { + logger.error("Error accessing field.", e); + return 0; + } + + if (o1FieldContent instanceof Integer) { + return ((Integer) o1FieldContent).compareTo((Integer) o2FieldContent); + } + return o1FieldContent.toString().compareTo(o2FieldContent.toString()); + } + }; + + dictQuery.sortBy(conceptEntryComparator); + } catch (NoSuchFieldException | SecurityException e) { + logger.error("Couldn't sort list.", e); + return null; + } + + List dictResults = dictQuery.execute(); + + int startIndex = (page - 1) * pageSize; + int endIndex = startIndex + pageSize; + if (endIndex > dictResults.size()) { + endIndex = dictResults.size(); + } + return new ArrayList(dictResults.subList(startIndex, endIndex)); + } + + /* + * (non-Javadoc) + * + * @see + * edu.asu.conceptpower.db4o.IConceptDBManager#getAllEntriesFromList(java. + * lang.String) + */ + @Override + public List getAllEntriesFromList(String listname) { + ConceptEntry entry = new ConceptEntry(); + entry.setConceptList(listname); + return dictionaryClient.queryByExample(entry); + } - List allResults = new ArrayList(); - allResults.addAll(results); - allResults.addAll(dictResults); - return allResults; + @Override + public List getAllEntriesByTypeId(String typeId) { + ConceptEntry entry = new ConceptEntry(); + entry.setTypeId(typeId); + return dictionaryClient.queryByExample(entry); } /* @@ -355,6 +391,10 @@ public void update(ConceptEntry entry, String databasename) { toBeUpdated.setWord(entry.getWord()); toBeUpdated.setWordnetId(entry.getWordnetId()); toBeUpdated.setDeleted(entry.isDeleted()); + for(ChangeEvent changeEvent : entry.getChangeEvents()) { + toBeUpdated.addNewChangeEvent(changeEvent); + } + dictionaryClient.store(toBeUpdated); dictionaryClient.commit(); } diff --git a/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/app/db/DatabaseManager.java b/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/app/db/DatabaseManager.java new file mode 100644 index 000000000..7fa30eb0a --- /dev/null +++ b/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/app/db/DatabaseManager.java @@ -0,0 +1,57 @@ +package edu.asu.conceptpower.app.db; + +import java.io.Serializable; + +import com.db4o.ObjectContainer; +import com.db4o.ObjectServer; +import com.db4o.cs.Db4oClientServer; +import com.db4o.cs.config.ServerConfiguration; + +import edu.asu.conceptpower.core.ConceptEntry; + +public class DatabaseManager implements Serializable { + + /** + * + */ + private static final long serialVersionUID = -3325272288078647257L; + private ObjectServer server; + private String databasePath; + + public void init() { + close(); + ServerConfiguration configuration = Db4oClientServer.newServerConfiguration(); + configuration.file().blockSize(80); + configuration.common().objectClass(ConceptEntry.class).objectField("wordnetId").indexed(true); + configuration.common().objectClass(ConceptEntry.class).objectField("id").indexed(true); + // Added to make sure list has been added to the database + // Ref: http://www.resolvinghere.com/sof/12343387.shtml + configuration.common().objectClass(ConceptEntry.class).updateDepth(2); + server = Db4oClientServer.openServer(configuration, databasePath, 0); + + } + + public ObjectContainer getClient() { + ObjectContainer container = server.openClient(); + return container; + } + + public String getDatabasePath() { + return databasePath; + } + + public void setDatabasePath(String databasePath) { + this.databasePath = databasePath; + } + + private void close() { + if (server != null) { + server.close(); + } + server = null; + } + + public void shutdown() { + close(); + } +} diff --git a/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/db/IDatabaseManager.java b/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/app/db/IDatabaseManager.java similarity index 90% rename from Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/db/IDatabaseManager.java rename to Conceptpower+Spring/src/main/java/edu/asu/conceptpower/app/db/IDatabaseManager.java index dfe8dec3b..9668ebc70 100644 --- a/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/db/IDatabaseManager.java +++ b/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/app/db/IDatabaseManager.java @@ -1,4 +1,4 @@ -package edu.asu.conceptpower.servlet.db; +package edu.asu.conceptpower.app.db; import javax.persistence.EntityManager; diff --git a/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/app/db/TypeDatabaseClient.java b/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/app/db/TypeDatabaseClient.java new file mode 100644 index 000000000..0bc74e894 --- /dev/null +++ b/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/app/db/TypeDatabaseClient.java @@ -0,0 +1,153 @@ +package edu.asu.conceptpower.app.db; + +import java.lang.reflect.Field; +import java.util.ArrayList; +import java.util.Comparator; +import java.util.List; + +import javax.annotation.PostConstruct; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.stereotype.Component; + +import com.db4o.ObjectContainer; +import com.db4o.ObjectSet; +import com.db4o.query.Query; + +import edu.asu.conceptpower.app.db4o.IConceptDBManager; +import edu.asu.conceptpower.app.util.URIHelper; +import edu.asu.conceptpower.core.ConceptType; + +@Component +public class TypeDatabaseClient { + + private ObjectContainer client; + + private final Logger logger = LoggerFactory.getLogger(getClass()); + + @Autowired + @Qualifier("typesDatabaseManager") + private DatabaseManager typeDatabase; + + @Autowired + private URIHelper uriHelper; + + @PostConstruct + public void init() { + this.client = typeDatabase.getClient(); + } + + public ConceptType getType(String uriOrId) { + String id = uriHelper.getTypeId(uriOrId); + ConceptType user = new ConceptType(id); + ObjectSet results = client.queryByExample(user); + + // there should only be exactly one object with this id + if (results.size() == 1) + return results.get(0); + + return null; + } + + public ConceptType findType(String name) { + ConceptType user = new ConceptType(); + user.setTypeName(name); + + ObjectSet results = client.queryByExample(user); + // there should only be exactly one object with this id + if (results.size() >= 1) + return results.get(0); + + return null; + } + + public ConceptType[] getAllTypes() { + ObjectSet results = client.query(ConceptType.class); + return results.toArray(new ConceptType[results.size()]); + } + + public ConceptType addType(ConceptType user) { + client.store(user); + client.commit(); + return user; + } + + public void deleteType(String id) { + ConceptType user = new ConceptType(); + user.setTypeId(id); + + ObjectSet results = client.queryByExample(user); + for (ConceptType res : results) { + client.delete(res); + client.commit(); + } + } + + public void update(ConceptType type) { + ConceptType toBeUpdated = getType(type.getTypeId()); + toBeUpdated.setCreatorId(type.getCreatorId()); + toBeUpdated.setDescription(type.getDescription()); + toBeUpdated.setMatches(type.getMatches()); + toBeUpdated.setModified(type.getModified()); + toBeUpdated.setSupertypeId(type.getSupertypeId()); + toBeUpdated.setTypeId(type.getTypeId()); + toBeUpdated.setTypeName(type.getTypeName()); + client.store(toBeUpdated); + client.commit(); + } + + public List getAllTypes(int page, int pageSize, final String sortBy, int sortDirection) + throws NoSuchFieldException, SecurityException { + + Query typeQuery = client.query(); + typeQuery.constrain(ConceptType.class); + + final Field sortField = ConceptType.class.getDeclaredField(sortBy); + sortField.setAccessible(true); + + Comparator conceptTypeComparator = new Comparator() { + + @Override + public int compare(ConceptType o1, ConceptType o2) { + Object o1FieldContent; + Object o2FieldContent; + try { + if (sortDirection == IConceptDBManager.ASCENDING) { + o1FieldContent = sortField.get(o1); + o2FieldContent = sortField.get(o2); + } else { + o2FieldContent = sortField.get(o1); + o1FieldContent = sortField.get(o2); + } + } catch (IllegalArgumentException | IllegalAccessException e) { + logger.error("Error accessing field.", e); + return 0; + } + + if (o1FieldContent instanceof Integer) { + return ((Integer) o1FieldContent).compareTo((Integer) o2FieldContent); + } + if (o1FieldContent == null || o2FieldContent == null) { + return 0; + } + return o1FieldContent.toString().compareTo(o2FieldContent.toString()); + } + + }; + + typeQuery.sortBy(conceptTypeComparator); + List conceptTypes = typeQuery.execute(); + + int startIndex = (page - 1) * pageSize; + int endIndex = startIndex + pageSize; + if (endIndex > conceptTypes.size()) { + endIndex = conceptTypes.size(); + } + + return new ArrayList(conceptTypes.subList(startIndex, endIndex)); + } + +} diff --git a/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/db/objectdb/ConceptDBManager.java b/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/app/db/objectdb/ConceptDBManager.java similarity index 76% rename from Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/db/objectdb/ConceptDBManager.java rename to Conceptpower+Spring/src/main/java/edu/asu/conceptpower/app/db/objectdb/ConceptDBManager.java index 32ed0e6f2..34b7171bc 100644 --- a/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/db/objectdb/ConceptDBManager.java +++ b/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/app/db/objectdb/ConceptDBManager.java @@ -1,13 +1,13 @@ -package edu.asu.conceptpower.servlet.db.objectdb; +package edu.asu.conceptpower.app.db.objectdb; import java.util.List; import org.springframework.beans.factory.annotation.Autowired; +import edu.asu.conceptpower.app.db.IDatabaseManager; +import edu.asu.conceptpower.app.db4o.IConceptDBManager; import edu.asu.conceptpower.core.ConceptEntry; import edu.asu.conceptpower.core.ConceptList; -import edu.asu.conceptpower.servlet.db.IDatabaseManager; -import edu.asu.conceptpower.servlet.db4o.IConceptDBManager; public class ConceptDBManager implements IConceptDBManager { @@ -64,7 +64,8 @@ public List getAllElementsOfType(Class clazz) { } @Override - public List getAllEntriesFromList(String listname) { + public List getAllEntriesFromList(String conceptList, int pageNo, int pageSize, String sortBy, + int sortDirection) { // TODO Auto-generated method stub return null; } @@ -96,6 +97,16 @@ public void update(ConceptList list, String listname, String databasename) { public List getConceptByWordnetId(String wordnetId) { return null; } - - + + @Override + public List getAllEntriesFromList(String listname) { + // TODO Auto-generated method stub + return null; + } + + @Override + public List getAllEntriesByTypeId(String typeId) { + // TODO Auto-generated method stub + return null; + } } diff --git a/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/db/objectdb/ObjectDbDatabaseManager.java b/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/app/db/objectdb/ObjectDbDatabaseManager.java similarity index 93% rename from Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/db/objectdb/ObjectDbDatabaseManager.java rename to Conceptpower+Spring/src/main/java/edu/asu/conceptpower/app/db/objectdb/ObjectDbDatabaseManager.java index ee3c43ac4..d69b66334 100644 --- a/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/db/objectdb/ObjectDbDatabaseManager.java +++ b/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/app/db/objectdb/ObjectDbDatabaseManager.java @@ -1,4 +1,4 @@ -package edu.asu.conceptpower.servlet.db.objectdb; +package edu.asu.conceptpower.app.db.objectdb; import javax.persistence.EntityManager; import javax.persistence.PersistenceContext; @@ -6,7 +6,7 @@ import org.springframework.stereotype.Component; import org.springframework.transaction.annotation.Transactional; -import edu.asu.conceptpower.servlet.db.IDatabaseManager; +import edu.asu.conceptpower.app.db.IDatabaseManager; //@Component diff --git a/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/db4o/DBNames.java b/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/app/db4o/DBNames.java similarity index 85% rename from Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/db4o/DBNames.java rename to Conceptpower+Spring/src/main/java/edu/asu/conceptpower/app/db4o/DBNames.java index 4403405fb..d3f9081ed 100644 --- a/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/db4o/DBNames.java +++ b/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/app/db4o/DBNames.java @@ -1,4 +1,4 @@ -package edu.asu.conceptpower.servlet.db4o; +package edu.asu.conceptpower.app.db4o; public interface DBNames { diff --git a/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/db4o/IConceptDBManager.java b/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/app/db4o/IConceptDBManager.java similarity index 73% rename from Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/db4o/IConceptDBManager.java rename to Conceptpower+Spring/src/main/java/edu/asu/conceptpower/app/db4o/IConceptDBManager.java index 27b1f7c4e..8438aa64b 100644 --- a/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/db4o/IConceptDBManager.java +++ b/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/app/db4o/IConceptDBManager.java @@ -1,14 +1,15 @@ -package edu.asu.conceptpower.servlet.db4o; +package edu.asu.conceptpower.app.db4o; import java.util.List; -import com.db4o.ObjectSet; - import edu.asu.conceptpower.core.ConceptEntry; import edu.asu.conceptpower.core.ConceptList; public interface IConceptDBManager { + public static final int ASCENDING = 1; + public static final int DESCENDING = -1; + public abstract ConceptEntry getEntry(String id); public abstract List queryByExample(Object example); @@ -32,7 +33,8 @@ public abstract ConceptEntry[] getEntriesByFieldContains(String field, */ public abstract List getAllElementsOfType(Class clazz); - public abstract List getAllEntriesFromList(String listname); + public abstract List getAllEntriesFromList(String conceptList, int pageNo, int pageSize, + String sortBy, int sortDirection); public abstract void store(Object element, String databasename); @@ -45,4 +47,8 @@ public abstract void update(ConceptList list, String listname, List getConceptByWordnetId(String wordnetId); + public List getAllEntriesFromList(String listname); + + public List getAllEntriesByTypeId(String typeId); + } \ No newline at end of file diff --git a/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/app/error/CPError.java b/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/app/error/CPError.java new file mode 100644 index 000000000..b2e5a295e --- /dev/null +++ b/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/app/error/CPError.java @@ -0,0 +1,14 @@ +package edu.asu.conceptpower.app.error; + +public class CPError { + + private String errorCode; + + public CPError(String errorCode) { + this.errorCode = errorCode; + } + + public String getErrorCode() { + return errorCode; + } +} diff --git a/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/exceptions/ConceptPowerExceptionHandler.java b/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/app/exceptions/ConceptPowerExceptionHandler.java similarity index 97% rename from Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/exceptions/ConceptPowerExceptionHandler.java rename to Conceptpower+Spring/src/main/java/edu/asu/conceptpower/app/exceptions/ConceptPowerExceptionHandler.java index 48fbf89d8..fc16f934d 100644 --- a/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/exceptions/ConceptPowerExceptionHandler.java +++ b/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/app/exceptions/ConceptPowerExceptionHandler.java @@ -1,4 +1,4 @@ -package edu.asu.conceptpower.servlet.exceptions; +package edu.asu.conceptpower.app.exceptions; import javax.servlet.http.HttpServletRequest; diff --git a/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/exceptions/ConceptPowerStorageException.java b/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/app/exceptions/ConceptPowerStorageException.java similarity index 93% rename from Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/exceptions/ConceptPowerStorageException.java rename to Conceptpower+Spring/src/main/java/edu/asu/conceptpower/app/exceptions/ConceptPowerStorageException.java index 3cc00a1a2..1b64f3c0d 100644 --- a/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/exceptions/ConceptPowerStorageException.java +++ b/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/app/exceptions/ConceptPowerStorageException.java @@ -1,4 +1,4 @@ -package edu.asu.conceptpower.servlet.exceptions; +package edu.asu.conceptpower.app.exceptions; /** * This is an exception thrown when there is a storage problem. diff --git a/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/exceptions/DictionaryDoesNotExistException.java b/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/app/exceptions/DictionaryDoesNotExistException.java similarity index 75% rename from Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/exceptions/DictionaryDoesNotExistException.java rename to Conceptpower+Spring/src/main/java/edu/asu/conceptpower/app/exceptions/DictionaryDoesNotExistException.java index 208dc9359..81277c3c2 100644 --- a/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/exceptions/DictionaryDoesNotExistException.java +++ b/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/app/exceptions/DictionaryDoesNotExistException.java @@ -1,4 +1,4 @@ -package edu.asu.conceptpower.servlet.exceptions; +package edu.asu.conceptpower.app.exceptions; public class DictionaryDoesNotExistException extends Exception { diff --git a/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/exceptions/DictionaryEntryExistsException.java b/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/app/exceptions/DictionaryEntryExistsException.java similarity index 75% rename from Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/exceptions/DictionaryEntryExistsException.java rename to Conceptpower+Spring/src/main/java/edu/asu/conceptpower/app/exceptions/DictionaryEntryExistsException.java index 166f36abd..b416f4652 100644 --- a/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/exceptions/DictionaryEntryExistsException.java +++ b/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/app/exceptions/DictionaryEntryExistsException.java @@ -1,4 +1,4 @@ -package edu.asu.conceptpower.servlet.exceptions; +package edu.asu.conceptpower.app.exceptions; public class DictionaryEntryExistsException extends Exception { diff --git a/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/exceptions/DictionaryExistsException.java b/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/app/exceptions/DictionaryExistsException.java similarity index 75% rename from Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/exceptions/DictionaryExistsException.java rename to Conceptpower+Spring/src/main/java/edu/asu/conceptpower/app/exceptions/DictionaryExistsException.java index c93d6f4da..d114a6682 100644 --- a/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/exceptions/DictionaryExistsException.java +++ b/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/app/exceptions/DictionaryExistsException.java @@ -1,4 +1,4 @@ -package edu.asu.conceptpower.servlet.exceptions; +package edu.asu.conceptpower.app.exceptions; public class DictionaryExistsException extends Exception { diff --git a/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/exceptions/DictionaryModifyException.java b/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/app/exceptions/DictionaryModifyException.java similarity index 75% rename from Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/exceptions/DictionaryModifyException.java rename to Conceptpower+Spring/src/main/java/edu/asu/conceptpower/app/exceptions/DictionaryModifyException.java index ebe6eb9f1..0595de28c 100644 --- a/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/exceptions/DictionaryModifyException.java +++ b/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/app/exceptions/DictionaryModifyException.java @@ -1,4 +1,4 @@ -package edu.asu.conceptpower.servlet.exceptions; +package edu.asu.conceptpower.app.exceptions; public class DictionaryModifyException extends Exception { diff --git a/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/exceptions/IndexerRunningException.java b/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/app/exceptions/IndexerRunningException.java similarity index 91% rename from Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/exceptions/IndexerRunningException.java rename to Conceptpower+Spring/src/main/java/edu/asu/conceptpower/app/exceptions/IndexerRunningException.java index 48d60cecc..4bb7f6910 100644 --- a/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/exceptions/IndexerRunningException.java +++ b/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/app/exceptions/IndexerRunningException.java @@ -1,4 +1,4 @@ -package edu.asu.conceptpower.servlet.exceptions; +package edu.asu.conceptpower.app.exceptions; public class IndexerRunningException extends Exception { diff --git a/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/exceptions/LuceneException.java b/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/app/exceptions/LuceneException.java similarity index 93% rename from Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/exceptions/LuceneException.java rename to Conceptpower+Spring/src/main/java/edu/asu/conceptpower/app/exceptions/LuceneException.java index bde9a587c..4fce541f9 100644 --- a/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/exceptions/LuceneException.java +++ b/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/app/exceptions/LuceneException.java @@ -1,4 +1,4 @@ -package edu.asu.conceptpower.servlet.exceptions; +package edu.asu.conceptpower.app.exceptions; /** diff --git a/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/jaxb/viaf/Channel.java b/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/app/jaxb/viaf/Channel.java similarity index 96% rename from Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/jaxb/viaf/Channel.java rename to Conceptpower+Spring/src/main/java/edu/asu/conceptpower/app/jaxb/viaf/Channel.java index 24cf1e3f5..b80ea376e 100644 --- a/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/jaxb/viaf/Channel.java +++ b/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/app/jaxb/viaf/Channel.java @@ -1,4 +1,4 @@ -package edu.asu.conceptpower.servlet.jaxb.viaf; +package edu.asu.conceptpower.app.jaxb.viaf; import java.util.List; diff --git a/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/jaxb/viaf/Item.java b/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/app/jaxb/viaf/Item.java similarity index 95% rename from Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/jaxb/viaf/Item.java rename to Conceptpower+Spring/src/main/java/edu/asu/conceptpower/app/jaxb/viaf/Item.java index 0b753dd1b..d1ae88c0a 100644 --- a/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/jaxb/viaf/Item.java +++ b/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/app/jaxb/viaf/Item.java @@ -1,4 +1,4 @@ -package edu.asu.conceptpower.servlet.jaxb.viaf; +package edu.asu.conceptpower.app.jaxb.viaf; import javax.xml.bind.annotation.XmlAccessType; import javax.xml.bind.annotation.XmlAccessorType; diff --git a/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/lucene/ILuceneDAO.java b/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/app/lucene/ILuceneDAO.java similarity index 55% rename from Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/lucene/ILuceneDAO.java rename to Conceptpower+Spring/src/main/java/edu/asu/conceptpower/app/lucene/ILuceneDAO.java index c9199bcfb..300259b7c 100644 --- a/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/lucene/ILuceneDAO.java +++ b/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/app/lucene/ILuceneDAO.java @@ -1,10 +1,10 @@ -package edu.asu.conceptpower.servlet.lucene; +package edu.asu.conceptpower.app.lucene; import edu.asu.conceptpower.core.IndexingEvent; public interface ILuceneDAO { - public void storeValues(long numberOfIndexedWords,String action); + public void storeValues(IndexingEvent bean); public IndexingEvent getTotalNumberOfWordsIndexed(); } diff --git a/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/app/lucene/ILuceneUtility.java b/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/app/lucene/ILuceneUtility.java new file mode 100644 index 000000000..0f203862c --- /dev/null +++ b/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/app/lucene/ILuceneUtility.java @@ -0,0 +1,21 @@ +package edu.asu.conceptpower.app.lucene; + +import java.util.Map; + +import edu.asu.conceptpower.app.exceptions.LuceneException; +import edu.asu.conceptpower.core.ConceptEntry; + +public interface ILuceneUtility { + + public void deleteById(String id, String userName) throws LuceneException; + + public void insertConcept(ConceptEntry entry, String userName) throws LuceneException, IllegalAccessException; + + public void deleteIndexes(String userName) throws LuceneException; + + public void indexConcepts(String userName) throws LuceneException, IllegalArgumentException, IllegalAccessException; + + public ConceptEntry[] queryIndex(Map fieldMap, String operator, int pageNumber, + int numberOfRecordsPerPage) throws LuceneException, IllegalAccessException; + +} \ No newline at end of file diff --git a/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/lucene/LuceneAction.java b/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/app/lucene/LuceneAction.java similarity index 81% rename from Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/lucene/LuceneAction.java rename to Conceptpower+Spring/src/main/java/edu/asu/conceptpower/app/lucene/LuceneAction.java index d0f93b0c2..c2eb76cf7 100644 --- a/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/lucene/LuceneAction.java +++ b/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/app/lucene/LuceneAction.java @@ -1,4 +1,4 @@ -package edu.asu.conceptpower.servlet.lucene; +package edu.asu.conceptpower.app.lucene; public interface LuceneAction { diff --git a/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/lucene/impl/LuceneDAO.java b/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/app/lucene/impl/LuceneDAO.java similarity index 79% rename from Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/lucene/impl/LuceneDAO.java rename to Conceptpower+Spring/src/main/java/edu/asu/conceptpower/app/lucene/impl/LuceneDAO.java index 6def65329..7a887c8c7 100644 --- a/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/lucene/impl/LuceneDAO.java +++ b/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/app/lucene/impl/LuceneDAO.java @@ -1,4 +1,4 @@ -package edu.asu.conceptpower.servlet.lucene.impl; +package edu.asu.conceptpower.app.lucene.impl; import java.util.Date; @@ -6,15 +6,13 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Qualifier; -import org.springframework.security.core.Authentication; -import org.springframework.security.core.context.SecurityContextHolder; import com.db4o.ObjectContainer; import com.db4o.ObjectSet; +import edu.asu.conceptpower.app.db.DatabaseManager; +import edu.asu.conceptpower.app.lucene.ILuceneDAO; import edu.asu.conceptpower.core.IndexingEvent; -import edu.asu.conceptpower.root.DatabaseManager; -import edu.asu.conceptpower.servlet.lucene.ILuceneDAO; /** * This class access db40 database to store the lucene details such as number of @@ -41,9 +39,7 @@ public void init() { /** * Stores the number of indexed word count along with the timestamp */ - public void storeValues(long numberOfIndexedWords, String action) { - Authentication auth = SecurityContextHolder.getContext().getAuthentication(); - IndexingEvent bean = new IndexingEvent(new Date(), numberOfIndexedWords, action, auth.getName()); + public void storeValues(IndexingEvent bean) { luceneClient.store(bean); luceneClient.commit(); } diff --git a/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/lucene/impl/LuceneUtility.java b/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/app/lucene/impl/LuceneUtility.java similarity index 63% rename from Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/lucene/impl/LuceneUtility.java rename to Conceptpower+Spring/src/main/java/edu/asu/conceptpower/app/lucene/impl/LuceneUtility.java index c40c5211f..fe9232daf 100644 --- a/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/lucene/impl/LuceneUtility.java +++ b/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/app/lucene/impl/LuceneUtility.java @@ -1,4 +1,4 @@ -package edu.asu.conceptpower.servlet.lucene.impl; +package edu.asu.conceptpower.app.lucene.impl; import java.io.File; import java.io.IOException; @@ -7,13 +7,22 @@ import java.nio.file.FileSystems; import java.nio.file.Path; import java.util.ArrayList; +import java.util.Arrays; +import java.util.Date; +import java.util.HashMap; +import java.util.HashSet; import java.util.Iterator; import java.util.List; import java.util.Map; +import java.util.Set; +import java.util.stream.Collectors; import javax.annotation.PostConstruct; import javax.annotation.PreDestroy; +import org.apache.lucene.analysis.Analyzer; +import org.apache.lucene.analysis.core.WhitespaceAnalyzer; +import org.apache.lucene.analysis.miscellaneous.PerFieldAnalyzerWrapper; import org.apache.lucene.analysis.standard.StandardAnalyzer; import org.apache.lucene.document.Document; import org.apache.lucene.document.Field; @@ -22,6 +31,7 @@ import org.apache.lucene.index.DirectoryReader; import org.apache.lucene.index.IndexWriter; import org.apache.lucene.index.IndexWriterConfig; +import org.apache.lucene.index.IndexableField; import org.apache.lucene.index.Term; import org.apache.lucene.queryparser.classic.ParseException; import org.apache.lucene.queryparser.classic.QueryParser; @@ -29,28 +39,30 @@ import org.apache.lucene.search.Query; import org.apache.lucene.search.ScoreDoc; import org.apache.lucene.search.TopDocs; +import org.apache.lucene.search.TopScoreDocCollector; import org.apache.lucene.store.Directory; import org.apache.lucene.store.FSDirectory; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Qualifier; -import org.springframework.beans.factory.annotation.Value; import org.springframework.context.annotation.PropertySource; +import org.springframework.core.env.Environment; import org.springframework.stereotype.Component; +import edu.asu.conceptpower.app.constants.LuceneFieldNames; +import edu.asu.conceptpower.app.db4o.IConceptDBManager; +import edu.asu.conceptpower.app.exceptions.LuceneException; +import edu.asu.conceptpower.app.lucene.ILuceneDAO; +import edu.asu.conceptpower.app.lucene.ILuceneUtility; +import edu.asu.conceptpower.app.lucene.LuceneAction; +import edu.asu.conceptpower.app.reflect.LuceneField; +import edu.asu.conceptpower.app.reflect.SearchField; +import edu.asu.conceptpower.app.wordnet.Constants; +import edu.asu.conceptpower.app.wordnet.WordNetConfiguration; import edu.asu.conceptpower.core.ConceptEntry; import edu.asu.conceptpower.core.IndexingEvent; -import edu.asu.conceptpower.servlet.db4o.IConceptDBManager; -import edu.asu.conceptpower.servlet.exceptions.LuceneException; -import edu.asu.conceptpower.servlet.lucene.ILuceneDAO; -import edu.asu.conceptpower.servlet.lucene.ILuceneUtility; -import edu.asu.conceptpower.servlet.lucene.LuceneAction; -import edu.asu.conceptpower.servlet.reflect.LuceneField; -import edu.asu.conceptpower.servlet.reflect.SearchField; -import edu.asu.conceptpower.servlet.rest.LuceneFieldNames; -import edu.asu.conceptpower.servlet.wordnet.Constants; -import edu.asu.conceptpower.servlet.wordnet.WordNetConfiguration; +import edu.asu.conceptpower.rest.SearchParamters; import edu.mit.jwi.Dictionary; import edu.mit.jwi.IDictionary; import edu.mit.jwi.item.IIndexWord; @@ -67,13 +79,13 @@ * */ @Component -@PropertySource("classpath:config.properties") +@PropertySource("classpath:/config.properties") public class LuceneUtility implements ILuceneUtility { private final Logger logger = LoggerFactory.getLogger(getClass()); @Autowired - private StandardAnalyzer whiteSpaceAnalyzer; + private StandardAnalyzer standardAnalyzer; @Autowired private WordNetConfiguration configuration; @@ -81,14 +93,18 @@ public class LuceneUtility implements ILuceneUtility { @Autowired private IConceptDBManager databaseClient; + @Autowired + private WhitespaceAnalyzer whiteSpaceAnalyzer; + + @Autowired + private Environment env; + @Autowired @Qualifier("luceneDAO") private ILuceneDAO luceneDAO; - @Value("${lucenePath}") private String lucenePath; - @Value("${numberOfLuceneResults}") private int numberOfResults; private IndexWriter writer = null; @@ -104,10 +120,12 @@ public class LuceneUtility implements ILuceneUtility { */ @PostConstruct public void init() throws LuceneException { + lucenePath = env.getProperty("lucenePath"); + numberOfResults = Integer.parseInt(env.getProperty("numberOfLuceneResults")); try { relativePath = FileSystems.getDefault().getPath(lucenePath, "index"); index = FSDirectory.open(relativePath); - configWhiteSpace = new IndexWriterConfig(whiteSpaceAnalyzer); + configWhiteSpace = new IndexWriterConfig(standardAnalyzer); writer = new IndexWriter(index, configWhiteSpace); reader = DirectoryReader.open(writer, true); searcher = new IndexSearcher(reader); @@ -121,7 +139,7 @@ public void init() throws LuceneException { * * @throws LuceneException */ - public void deleteById(String id) throws LuceneException { + public void deleteById(String id, String userName) throws LuceneException { try { writer.deleteDocuments(new Term(LuceneFieldNames.ID, id)); writer.commit(); @@ -129,7 +147,8 @@ public void deleteById(String id) throws LuceneException { } catch (IOException ex) { throw new LuceneException("Issues in deletion. Please retry", ex); } - luceneDAO.storeValues(-1, LuceneAction.DELETE); + IndexingEvent event = new IndexingEvent(new Date(), -1, LuceneAction.DELETE, userName); + luceneDAO.storeValues(event); } /** @@ -137,7 +156,7 @@ public void deleteById(String id) throws LuceneException { * values to be stored into lucene index After storing the values in index, * index count is increased in tables in lucene database */ - public void insertConcept(ConceptEntry entry) throws LuceneException, IllegalAccessException { + public void insertConcept(ConceptEntry entry, String userName) throws LuceneException, IllegalAccessException { Document doc = new Document(); java.lang.reflect.Field[] fields = entry.getClass().getDeclaredFields(); @@ -148,13 +167,30 @@ public void insertConcept(ConceptEntry entry) throws LuceneException, IllegalAcc if (searchFieldAnnotation != null) { Object contentOfField = field.get(entry); if (contentOfField != null) { - - if (searchFieldAnnotation.isIndexable()) { - doc.add(new TextField(searchFieldAnnotation.lucenefieldName(), String.valueOf(contentOfField), - Field.Store.YES)); + if (searchFieldAnnotation.isTokenized()) { + if (searchFieldAnnotation.isMultiple()) { + String[] contents = String.valueOf(contentOfField).split(","); + for (String content : contents) { + doc.add(new TextField(searchFieldAnnotation.lucenefieldName(), content, + Field.Store.YES)); + } + } else { + doc.add(new TextField(searchFieldAnnotation.lucenefieldName(), + String.valueOf(contentOfField), Field.Store.YES)); + } } else { - doc.add(new StringField(searchFieldAnnotation.lucenefieldName(), - String.valueOf(contentOfField), Field.Store.YES)); + // Non tokenized + if (searchFieldAnnotation.isMultiple()) { + String[] contents = String.valueOf(contentOfField).split(","); + for (String content : contents) { + doc.add(new StringField(searchFieldAnnotation.lucenefieldName(), content, + Field.Store.YES)); + } + } else { + doc.add(new StringField(searchFieldAnnotation.lucenefieldName(), + String.valueOf(contentOfField), Field.Store.YES)); + } + } } } @@ -167,7 +203,8 @@ public void insertConcept(ConceptEntry entry) throws LuceneException, IllegalAcc } catch (IOException ex) { throw new LuceneException("Cannot insert concept in lucene. Please retry", ex); } - luceneDAO.storeValues(1, LuceneAction.INSERT); + IndexingEvent bean = new IndexingEvent(new Date(), 1, LuceneAction.INSERT, userName); + luceneDAO.storeValues(bean); } /** @@ -185,7 +222,16 @@ private ConceptEntry getConceptFromDocument(Document d) throws IllegalAccessExce LuceneField luceneFieldAnnotation = field.getAnnotation(LuceneField.class); field.setAccessible(true); if (luceneFieldAnnotation != null && d.get(luceneFieldAnnotation.lucenefieldName()) != null) - field.set(con, d.get(luceneFieldAnnotation.lucenefieldName())); + if (!luceneFieldAnnotation.isMultiple()) { + IndexableField[] indexableFields = d.getFields(luceneFieldAnnotation.lucenefieldName()); + String content = Arrays.asList(indexableFields).stream().filter(iF -> iF.stringValue() != null) + .map(iF -> iF.stringValue()).collect(Collectors.joining(",")); + field.set(con, content); + + } else { + field.set(con, d.get(luceneFieldAnnotation.lucenefieldName())); + } + } return con; } @@ -195,7 +241,7 @@ private ConceptEntry getConceptFromDocument(Document d) throws IllegalAccessExce * index count is decremented in table */ @Override - public void deleteIndexes() throws LuceneException { + public void deleteIndexes(String userName) throws LuceneException { try { writer.deleteAll(); writer.commit(); @@ -204,7 +250,9 @@ public void deleteIndexes() throws LuceneException { throw new LuceneException("Problem in deleting indexes. Please retry", e); } IndexingEvent bean = luceneDAO.getTotalNumberOfWordsIndexed(); - luceneDAO.storeValues(-bean.getIndexedWordsCount(), LuceneAction.DELETE); + IndexingEvent updatedBean = new IndexingEvent(new Date(), -bean.getIndexedWordsCount(), LuceneAction.DELETE, + userName); + luceneDAO.storeValues(updatedBean); } /** @@ -216,7 +264,8 @@ public void deleteIndexes() throws LuceneException { * @param writer * @return */ - protected int[] createDocuments(Iterator iterator, IDictionary dict, IndexWriter writer) { + protected int[] createDocuments(Iterator iterator, IDictionary dict, IndexWriter writer, + Set wordnetIdsOfWrappers) { int numberOfIndexedWords = 0; int numberOfUnIndexedWords = 0; for (; iterator.hasNext();) { @@ -225,10 +274,7 @@ protected int[] createDocuments(Iterator iterator, IDictionary dict, for (IWordID wordId : wordIdds) { IWord word = dict.getWord(wordId); - List entries = databaseClient.getConceptByWordnetId(word.getID().toString()); - if (entries != null && !entries.isEmpty()) { - logger.debug("Found concept for " + wordId.toString()); - } else { + if (!wordnetIdsOfWrappers.contains(word.getID().toString())) { Document doc = createIndividualDocument(dict, wordId); try { numberOfIndexedWords++; @@ -259,7 +305,7 @@ private Document createIndividualDocument(IDictionary dict, IWordID wordId) { StringBuffer sb = new StringBuffer(); for (IWord syn : synonyms) { if (!syn.getID().equals(word.getID())) - sb.append(syn.getID().toString() + edu.asu.conceptpower.servlet.core.Constants.SYNONYM_SEPARATOR); + sb.append(syn.getID().toString() + edu.asu.conceptpower.app.core.Constants.SYNONYM_SEPARATOR); } doc.add(new TextField(LuceneFieldNames.SYNONYMID, sb.toString(), Field.Store.YES)); // Adding this new data to delete only wordnet concepts while @@ -278,16 +324,18 @@ private Document createIndividualDocument(IDictionary dict, IWordID wordId) { * @throws IllegalArgumentException * @throws IllegalAccessException */ - protected int[] createDocumentsFromConceptEntries(List conceptEntryList) + protected int[] createDocumentsFromConceptEntries(List conceptEntryList, String userName) throws IllegalArgumentException, IllegalAccessException { int numberOfIndexedConcepts = 0; int numberOfUnindexConcepts = 0; for (ConceptEntry entry : conceptEntryList) { - try { - insertConcept(entry); - numberOfIndexedConcepts++; - } catch (LuceneException e) { - numberOfUnindexConcepts++; + if (!entry.isDeleted()) { + try { + insertConcept(entry, userName); + numberOfIndexedConcepts++; + } catch (LuceneException e) { + numberOfUnindexConcepts++; + } } } int[] returnValue = new int[2]; @@ -301,7 +349,8 @@ protected int[] createDocumentsFromConceptEntries(List conceptEntr * different POS and loads the data into lucene index */ @Override - public void indexConcepts() throws LuceneException, IllegalArgumentException, IllegalAccessException { + public void indexConcepts(String userName) + throws LuceneException, IllegalArgumentException, IllegalAccessException { String wnhome = configuration.getWordnetPath(); String path = wnhome + File.separator + configuration.getDictFolder(); @@ -320,27 +369,33 @@ public void indexConcepts() throws LuceneException, IllegalArgumentException, Il throw new LuceneException("Issues while opening the dictionary", e); } + // Fetching DB4o Data + List conceptEntriesList = (List) databaseClient + .getAllElementsOfType(ConceptEntry.class); + + Set wordnetIdsOfWrappers = getWordNetIdsOfWrappers(conceptEntriesList); + // 2. Adding data into Iterator iterator = dict.getIndexWordIterator(POS.NOUN); - int[] numberOfWord = createDocuments(iterator, dict, writer); + int[] numberOfWord = createDocuments(iterator, dict, writer, wordnetIdsOfWrappers); int numberOfIndexedWords = numberOfWord[0]; int numberOfUnIndexedWords = numberOfWord[1]; iterator = dict.getIndexWordIterator(POS.ADVERB); - numberOfWord = createDocuments(iterator, dict, writer); + numberOfWord = createDocuments(iterator, dict, writer, wordnetIdsOfWrappers); numberOfIndexedWords += numberOfWord[0]; numberOfUnIndexedWords += numberOfWord[1]; iterator = dict.getIndexWordIterator(POS.ADJECTIVE); - numberOfWord = createDocuments(iterator, dict, writer); + numberOfWord = createDocuments(iterator, dict, writer, wordnetIdsOfWrappers); numberOfIndexedWords += numberOfWord[0]; numberOfUnIndexedWords += numberOfWord[1]; iterator = dict.getIndexWordIterator(POS.VERB); - numberOfWord = createDocuments(iterator, dict, writer); + numberOfWord = createDocuments(iterator, dict, writer, wordnetIdsOfWrappers); numberOfIndexedWords += numberOfWord[0]; numberOfUnIndexedWords += numberOfWord[1]; @@ -352,13 +407,8 @@ public void indexConcepts() throws LuceneException, IllegalArgumentException, Il throw new LuceneException("Issues in writing document", e); } - // Fetching DB4o Data - - List conceptEntriesList = (List) databaseClient - .getAllElementsOfType(ConceptEntry.class); - - numberOfWord = createDocumentsFromConceptEntries(conceptEntriesList); + numberOfWord = createDocumentsFromConceptEntries(conceptEntriesList, userName); numberOfIndexedWords += numberOfWord[0]; numberOfUnIndexedWords += numberOfWord[1]; @@ -369,7 +419,8 @@ public void indexConcepts() throws LuceneException, IllegalArgumentException, Il throw new LuceneException("Issues in writing document", e); } - luceneDAO.storeValues(numberOfIndexedWords, LuceneAction.REINDEX); + IndexingEvent event = new IndexingEvent(new Date(), numberOfIndexedWords, LuceneAction.REINDEX, userName); + luceneDAO.storeValues(event); if (numberOfUnIndexedWords > 0) { throw new LuceneException("Indexing not done for " + numberOfUnIndexedWords); @@ -380,11 +431,13 @@ public void indexConcepts() throws LuceneException, IllegalArgumentException, Il * This method fetches the concept power by iterating the fieldMap. The * fieldMap contains the search criteria */ - public ConceptEntry[] queryIndex(Map fieldMap, String operator) - throws LuceneException, IllegalAccessException { + public ConceptEntry[] queryIndex(Map fieldMap, String operator, int page, + int numberOfRecordsPerPage) throws LuceneException, IllegalAccessException { + Map analyzerPerField = new HashMap<>(); + if (operator == null) { - operator = "AND"; + operator = SearchParamters.OP_AND; } StringBuffer queryString = new StringBuffer(); @@ -396,13 +449,13 @@ public ConceptEntry[] queryIndex(Map fieldMap, String operator) LuceneField luceneFieldAnnotation = field.getAnnotation(LuceneField.class); if (search != null) { String searchString = fieldMap.get(search.fieldName()); - + if(searchString != null){ if (firstEntry != 1) queryString.append(" " + operator + " "); firstEntry++; queryString.append(luceneFieldAnnotation.lucenefieldName() + ":"); - + StringBuffer searchBuffer = new StringBuffer("("); String[] searchParts = searchString.split(" "); @@ -412,7 +465,7 @@ public ConceptEntry[] queryIndex(Map fieldMap, String operator) searchBuffer.append("+"); } - searchBuffer.append(term + " "); + searchBuffer.append(QueryParser.escape(term) + " "); if (term.startsWith("\"")) { quoteOpen = true; @@ -429,18 +482,51 @@ public ConceptEntry[] queryIndex(Map fieldMap, String operator) } searchBuffer.append(")"); queryString.append(searchBuffer.toString()); + if (!luceneFieldAnnotation.isTokenized()) { + // If the field is not tokenzied, then the field needs + // to be analyzed using a whitespaceanalyzer, rather + // than standard analyzer. This is because for non + // tokenized strings we need exact matches and not all + // the nearest matches. + analyzerPerField.put(luceneFieldAnnotation.lucenefieldName(), whiteSpaceAnalyzer); + } } - + } } + PerFieldAnalyzerWrapper perFieldAnalyzerWrapper = new PerFieldAnalyzerWrapper(standardAnalyzer, + analyzerPerField); + List concepts = new ArrayList(); try { - - Query q = new QueryParser("", whiteSpaceAnalyzer).parse(queryString.toString()); - TopDocs docs = searcher.search(q, numberOfResults); - ScoreDoc[] hits = docs.scoreDocs; + TopScoreDocCollector collector = TopScoreDocCollector.create(numberOfResults); + int startIndex = 0; + int hitsPerPage = 0; + if (page > 0) { + // page number starts with 1. + startIndex = calculateStartIndex(page, numberOfRecordsPerPage); + hitsPerPage = numberOfRecordsPerPage; + } else if (numberOfRecordsPerPage > 0) { + // This condition will be called when user requests with a + // particular number of results and we need to return all the + // page result. Page will be -1 + startIndex = 0; + hitsPerPage = numberOfRecordsPerPage; + } else { + // Fetching results without pagination. + // Start index 0 to end Index --> 100 (default we fetch top 100 + // records) + startIndex = 0; + hitsPerPage = numberOfResults; + } + Query q = new QueryParser("", perFieldAnalyzerWrapper).parse(queryString.toString()); + searcher.search(q, collector); + // If page number is more than the available results, we just pass + // empty result. + TopDocs topDocs = collector.topDocs(startIndex, hitsPerPage); + ScoreDoc[] hits = topDocs.scoreDocs; for (int i = 0; i < hits.length; ++i) { int docId = hits[i].doc; Document d = searcher.doc(docId); @@ -454,10 +540,15 @@ public ConceptEntry[] queryIndex(Map fieldMap, String operator) } catch (ParseException e) { throw new LuceneException("Issues in framing the query", e); } + logger.debug("Number of concepts retrieved from lucene = " + concepts.size()); return concepts.toArray(new ConceptEntry[concepts.size()]); } - + + private int calculateStartIndex(int page, int numberOfRecordsPerPage) { + return (page - 1) * numberOfRecordsPerPage; + } + /** * This method reloads the reader after every update to the index * @@ -473,6 +564,24 @@ private void reloadReader() throws IOException { } } + /** + * This method fetches the wordnet ids associated with the concept wrappers. + * These wordnet ids will not be indexed using lucene. + * + * @param conceptEntries + * @return + */ + private Set getWordNetIdsOfWrappers(List conceptEntries) { + Set wordnetIds = new HashSet<>(); + for (ConceptEntry conceptEntry : conceptEntries) { + if (conceptEntry.getWordnetId() != null && !conceptEntry.getWordnetId().trim().isEmpty()) { + String[] wordNetIds = conceptEntry.getWordnetId().split(","); + wordnetIds.addAll(Arrays.asList(wordNetIds)); + } + } + return wordnetIds; + } + @PreDestroy public void destroy() throws LuceneException { try { diff --git a/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/profile/ISearchResult.java b/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/app/profile/ISearchResult.java similarity index 89% rename from Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/profile/ISearchResult.java rename to Conceptpower+Spring/src/main/java/edu/asu/conceptpower/app/profile/ISearchResult.java index 7b0cbadd2..e738023f1 100644 --- a/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/profile/ISearchResult.java +++ b/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/app/profile/ISearchResult.java @@ -1,4 +1,4 @@ -package edu.asu.conceptpower.servlet.profile; +package edu.asu.conceptpower.app.profile; /** * this interface has methods which are getters and setters for all the diff --git a/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/profile/ISearchResultBackBeanfactory.java b/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/app/profile/ISearchResultBackBeanfactory.java similarity index 76% rename from Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/profile/ISearchResultBackBeanfactory.java rename to Conceptpower+Spring/src/main/java/edu/asu/conceptpower/app/profile/ISearchResultBackBeanfactory.java index a0379bd2b..903bea567 100644 --- a/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/profile/ISearchResultBackBeanfactory.java +++ b/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/app/profile/ISearchResultBackBeanfactory.java @@ -1,6 +1,6 @@ -package edu.asu.conceptpower.servlet.profile; +package edu.asu.conceptpower.app.profile; -import edu.asu.conceptpower.servlet.web.backing.SearchResultBackBean; +import edu.asu.conceptpower.web.backing.SearchResultBackBean; /** * this interface has method which is used for creating new object of diff --git a/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/profile/ISearchResultFactory.java b/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/app/profile/ISearchResultFactory.java similarity index 87% rename from Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/profile/ISearchResultFactory.java rename to Conceptpower+Spring/src/main/java/edu/asu/conceptpower/app/profile/ISearchResultFactory.java index e98a38b98..4eab9b296 100644 --- a/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/profile/ISearchResultFactory.java +++ b/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/app/profile/ISearchResultFactory.java @@ -1,4 +1,4 @@ -package edu.asu.conceptpower.servlet.profile; +package edu.asu.conceptpower.app.profile; /** * this interface has method which creates new object of SearchResult class diff --git a/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/profile/IService.java b/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/app/profile/IService.java similarity index 94% rename from Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/profile/IService.java rename to Conceptpower+Spring/src/main/java/edu/asu/conceptpower/app/profile/IService.java index 353ae1154..29cd336e5 100644 --- a/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/profile/IService.java +++ b/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/app/profile/IService.java @@ -1,4 +1,4 @@ -package edu.asu.conceptpower.servlet.profile; +package edu.asu.conceptpower.app.profile; import java.util.List; diff --git a/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/profile/IServiceFormFactory.java b/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/app/profile/IServiceFormFactory.java similarity index 73% rename from Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/profile/IServiceFormFactory.java rename to Conceptpower+Spring/src/main/java/edu/asu/conceptpower/app/profile/IServiceFormFactory.java index 49a38c4ba..528a4c5ee 100644 --- a/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/profile/IServiceFormFactory.java +++ b/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/app/profile/IServiceFormFactory.java @@ -1,6 +1,6 @@ -package edu.asu.conceptpower.servlet.profile; +package edu.asu.conceptpower.app.profile; -import edu.asu.conceptpower.servlet.profile.impl.ServiceForm; +import edu.asu.conceptpower.app.profile.impl.ServiceForm; /** * this interface has method which creates new object of class ServiceForm diff --git a/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/profile/IServiceRegistry.java b/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/app/profile/IServiceRegistry.java similarity index 94% rename from Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/profile/IServiceRegistry.java rename to Conceptpower+Spring/src/main/java/edu/asu/conceptpower/app/profile/IServiceRegistry.java index bc8dbb63e..a0d8f741b 100644 --- a/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/profile/IServiceRegistry.java +++ b/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/app/profile/IServiceRegistry.java @@ -1,4 +1,4 @@ -package edu.asu.conceptpower.servlet.profile; +package edu.asu.conceptpower.app.profile; import java.util.Map; diff --git a/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/profile/factory/impl/SearchResultFactory.java b/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/app/profile/factory/impl/SearchResultFactory.java similarity index 64% rename from Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/profile/factory/impl/SearchResultFactory.java rename to Conceptpower+Spring/src/main/java/edu/asu/conceptpower/app/profile/factory/impl/SearchResultFactory.java index 401882e28..0179e484d 100644 --- a/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/profile/factory/impl/SearchResultFactory.java +++ b/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/app/profile/factory/impl/SearchResultFactory.java @@ -1,10 +1,10 @@ -package edu.asu.conceptpower.servlet.profile.factory.impl; +package edu.asu.conceptpower.app.profile.factory.impl; import org.springframework.stereotype.Service; -import edu.asu.conceptpower.servlet.profile.ISearchResult; -import edu.asu.conceptpower.servlet.profile.ISearchResultFactory; -import edu.asu.conceptpower.servlet.profile.impl.SearchResult; +import edu.asu.conceptpower.app.profile.ISearchResult; +import edu.asu.conceptpower.app.profile.ISearchResultFactory; +import edu.asu.conceptpower.app.profile.impl.SearchResult; /** * this class has method which creates new object of ISearchResult type diff --git a/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/profile/impl/SearchResult.java b/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/app/profile/impl/SearchResult.java similarity index 84% rename from Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/profile/impl/SearchResult.java rename to Conceptpower+Spring/src/main/java/edu/asu/conceptpower/app/profile/impl/SearchResult.java index 141ba5dfb..529e9f954 100644 --- a/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/profile/impl/SearchResult.java +++ b/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/app/profile/impl/SearchResult.java @@ -1,8 +1,8 @@ -package edu.asu.conceptpower.servlet.profile.impl; +package edu.asu.conceptpower.app.profile.impl; import org.springframework.stereotype.Service; -import edu.asu.conceptpower.servlet.profile.ISearchResult; +import edu.asu.conceptpower.app.profile.ISearchResult; @Service public class SearchResult implements ISearchResult { diff --git a/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/profile/impl/ServiceBackBean.java b/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/app/profile/impl/ServiceBackBean.java similarity index 89% rename from Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/profile/impl/ServiceBackBean.java rename to Conceptpower+Spring/src/main/java/edu/asu/conceptpower/app/profile/impl/ServiceBackBean.java index 58e5b8667..813b4da34 100644 --- a/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/profile/impl/ServiceBackBean.java +++ b/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/app/profile/impl/ServiceBackBean.java @@ -1,4 +1,4 @@ -package edu.asu.conceptpower.servlet.profile.impl; +package edu.asu.conceptpower.app.profile.impl; import org.springframework.stereotype.Service; diff --git a/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/profile/impl/ServiceForm.java b/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/app/profile/impl/ServiceForm.java similarity index 88% rename from Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/profile/impl/ServiceForm.java rename to Conceptpower+Spring/src/main/java/edu/asu/conceptpower/app/profile/impl/ServiceForm.java index 9ab536a3f..729add6a1 100644 --- a/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/profile/impl/ServiceForm.java +++ b/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/app/profile/impl/ServiceForm.java @@ -1,4 +1,4 @@ -package edu.asu.conceptpower.servlet.profile.impl; +package edu.asu.conceptpower.app.profile.impl; import java.util.List; diff --git a/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/profile/impl/ServiceRegistry.java b/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/app/profile/impl/ServiceRegistry.java similarity index 93% rename from Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/profile/impl/ServiceRegistry.java rename to Conceptpower+Spring/src/main/java/edu/asu/conceptpower/app/profile/impl/ServiceRegistry.java index 54a416f5a..f6eaf5cbe 100644 --- a/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/profile/impl/ServiceRegistry.java +++ b/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/app/profile/impl/ServiceRegistry.java @@ -1,4 +1,4 @@ -package edu.asu.conceptpower.servlet.profile.impl; +package edu.asu.conceptpower.app.profile.impl; import java.util.HashMap; import java.util.Iterator; @@ -10,8 +10,8 @@ import org.springframework.context.ApplicationContext; import org.springframework.stereotype.Service; -import edu.asu.conceptpower.servlet.profile.IService; -import edu.asu.conceptpower.servlet.profile.IServiceRegistry; +import edu.asu.conceptpower.app.profile.IService; +import edu.asu.conceptpower.app.profile.IServiceRegistry; /*** * this class registers all the services and creates one time objects for each diff --git a/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/profile/impl/ViafReply.java b/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/app/profile/impl/ViafReply.java similarity index 84% rename from Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/profile/impl/ViafReply.java rename to Conceptpower+Spring/src/main/java/edu/asu/conceptpower/app/profile/impl/ViafReply.java index 5064c3862..c0ef912d7 100644 --- a/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/profile/impl/ViafReply.java +++ b/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/app/profile/impl/ViafReply.java @@ -1,11 +1,11 @@ -package edu.asu.conceptpower.servlet.profile.impl; +package edu.asu.conceptpower.app.profile.impl; import javax.xml.bind.annotation.XmlAccessType; import javax.xml.bind.annotation.XmlAccessorType; import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlRootElement; -import edu.asu.conceptpower.servlet.jaxb.viaf.Channel; +import edu.asu.conceptpower.app.jaxb.viaf.Channel; /** * diff --git a/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/profile/impl/ViafService.java b/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/app/profile/impl/ViafService.java similarity index 90% rename from Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/profile/impl/ViafService.java rename to Conceptpower+Spring/src/main/java/edu/asu/conceptpower/app/profile/impl/ViafService.java index 57616dd9e..c76b2aa49 100644 --- a/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/profile/impl/ViafService.java +++ b/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/app/profile/impl/ViafService.java @@ -1,4 +1,4 @@ -package edu.asu.conceptpower.servlet.profile.impl; +package edu.asu.conceptpower.app.profile.impl; import java.util.ArrayList; import java.util.List; @@ -11,10 +11,10 @@ import org.springframework.stereotype.Service; import org.springframework.web.client.RestTemplate; -import edu.asu.conceptpower.servlet.jaxb.viaf.Item; -import edu.asu.conceptpower.servlet.profile.ISearchResult; -import edu.asu.conceptpower.servlet.profile.ISearchResultFactory; -import edu.asu.conceptpower.servlet.profile.IService; +import edu.asu.conceptpower.app.jaxb.viaf.Item; +import edu.asu.conceptpower.app.profile.ISearchResult; +import edu.asu.conceptpower.app.profile.ISearchResultFactory; +import edu.asu.conceptpower.app.profile.IService; /** * this class contains methods which connects quadriga to viaf authority service diff --git a/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/app/rdf/RDFMessageFactory.java b/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/app/rdf/RDFMessageFactory.java new file mode 100644 index 000000000..9b4ced931 --- /dev/null +++ b/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/app/rdf/RDFMessageFactory.java @@ -0,0 +1,146 @@ +package edu.asu.conceptpower.app.rdf; + +import java.io.StringWriter; +import java.util.HashMap; +import java.util.Map; + +import org.apache.jena.rdf.model.Model; +import org.apache.jena.rdf.model.ModelFactory; +import org.apache.jena.rdf.model.Property; +import org.apache.jena.rdf.model.Resource; +import org.apache.jena.vocabulary.RDF; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +import edu.asu.conceptpower.app.db.TypeDatabaseClient; +import edu.asu.conceptpower.app.util.URIHelper; +import edu.asu.conceptpower.core.ConceptEntry; + +/** + * + * @author karthikeyanmohan + * + */ +@Component +public class RDFMessageFactory { + + @Autowired + private TypeDatabaseClient typeManager; + + @Autowired + private URIHelper creator; + + private final String madsrdf = "http://www.loc.gov/mads/rdf/v1#"; + private final String rdf = "http://www.w3.org/1999/02/22-rdf-syntax-ns#"; + private final String cidocCrm = "http://www.cidoc-crm.org/cidoc-crm/"; + private final String dCTerms = "http://purl.org/dc/terms/"; + private final String schema = "http://schema.org/"; + private final String changeset = "http://purl.org/vocab/changeset/schema#"; + private final String owl = "http://www.w3.org/2002/07/owl#"; + private final String skos = "http://www.w3.org/2008/05/skos#"; + private final String skosType = "http://www.w3.org/2008/05/skos#Concept"; + private final String authorityType = "http://www.loc.gov/mads/rdf/v1#Authority"; + + public String generateRDF(ConceptEntry[] entries) { + Model model = ModelFactory.createDefaultModel(); + String syntax = "RDF/XML"; + StringWriter out = new StringWriter(); + model.setNsPrefixes(getPrefixMap()); + Property identifiers = model.createProperty(dCTerms + "identifiers"); + Property madsrdfProperty = model.createProperty(madsrdf + "authoritativeLabel"); + Property skosProperty = model.createProperty(skos + "prefLabel"); + Property schemaName = model.createProperty(schema + "name"); + Property schemaDescription = model.createProperty(schema + "description"); + Property madsrdfCL = model.createProperty(madsrdf + "isMemberOfMADSCollection"); + Property csCreator = model.createProperty(changeset + "creatorName"); + Property owlEqualTo = model.createProperty(owl + "sameAs"); + Property rdfsSeeAlso = model.createProperty(rdf + "seeAlso"); + Property skosRelated = model.createProperty(skos + "related"); + + for (ConceptEntry entry : entries) { + + Resource resource = model.createResource(creator.getURI(entry)); + + resource.addProperty(identifiers, entry.getId()); + resource.addProperty(madsrdfProperty, entry.getWord()); + resource.addProperty(skosProperty, entry.getWord()); + resource.addProperty(schemaName, entry.getWord()); + resource.addProperty(schemaDescription, entry.getDescription()); + + if (entry.getConceptList() != null) { + resource.addProperty(madsrdfCL, creator.getConceptListURI(entry)); + } + + if (entry.getCreatorId() != null) { + resource.addProperty(csCreator, entry.getCreatorId()); + } + + if (entry.getModified() != null) { + resource.addProperty(csCreator, entry.getCreatorId()); + } + + if (entry.getEqualTo() != null) { + String[] equals = entry.getEqualTo().split(","); + for (String equal : equals) { + resource.addProperty(owlEqualTo, equal); + } + } + + if (entry.getSimilarTo() != null) { + String[] similarTo = entry.getSimilarTo().split(","); + for (String similar : similarTo) { + resource.addProperty(rdfsSeeAlso, similar); + } + } + + if (entry.getWordnetId() != null) { + resource.addProperty(owlEqualTo, creator.getWordnetURI(entry)); + } + + if (entry.getSynonymIds() != null) { + String[] synonymIds = entry.getSynonymIds() + .split(edu.asu.conceptpower.app.core.Constants.SYNONYM_SEPARATOR); + for (String synonymId : synonymIds) { + resource.addProperty(skosRelated, synonymId); + } + } + + Resource typeResource = model.createResource(skosType); + resource.addProperty(RDF.type, typeResource); + + Resource typeRes = model.createResource(authorityType); + resource.addProperty(RDF.type, typeRes); + + if (entry.getTypeId() != null) { + Resource typesRes = model.createResource(creator.getTypeURI(entry)); + resource.addProperty(RDF.type, typesRes); + } + + String matchesURI = entry.getTypeId(); + if (matchesURI != null) { + String matches = typeManager.getType(matchesURI).getMatches(); + if (matches != null && !matches.equalsIgnoreCase("")) { + Resource cdocResource = model.createResource(matches); + resource.addProperty(RDF.type, cdocResource); + } + } + + } + model.write(out, syntax); + return out.toString(); + } + + private Map getPrefixMap() { + Map prefixMap = new HashMap(); + prefixMap.put("skos", skos); + prefixMap.put("madsrdf", madsrdf); + prefixMap.put("dcterms", dCTerms); + prefixMap.put("schema", schema); + prefixMap.put("cs", changeset); + prefixMap.put("owl", owl); + prefixMap.put("cidoccrm", cidocCrm); + prefixMap.put("rdf", rdf); + return prefixMap; + } + +} diff --git a/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/reflect/LuceneField.java b/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/app/reflect/LuceneField.java similarity index 75% rename from Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/reflect/LuceneField.java rename to Conceptpower+Spring/src/main/java/edu/asu/conceptpower/app/reflect/LuceneField.java index daa10fcc0..d382eb170 100644 --- a/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/reflect/LuceneField.java +++ b/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/app/reflect/LuceneField.java @@ -1,4 +1,4 @@ -package edu.asu.conceptpower.servlet.reflect; +package edu.asu.conceptpower.app.reflect; import java.lang.annotation.ElementType; import java.lang.annotation.Retention; @@ -10,5 +10,6 @@ public @interface LuceneField { String lucenefieldName(); - boolean isIndexable(); + boolean isTokenized(); + boolean isMultiple(); } diff --git a/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/reflect/SearchField.java b/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/app/reflect/SearchField.java similarity index 85% rename from Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/reflect/SearchField.java rename to Conceptpower+Spring/src/main/java/edu/asu/conceptpower/app/reflect/SearchField.java index c4103a79f..b21057de0 100644 --- a/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/reflect/SearchField.java +++ b/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/app/reflect/SearchField.java @@ -1,4 +1,4 @@ -package edu.asu.conceptpower.servlet.reflect; +package edu.asu.conceptpower.app.reflect; import java.lang.annotation.ElementType; import java.lang.annotation.Retention; diff --git a/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/service/IAuthorityFileSearch.java b/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/app/service/IAuthorityFileSearch.java similarity index 86% rename from Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/service/IAuthorityFileSearch.java rename to Conceptpower+Spring/src/main/java/edu/asu/conceptpower/app/service/IAuthorityFileSearch.java index 50b02108a..05290cb32 100644 --- a/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/service/IAuthorityFileSearch.java +++ b/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/app/service/IAuthorityFileSearch.java @@ -1,8 +1,8 @@ -package edu.asu.conceptpower.servlet.service; +package edu.asu.conceptpower.app.service; import java.util.List; -import edu.asu.conceptpower.servlet.profile.ISearchResult; +import edu.asu.conceptpower.app.profile.ISearchResult; /** * the interface has methods which are used to copy all the contents from diff --git a/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/app/service/IConceptMergeService.java b/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/app/service/IConceptMergeService.java new file mode 100644 index 000000000..b17ef5398 --- /dev/null +++ b/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/app/service/IConceptMergeService.java @@ -0,0 +1,19 @@ +package edu.asu.conceptpower.app.service; + +import java.util.List; + +import edu.asu.conceptpower.app.bean.ConceptsMergeBean; +import edu.asu.conceptpower.app.exceptions.DictionaryDoesNotExistException; +import edu.asu.conceptpower.app.exceptions.DictionaryModifyException; +import edu.asu.conceptpower.app.exceptions.IndexerRunningException; +import edu.asu.conceptpower.app.exceptions.LuceneException; +import edu.asu.conceptpower.core.ConceptEntry; + +public interface IConceptMergeService { + public ConceptsMergeBean prepareMergeConcepts(List conceptEntries, + ConceptsMergeBean mergeConceptsBean); + + public void mergeConcepts(ConceptsMergeBean conceptsMergeBean, String userName) throws LuceneException, + IndexerRunningException, IllegalAccessException, DictionaryDoesNotExistException, DictionaryModifyException; + +} diff --git a/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/service/IEmailService.java b/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/app/service/IEmailService.java similarity index 79% rename from Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/service/IEmailService.java rename to Conceptpower+Spring/src/main/java/edu/asu/conceptpower/app/service/IEmailService.java index 99c001333..22075089d 100644 --- a/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/service/IEmailService.java +++ b/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/app/service/IEmailService.java @@ -1,4 +1,4 @@ -package edu.asu.conceptpower.servlet.service; +package edu.asu.conceptpower.app.service; public interface IEmailService { diff --git a/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/service/impl/AuthorityFileSearch.java b/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/app/service/impl/AuthorityFileSearch.java similarity index 74% rename from Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/service/impl/AuthorityFileSearch.java rename to Conceptpower+Spring/src/main/java/edu/asu/conceptpower/app/service/impl/AuthorityFileSearch.java index c5016f7c0..526f4684e 100644 --- a/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/service/impl/AuthorityFileSearch.java +++ b/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/app/service/impl/AuthorityFileSearch.java @@ -1,4 +1,4 @@ -package edu.asu.conceptpower.servlet.service.impl; +package edu.asu.conceptpower.app.service.impl; import java.util.ArrayList; import java.util.List; @@ -6,11 +6,11 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; -import edu.asu.conceptpower.servlet.profile.ISearchResult; -import edu.asu.conceptpower.servlet.profile.IService; -import edu.asu.conceptpower.servlet.profile.IServiceRegistry; -import edu.asu.conceptpower.servlet.service.IAuthorityFileSearch; -import edu.asu.conceptpower.servlet.web.backing.SearchResultBackBean; +import edu.asu.conceptpower.app.profile.ISearchResult; +import edu.asu.conceptpower.app.profile.IService; +import edu.asu.conceptpower.app.profile.IServiceRegistry; +import edu.asu.conceptpower.app.service.IAuthorityFileSearch; +import edu.asu.conceptpower.web.backing.SearchResultBackBean; /** * This class query a specified service and returns the results. diff --git a/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/app/service/impl/ConceptMergeService.java b/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/app/service/impl/ConceptMergeService.java new file mode 100644 index 000000000..5fdea6bb5 --- /dev/null +++ b/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/app/service/impl/ConceptMergeService.java @@ -0,0 +1,194 @@ +package edu.asu.conceptpower.app.service.impl; + +import java.util.Arrays; +import java.util.List; +import java.util.stream.Collectors; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import edu.asu.conceptpower.app.bean.ConceptsMergeBean; +import edu.asu.conceptpower.app.core.IConceptManager; +import edu.asu.conceptpower.app.core.IConceptTypesService; +import edu.asu.conceptpower.app.core.IConceptTypesService.IdType; +import edu.asu.conceptpower.app.error.CPError; +import edu.asu.conceptpower.app.exceptions.DictionaryDoesNotExistException; +import edu.asu.conceptpower.app.exceptions.DictionaryModifyException; +import edu.asu.conceptpower.app.exceptions.IndexerRunningException; +import edu.asu.conceptpower.app.exceptions.LuceneException; +import edu.asu.conceptpower.app.service.IConceptMergeService; +import edu.asu.conceptpower.core.ConceptEntry; + +@Service +public class ConceptMergeService implements IConceptMergeService { + + @Autowired + private IConceptManager conceptManager; + + @Autowired + private IConceptTypesService conceptTypesService; + + @Override + public ConceptsMergeBean prepareMergeConcepts(List conceptEntries, + ConceptsMergeBean conceptsMergeBean) { + boolean typeWarning = false; + boolean posWarning = false; + conceptsMergeBean.clear(); + for (ConceptEntry entry : conceptEntries) { + if (entry.getWord() != null && !entry.getWord().isEmpty()) { + conceptsMergeBean.setWord(conceptsMergeBean.getWord() == null + || conceptsMergeBean.getWord().length() < entry.getWord().length() ? entry.getWord() + : conceptsMergeBean.getWord()); + } + + if (conceptsMergeBean.getSelectedPosValue() == null) { + conceptsMergeBean.setSelectedPosValue(entry.getPos().toLowerCase()); + } else if (!conceptsMergeBean.getSelectedPosValue().equalsIgnoreCase(entry.getPos())) { + posWarning = true; + } + + if (entry.getDescription() != null && !entry.getDescription().isEmpty()) { + conceptsMergeBean.getDescriptions().add(entry.getDescription().trim()); + } + + if (entry.getSynonymIds() != null && !entry.getSynonymIds().isEmpty()) { + conceptsMergeBean.getSynonymsids().addAll(Arrays.asList(entry.getSynonymIds().split(","))); + } + + if (entry.getEqualTo() != null && !entry.getEqualTo().isEmpty()) { + conceptsMergeBean.getEqualsValues().add(entry.getEqualTo()); + } + if (entry.getSimilarTo() != null && !entry.getSimilarTo().isEmpty()) { + conceptsMergeBean.getSimilarValues().add(entry.getSimilarTo()); + } + + if (entry.getTypeId() != null && conceptsMergeBean.getSelectedTypeId() == null) { + conceptsMergeBean.setSelectedTypeId(entry.getTypeId()); + } else if (entry.getTypeId() != null + && !entry.getTypeId().equalsIgnoreCase(conceptsMergeBean.getSelectedTypeId())) { + typeWarning = true; + } + + conceptsMergeBean.getMergeIds().add(entry.getId()); + + if (IdType.LOCAL_CONCEPT_ID == conceptTypesService.getConceptTypeByConceptId(entry.getId())) { + if(entry.getWordnetId() != null) { + conceptsMergeBean.getAlternativeIds().addAll(Arrays.asList(entry.getWordnetId().split(","))); + } + } + conceptsMergeBean.getAlternativeIds().add(entry.getId()); + if (!entry.getAlternativeIds().isEmpty()) { + conceptsMergeBean.getAlternativeIds().addAll(entry.getAlternativeIds()); + } + } + + if (posWarning) { + CPError errroMessage = new CPError("error_message_101"); + conceptsMergeBean.getErrorMessages().add(errroMessage); + } + + if (typeWarning) { + CPError errroMessage = new CPError("error_message_102"); + conceptsMergeBean.getErrorMessages().add(errroMessage); + } + + // By default new id will be created + conceptsMergeBean.setSelectedConceptId(""); + conceptsMergeBean.setSelectedListName(""); + + // Removing all the wordnet ids from this list. Users can merge into any + // of the user defined CCP id or can create a new id for the merging + // concepts. As per design cannot merge into wordnet id, because wordnet + // id concepts cannot be updated. + + return conceptsMergeBean; + } + + @Override + public void mergeConcepts(ConceptsMergeBean conceptsMergeBean, String userName) + throws LuceneException, IndexerRunningException, IllegalAccessException, DictionaryDoesNotExistException, + DictionaryModifyException { + + if (conceptsMergeBean.getSelectedConceptId().trim().equals("")) { + // Add + ConceptEntry entry = new ConceptEntry(); + fillConceptEntry(entry, conceptsMergeBean); + conceptManager.addConceptListEntry(entry, userName); + } else { + // Update + ConceptEntry entry = conceptManager.getConceptEntry(conceptsMergeBean.getSelectedConceptId()); + fillConceptEntry(entry, conceptsMergeBean); + conceptManager.storeModifiedConcept(entry, userName); + } + + deleteMergedConcepts(userName, conceptsMergeBean); + } + + private void deleteMergedConcepts(String userName, ConceptsMergeBean conceptsMergeBean) + throws LuceneException, IndexerRunningException, IllegalAccessException, + DictionaryDoesNotExistException, DictionaryModifyException { + + for (String id : conceptsMergeBean.getMergeIds()) { + if (IdType.SPECIFIC_WORDNET_CONCEPT_ID == conceptTypesService.getConceptTypeByConceptId(id)) { + // If its a wordnet concept, then create a wrapper and set + // the delete flag to true. This is done in two steps + // because changeevent object needs to be updated for + // deletion correctly. + String conceptWrapperId = createConceptWrapperById(id, userName, conceptsMergeBean); + conceptManager.deleteConcept(conceptWrapperId, userName); + } else if (!id.equalsIgnoreCase(conceptsMergeBean.getSelectedConceptId().trim())) { + conceptManager.deleteConcept(id, userName); + } + } + } + + private String createConceptWrapperById(String wrapperId, String userName, ConceptsMergeBean conceptsMergeBean) + throws IllegalAccessException, DictionaryDoesNotExistException, DictionaryModifyException, LuceneException, + IndexerRunningException { + ConceptEntry entry = conceptManager.getConceptEntry(wrapperId); + // Creating concept wrapper with all the values, because in future we + // will be including manipulations on deleted wrappers as well. + // WrapperId has been added to delete the wordnet id. If this wordnet + // id is not deleted, then the merged wordnet id will be appearing on + // concept search screen. If WID-1 and WID-2 are merged, then each time + // we create a wrapper for WID-1 and WID-2, we need to have WID-1 and + // WID-2 in wordnet id field to be deleted. + entry.setConceptList(conceptsMergeBean.getSelectedListName()); + return conceptManager.addConceptListEntry(entry, userName); + } + + private void fillConceptEntry(ConceptEntry entry, ConceptsMergeBean conceptMergeBean) { + entry.setPos(conceptMergeBean.getSelectedPosValue()); + entry.setConceptList(conceptMergeBean.getSelectedListName()); + entry.setTypeId(conceptMergeBean.getSelectedTypeId()); + + String prefix = ","; + entry.setWord(conceptMergeBean.getWord()); + + String description = conceptMergeBean.getDescriptions().stream().map(i -> i.toString().trim()) + .collect(Collectors.joining(" ")); + entry.setDescription(description.trim().replaceAll("\\s+", " ")); + + String synonymIds = conceptMergeBean.getSynonymsids().stream().map(i -> i.toString()) + .collect(Collectors.joining(prefix)); + entry.setSynonymIds(synonymIds); + + String equals = conceptMergeBean.getEqualsValues().stream().map(i -> i.toString()) + .collect(Collectors.joining(prefix)); + entry.setEqualTo(equals); + + String similar = conceptMergeBean.getSimilarValues().stream().map(i -> i.toString()) + .collect(Collectors.joining(prefix)); + entry.setSimilarTo(similar); + + if (entry.getAlternativeIds() != null) { + entry.getAlternativeIds().addAll(conceptMergeBean.getAlternativeIds()); + } else { + entry.setAlternativeIds(conceptMergeBean.getAlternativeIds()); + } + + entry.setMergedIds(conceptMergeBean.getMergeIds().stream().collect(Collectors.joining(","))); + + } + +} diff --git a/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/service/impl/EmailService.java b/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/app/service/impl/EmailService.java similarity index 87% rename from Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/service/impl/EmailService.java rename to Conceptpower+Spring/src/main/java/edu/asu/conceptpower/app/service/impl/EmailService.java index 7a0719685..3f13e7c0f 100644 --- a/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/service/impl/EmailService.java +++ b/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/app/service/impl/EmailService.java @@ -1,11 +1,11 @@ -package edu.asu.conceptpower.servlet.service.impl; +package edu.asu.conceptpower.app.service.impl; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.mail.MailSender; import org.springframework.mail.SimpleMailMessage; import org.springframework.stereotype.Service; -import edu.asu.conceptpower.servlet.service.IEmailService; +import edu.asu.conceptpower.app.service.IEmailService; @Service public class EmailService implements IEmailService { diff --git a/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/root/CPUserDetails.java b/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/app/users/CPUserDetails.java similarity index 93% rename from Conceptpower+Spring/src/main/java/edu/asu/conceptpower/root/CPUserDetails.java rename to Conceptpower+Spring/src/main/java/edu/asu/conceptpower/app/users/CPUserDetails.java index 0125cc2a6..bae8ae17f 100644 --- a/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/root/CPUserDetails.java +++ b/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/app/users/CPUserDetails.java @@ -1,4 +1,4 @@ -package edu.asu.conceptpower.root; +package edu.asu.conceptpower.app.users; import java.util.Collection; import java.util.List; @@ -6,8 +6,6 @@ import org.springframework.security.core.GrantedAuthority; import org.springframework.security.core.userdetails.UserDetails; -import edu.asu.conceptpower.servlet.users.ConceptpowerGrantedAuthority; - /** * UserDetails implementation for Conceptpower. * @author Julia Damerow diff --git a/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/users/ConceptpowerGrantedAuthority.java b/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/app/users/ConceptpowerGrantedAuthority.java similarity index 93% rename from Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/users/ConceptpowerGrantedAuthority.java rename to Conceptpower+Spring/src/main/java/edu/asu/conceptpower/app/users/ConceptpowerGrantedAuthority.java index 92eafa04e..9481ddfd1 100644 --- a/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/users/ConceptpowerGrantedAuthority.java +++ b/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/app/users/ConceptpowerGrantedAuthority.java @@ -1,4 +1,4 @@ -package edu.asu.conceptpower.servlet.users; +package edu.asu.conceptpower.app.users; import org.springframework.security.core.GrantedAuthority; diff --git a/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/users/IUserManager.java b/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/app/users/IUserManager.java similarity index 95% rename from Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/users/IUserManager.java rename to Conceptpower+Spring/src/main/java/edu/asu/conceptpower/app/users/IUserManager.java index f071c2fde..8fb10c316 100644 --- a/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/users/IUserManager.java +++ b/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/app/users/IUserManager.java @@ -1,4 +1,4 @@ -package edu.asu.conceptpower.servlet.users; +package edu.asu.conceptpower.app.users; import java.util.Map; diff --git a/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/users/Token.java b/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/app/users/Token.java similarity index 94% rename from Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/users/Token.java rename to Conceptpower+Spring/src/main/java/edu/asu/conceptpower/app/users/Token.java index c76687a5d..72fa0ea5a 100644 --- a/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/users/Token.java +++ b/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/app/users/Token.java @@ -1,4 +1,4 @@ -package edu.asu.conceptpower.servlet.users; +package edu.asu.conceptpower.app.users; import java.util.Date; diff --git a/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/root/UserDatabaseClient.java b/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/app/users/UserDatabaseClient.java similarity index 96% rename from Conceptpower+Spring/src/main/java/edu/asu/conceptpower/root/UserDatabaseClient.java rename to Conceptpower+Spring/src/main/java/edu/asu/conceptpower/app/users/UserDatabaseClient.java index 2ec61e8b4..fb43d8c37 100644 --- a/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/root/UserDatabaseClient.java +++ b/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/app/users/UserDatabaseClient.java @@ -1,4 +1,4 @@ -package edu.asu.conceptpower.root; +package edu.asu.conceptpower.app.users; import java.util.List; @@ -11,7 +11,7 @@ import com.db4o.ObjectContainer; import com.db4o.ObjectSet; -import edu.asu.conceptpower.servlet.users.Token; +import edu.asu.conceptpower.app.db.DatabaseManager; import edu.asu.conceptpower.users.User; @Component diff --git a/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/root/UserService.java b/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/app/users/UserService.java similarity index 89% rename from Conceptpower+Spring/src/main/java/edu/asu/conceptpower/root/UserService.java rename to Conceptpower+Spring/src/main/java/edu/asu/conceptpower/app/users/UserService.java index ddf02bfef..f550fd692 100644 --- a/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/root/UserService.java +++ b/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/app/users/UserService.java @@ -1,4 +1,4 @@ -package edu.asu.conceptpower.root; +package edu.asu.conceptpower.app.users; import java.util.ArrayList; import java.util.List; @@ -9,8 +9,6 @@ import org.springframework.security.core.userdetails.UsernameNotFoundException; import org.springframework.stereotype.Service; -import edu.asu.conceptpower.servlet.users.ConceptpowerGrantedAuthority; -import edu.asu.conceptpower.servlet.users.IUserManager; import edu.asu.conceptpower.users.User; @Service("userService") diff --git a/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/root/UsersManager.java b/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/app/users/UsersManager.java similarity index 97% rename from Conceptpower+Spring/src/main/java/edu/asu/conceptpower/root/UsersManager.java rename to Conceptpower+Spring/src/main/java/edu/asu/conceptpower/app/users/UsersManager.java index 9d6cb73f7..0738247e3 100644 --- a/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/root/UsersManager.java +++ b/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/app/users/UsersManager.java @@ -1,4 +1,4 @@ -package edu.asu.conceptpower.root; +package edu.asu.conceptpower.app.users; import java.io.IOException; import java.util.ArrayList; @@ -19,8 +19,6 @@ import org.springframework.security.crypto.bcrypt.BCrypt; import org.springframework.stereotype.Service; -import edu.asu.conceptpower.servlet.users.IUserManager; -import edu.asu.conceptpower.servlet.users.Token; import edu.asu.conceptpower.users.User; /** diff --git a/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/root/IURIHelper.java b/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/app/util/IURIHelper.java similarity index 87% rename from Conceptpower+Spring/src/main/java/edu/asu/conceptpower/root/IURIHelper.java rename to Conceptpower+Spring/src/main/java/edu/asu/conceptpower/app/util/IURIHelper.java index 40f986f7c..39452eea3 100644 --- a/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/root/IURIHelper.java +++ b/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/app/util/IURIHelper.java @@ -1,4 +1,4 @@ -package edu.asu.conceptpower.root; +package edu.asu.conceptpower.app.util; import edu.asu.conceptpower.core.ConceptEntry; import edu.asu.conceptpower.core.ConceptType; diff --git a/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/app/util/URIHelper.java b/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/app/util/URIHelper.java new file mode 100644 index 000000000..64330b66d --- /dev/null +++ b/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/app/util/URIHelper.java @@ -0,0 +1,70 @@ +package edu.asu.conceptpower.app.util; + +import java.util.HashMap; +import java.util.Map; +import java.util.Set; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import edu.asu.conceptpower.app.config.XMLConfig; +import edu.asu.conceptpower.core.ConceptEntry; +import edu.asu.conceptpower.core.ConceptType; +import edu.asu.conceptpower.rest.msg.xml.XMLConstants; + +/** + * This class creates URIs for concepts and types based on the in xml-config.xml + * configured URI prefixes. + */ +@Service +public class URIHelper implements IURIHelper { + + @Autowired + private XMLConfig xmlConfig; + + public String getURI(ConceptEntry entry) { + + String uriPrefix = xmlConfig.getUriPrefix(); + + if (entry.getId() != null && !entry.getId().isEmpty()) + return uriPrefix + entry.getId(); + + else + return uriPrefix + entry.getWordnetId(); + } + + public String getTypeURI(ConceptType type) { + return XMLConstants.TYPE_NAMESPACE + XMLConstants.TYPE_PREFIX + type.getTypeId(); + } + + public String getTypeURI(ConceptEntry entry) { + return XMLConstants.TYPE_NAMESPACE + XMLConstants.TYPE_PREFIX + entry.getTypeId(); + } + + public String getTypeId(String typeUriOrId) { + if (!typeUriOrId.startsWith(XMLConstants.TYPE_NAMESPACE + XMLConstants.TYPE_PREFIX)) { + return typeUriOrId; + } + + return typeUriOrId.substring((XMLConstants.TYPE_NAMESPACE + XMLConstants.TYPE_PREFIX).length()); + } + + public String getConceptListURI(ConceptEntry entry) { + String list = entry.getConceptList(); + return XMLConstants.LIST_NAMESPACE + list; + } + + public String getWordnetURI(ConceptEntry entry) { + String wordnetId = entry.getWordnetId(); + return XMLConstants.WORDNET_NAMESPACE + wordnetId; + } + + public Map getUrisBasedOnIds(Set ids) { + Map uriPrefixes = new HashMap<>(); + String uriPrefix = xmlConfig.getUriPrefix(); + for (String id : ids) { + uriPrefixes.put(id, uriPrefix + id); + } + return uriPrefixes; + } +} diff --git a/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/app/validation/ConceptAddValidator.java b/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/app/validation/ConceptAddValidator.java new file mode 100644 index 000000000..edfc64b18 --- /dev/null +++ b/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/app/validation/ConceptAddValidator.java @@ -0,0 +1,28 @@ +package edu.asu.conceptpower.app.validation; + +import org.springframework.stereotype.Component; + +import org.springframework.validation.Errors; +import org.springframework.validation.ValidationUtils; +import org.springframework.validation.Validator; + +import edu.asu.conceptpower.app.profile.impl.ServiceBackBean; +import edu.asu.conceptpower.web.backing.ConceptAddBean; + +@Component +public class ConceptAddValidator implements Validator { + + @Override + public boolean supports(Class arg0) { + return arg0.isAssignableFrom(ConceptAddBean.class) || arg0.isAssignableFrom(ServiceBackBean.class); + } + + @Override + public void validate(Object target, Errors errors) { + ValidationUtils.rejectIfEmptyOrWhitespace(errors, "name", "concept_name.required"); + ValidationUtils.rejectIfEmptyOrWhitespace(errors, "pos", "pos.required"); + ValidationUtils.rejectIfEmptyOrWhitespace(errors, "selectedList", "list.required"); + ValidationUtils.rejectIfEmptyOrWhitespace(errors, "selectedTypes", "types.required"); + } + +} diff --git a/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/validation/ConceptListAddValidator.java b/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/app/validation/ConceptListAddValidator.java similarity index 82% rename from Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/validation/ConceptListAddValidator.java rename to Conceptpower+Spring/src/main/java/edu/asu/conceptpower/app/validation/ConceptListAddValidator.java index 20af39a18..b08c13285 100644 --- a/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/validation/ConceptListAddValidator.java +++ b/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/app/validation/ConceptListAddValidator.java @@ -1,4 +1,4 @@ -package edu.asu.conceptpower.servlet.validation; +package edu.asu.conceptpower.app.validation; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; @@ -6,9 +6,9 @@ import org.springframework.validation.ValidationUtils; import org.springframework.validation.Validator; -import edu.asu.conceptpower.servlet.core.IConceptListManager; -import edu.asu.conceptpower.servlet.web.ConceptListAddForm; -import edu.asu.conceptpower.servlet.wordnet.Constants; +import edu.asu.conceptpower.app.core.IConceptListManager; +import edu.asu.conceptpower.app.wordnet.Constants; +import edu.asu.conceptpower.web.ConceptListAddForm; @Component public class ConceptListAddValidator implements Validator { @@ -30,7 +30,7 @@ public void validate(Object target, Errors errors) { if (!errors.hasErrors()) { ConceptListAddForm conceptListAddForm = (ConceptListAddForm) target; if (conceptListAddForm.getListName().equals(Constants.WORDNET_DICTIONARY)) { - errors.rejectValue("listName", "concept_name.wordnet"); + errors.rejectValue("listName", "concept_list_name.wordnet"); } if (!conceptListAddForm.getListName().equalsIgnoreCase(conceptListAddForm.getOldListName())) { diff --git a/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/validation/ConceptSearchValidator.java b/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/app/validation/ConceptSearchValidator.java similarity index 85% rename from Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/validation/ConceptSearchValidator.java rename to Conceptpower+Spring/src/main/java/edu/asu/conceptpower/app/validation/ConceptSearchValidator.java index 8a6f797fd..64121899b 100644 --- a/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/validation/ConceptSearchValidator.java +++ b/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/app/validation/ConceptSearchValidator.java @@ -1,11 +1,11 @@ -package edu.asu.conceptpower.servlet.validation; +package edu.asu.conceptpower.app.validation; import org.springframework.stereotype.Component; import org.springframework.validation.Errors; import org.springframework.validation.ValidationUtils; import org.springframework.validation.Validator; -import edu.asu.conceptpower.servlet.web.ConceptSearchBean; +import edu.asu.conceptpower.web.ConceptSearchBean; @Component public class ConceptSearchValidator implements Validator { diff --git a/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/validation/ConceptTypeAddValidator.java b/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/app/validation/ConceptTypeAddValidator.java similarity index 90% rename from Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/validation/ConceptTypeAddValidator.java rename to Conceptpower+Spring/src/main/java/edu/asu/conceptpower/app/validation/ConceptTypeAddValidator.java index 6ca5db97a..1a71ca22f 100644 --- a/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/validation/ConceptTypeAddValidator.java +++ b/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/app/validation/ConceptTypeAddValidator.java @@ -1,4 +1,4 @@ -package edu.asu.conceptpower.servlet.validation; +package edu.asu.conceptpower.app.validation; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; @@ -6,8 +6,8 @@ import org.springframework.validation.ValidationUtils; import org.springframework.validation.Validator; -import edu.asu.conceptpower.root.TypeDatabaseClient; -import edu.asu.conceptpower.servlet.web.ConceptTypeAddForm; +import edu.asu.conceptpower.app.db.TypeDatabaseClient; +import edu.asu.conceptpower.web.ConceptTypeAddForm; /** * This class provides methods for validating name, description for concept diff --git a/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/validation/EmailValidator.java b/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/app/validation/EmailValidator.java similarity index 92% rename from Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/validation/EmailValidator.java rename to Conceptpower+Spring/src/main/java/edu/asu/conceptpower/app/validation/EmailValidator.java index c8255396f..260c1d40d 100644 --- a/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/validation/EmailValidator.java +++ b/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/app/validation/EmailValidator.java @@ -1,13 +1,13 @@ -package edu.asu.conceptpower.servlet.validation; +package edu.asu.conceptpower.app.validation; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; import org.springframework.validation.Errors; import org.springframework.validation.Validator; -import edu.asu.conceptpower.servlet.users.IUserManager; -import edu.asu.conceptpower.servlet.web.backing.UserBacking; +import edu.asu.conceptpower.app.users.IUserManager; import edu.asu.conceptpower.users.User; +import edu.asu.conceptpower.web.backing.UserBacking; @Component public class EmailValidator implements Validator { diff --git a/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/validation/UserValidator.java b/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/app/validation/UserValidator.java similarity index 95% rename from Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/validation/UserValidator.java rename to Conceptpower+Spring/src/main/java/edu/asu/conceptpower/app/validation/UserValidator.java index 274f6c9b9..2792d594a 100644 --- a/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/validation/UserValidator.java +++ b/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/app/validation/UserValidator.java @@ -1,12 +1,12 @@ -package edu.asu.conceptpower.servlet.validation; +package edu.asu.conceptpower.app.validation; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; import org.springframework.validation.Errors; import org.springframework.validation.Validator; -import edu.asu.conceptpower.servlet.users.IUserManager; -import edu.asu.conceptpower.servlet.web.backing.UserBacking; +import edu.asu.conceptpower.app.users.IUserManager; +import edu.asu.conceptpower.web.backing.UserBacking; @Component public class UserValidator implements Validator { diff --git a/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/validation/ValuesMatch.java b/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/app/validation/ValuesMatch.java similarity index 93% rename from Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/validation/ValuesMatch.java rename to Conceptpower+Spring/src/main/java/edu/asu/conceptpower/app/validation/ValuesMatch.java index f5e35c5af..9a90030dc 100644 --- a/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/validation/ValuesMatch.java +++ b/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/app/validation/ValuesMatch.java @@ -1,4 +1,4 @@ -package edu.asu.conceptpower.servlet.validation; +package edu.asu.conceptpower.app.validation; import java.lang.annotation.ElementType; import java.lang.annotation.Retention; diff --git a/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/validation/ValuesMatchValidator.java b/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/app/validation/ValuesMatchValidator.java similarity index 98% rename from Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/validation/ValuesMatchValidator.java rename to Conceptpower+Spring/src/main/java/edu/asu/conceptpower/app/validation/ValuesMatchValidator.java index e0acb670e..8af66b446 100644 --- a/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/validation/ValuesMatchValidator.java +++ b/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/app/validation/ValuesMatchValidator.java @@ -1,4 +1,4 @@ -package edu.asu.conceptpower.servlet.validation; +package edu.asu.conceptpower.app.validation; import java.lang.reflect.InvocationTargetException; diff --git a/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/wordnet/Constants.java b/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/app/wordnet/Constants.java similarity index 76% rename from Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/wordnet/Constants.java rename to Conceptpower+Spring/src/main/java/edu/asu/conceptpower/app/wordnet/Constants.java index 8a64f0587..ef167cea6 100644 --- a/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/wordnet/Constants.java +++ b/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/app/wordnet/Constants.java @@ -1,4 +1,4 @@ -package edu.asu.conceptpower.servlet.wordnet; +package edu.asu.conceptpower.app.wordnet; public interface Constants { diff --git a/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/wordnet/WordNetConfiguration.java b/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/app/wordnet/WordNetConfiguration.java similarity index 92% rename from Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/wordnet/WordNetConfiguration.java rename to Conceptpower+Spring/src/main/java/edu/asu/conceptpower/app/wordnet/WordNetConfiguration.java index 9c76bf05f..d9bf14d4e 100644 --- a/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/wordnet/WordNetConfiguration.java +++ b/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/app/wordnet/WordNetConfiguration.java @@ -1,4 +1,4 @@ -package edu.asu.conceptpower.servlet.wordnet; +package edu.asu.conceptpower.app.wordnet; import java.io.Serializable; diff --git a/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/wordnet/WordNetManager.java b/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/app/wordnet/WordNetManager.java similarity index 89% rename from Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/wordnet/WordNetManager.java rename to Conceptpower+Spring/src/main/java/edu/asu/conceptpower/app/wordnet/WordNetManager.java index 769cc2318..c6acdb40c 100644 --- a/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/wordnet/WordNetManager.java +++ b/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/app/wordnet/WordNetManager.java @@ -1,4 +1,4 @@ -package edu.asu.conceptpower.servlet.wordnet; +package edu.asu.conceptpower.app.wordnet; import java.io.File; import java.io.IOException; @@ -51,10 +51,10 @@ public void init() throws IOException, org.apache.lucene.queryparser.classic.Par dict.open(); posMap = new HashMap(); - posMap.put(edu.asu.conceptpower.servlet.core.POS.NOUN, POS.NOUN); - posMap.put(edu.asu.conceptpower.servlet.core.POS.VERB, POS.VERB); - posMap.put(edu.asu.conceptpower.servlet.core.POS.ADVERB, POS.ADVERB); - posMap.put(edu.asu.conceptpower.servlet.core.POS.ADJECTIVE, POS.ADJECTIVE); + posMap.put(edu.asu.conceptpower.app.core.POS.NOUN, POS.NOUN); + posMap.put(edu.asu.conceptpower.app.core.POS.VERB, POS.VERB); + posMap.put(edu.asu.conceptpower.app.core.POS.ADVERB, POS.ADVERB); + posMap.put(edu.asu.conceptpower.app.core.POS.ADJECTIVE, POS.ADJECTIVE); } @@ -104,7 +104,7 @@ protected ConceptEntry createConceptEntry(IWord word) { ConceptEntry entry = new ConceptEntry(); entry.setId(word.getID().toString()); entry.setWordnetId(word.getID().toString()); - entry.setWord(word.getLemma()); + entry.setWord(word.getLemma().replace("_", " ")); entry.setPos(word.getPOS().name()); entry.setConceptList(Constants.WORDNET_DICTIONARY); @@ -115,7 +115,7 @@ protected ConceptEntry createConceptEntry(IWord word) { StringBuffer sb = new StringBuffer(); for (IWord syn : synonyms) { if (!syn.getID().equals(word.getID())) - sb.append(syn.getID().toString() + edu.asu.conceptpower.servlet.core.Constants.SYNONYM_SEPARATOR); + sb.append(syn.getID().toString() + edu.asu.conceptpower.app.core.Constants.SYNONYM_SEPARATOR); } entry.setSynonymIds(sb.toString()); diff --git a/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/wrapper/.gitignore b/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/app/wrapper/.gitignore similarity index 100% rename from Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/wrapper/.gitignore rename to Conceptpower+Spring/src/main/java/edu/asu/conceptpower/app/wrapper/.gitignore diff --git a/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/app/wrapper/ConceptEntryWrapper.java b/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/app/wrapper/ConceptEntryWrapper.java new file mode 100644 index 000000000..7659c2326 --- /dev/null +++ b/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/app/wrapper/ConceptEntryWrapper.java @@ -0,0 +1,127 @@ +package edu.asu.conceptpower.app.wrapper; + +import java.io.Serializable; +import java.util.List; + +import edu.asu.conceptpower.core.ConceptEntry; +import edu.asu.conceptpower.core.ConceptType; +import edu.asu.conceptpower.users.User; + +/** + * This class describes the concept entry wrapper in concept power. It provides + * properties which are not available for the concept entries to be wrapped + * + * @author Julia Damerow + * + */ +public class ConceptEntryWrapper implements Serializable { + + private static final long serialVersionUID = -4261304897583134670L; + private ConceptEntry entry; + private List synonyms; + private ConceptType type; + private User creator; + private List wrappedWordnetEntries; + private String description; + private String uri; + + // This field denotes if there is an error in fetching the concept. If it is + // set true then error msg is displayed on the screen + private boolean error; + private String errorMsg; + + private String creatorId; + private String lastModifiedEvent; + + public ConceptEntryWrapper(ConceptEntry entry) { + this.entry = entry; + } + + public ConceptEntry getEntry() { + return entry; + } + + public void setEntry(ConceptEntry entry) { + this.entry = entry; + } + + public List getSynonyms() { + return synonyms; + } + + public void setSynonyms(List synonyms) { + this.synonyms = synonyms; + } + + public ConceptType getType() { + return type; + } + + public void setType(ConceptType type) { + this.type = type; + } + + public User getCreator() { + return creator; + } + + public void setCreator(User creator) { + this.creator = creator; + } + + public void setWrappedWordnetEntries(List wrappedWordnetEntries) { + this.wrappedWordnetEntries = wrappedWordnetEntries; + } + + public List getWrappedWordnetEntries() { + return wrappedWordnetEntries; + } + + public String getDescription() { + return description; + } + + public void setDescription(String description) { + this.description = description.replace("\n", "
"); + } + + public String getUri() { + return uri; + } + + public void setUri(String uri) { + this.uri = uri; + } + + public boolean isError() { + return error; + } + + public void setError(boolean error) { + this.error = error; + } + + public String getErrorMsg() { + return errorMsg; + } + + public void setErrorMsg(String errorMsg) { + this.errorMsg = errorMsg; + } + + public String getCreatorId() { + return creatorId; + } + + public void setCreatorId(String creatorId) { + this.creatorId = creatorId; + } + + public String getLastModifiedEvent() { + return lastModifiedEvent; + } + + public void setLastModifiedEvent(String lastModifiedEvent) { + this.lastModifiedEvent = lastModifiedEvent; + } +} diff --git a/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/wrapper/ConceptTypeWrapper.java b/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/app/wrapper/ConceptTypeWrapper.java similarity index 90% rename from Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/wrapper/ConceptTypeWrapper.java rename to Conceptpower+Spring/src/main/java/edu/asu/conceptpower/app/wrapper/ConceptTypeWrapper.java index 9ebd8fc10..523af78bf 100644 --- a/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/wrapper/ConceptTypeWrapper.java +++ b/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/app/wrapper/ConceptTypeWrapper.java @@ -1,11 +1,11 @@ -package edu.asu.conceptpower.servlet.wrapper; +package edu.asu.conceptpower.app.wrapper; import java.io.Serializable; import org.springframework.beans.factory.annotation.Autowired; +import edu.asu.conceptpower.app.util.URIHelper; import edu.asu.conceptpower.core.ConceptType; -import edu.asu.conceptpower.root.URIHelper; /** * diff --git a/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/wrapper/ConceptWrapperCreator.java b/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/app/wrapper/ConceptWrapperCreator.java similarity index 91% rename from Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/wrapper/ConceptWrapperCreator.java rename to Conceptpower+Spring/src/main/java/edu/asu/conceptpower/app/wrapper/ConceptWrapperCreator.java index 100e50e71..8b21411c2 100644 --- a/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/wrapper/ConceptWrapperCreator.java +++ b/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/app/wrapper/ConceptWrapperCreator.java @@ -1,4 +1,4 @@ -package edu.asu.conceptpower.servlet.wrapper; +package edu.asu.conceptpower.app.wrapper; import org.springframework.beans.BeansException; import org.springframework.beans.factory.BeanFactory; diff --git a/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/wrapper/IConceptWrapperCreator.java b/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/app/wrapper/IConceptWrapperCreator.java similarity index 67% rename from Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/wrapper/IConceptWrapperCreator.java rename to Conceptpower+Spring/src/main/java/edu/asu/conceptpower/app/wrapper/IConceptWrapperCreator.java index 62a436b45..5cf49c572 100644 --- a/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/wrapper/IConceptWrapperCreator.java +++ b/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/app/wrapper/IConceptWrapperCreator.java @@ -1,9 +1,9 @@ -package edu.asu.conceptpower.servlet.wrapper; +package edu.asu.conceptpower.app.wrapper; import java.util.List; +import edu.asu.conceptpower.app.exceptions.LuceneException; import edu.asu.conceptpower.core.ConceptEntry; -import edu.asu.conceptpower.servlet.exceptions.LuceneException; public interface IConceptWrapperCreator { diff --git a/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/wrapper/impl/ConceptEntryWrapperCreator.java b/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/app/wrapper/impl/ConceptEntryWrapperCreator.java similarity index 68% rename from Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/wrapper/impl/ConceptEntryWrapperCreator.java rename to Conceptpower+Spring/src/main/java/edu/asu/conceptpower/app/wrapper/impl/ConceptEntryWrapperCreator.java index 77807c2e0..8747ed31e 100644 --- a/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/wrapper/impl/ConceptEntryWrapperCreator.java +++ b/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/app/wrapper/impl/ConceptEntryWrapperCreator.java @@ -1,20 +1,21 @@ -package edu.asu.conceptpower.servlet.wrapper.impl; +package edu.asu.conceptpower.app.wrapper.impl; import java.util.ArrayList; import java.util.List; +import org.apache.commons.lang3.StringEscapeUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; +import edu.asu.conceptpower.app.core.Constants; +import edu.asu.conceptpower.app.core.IConceptManager; +import edu.asu.conceptpower.app.core.IConceptTypeManger; +import edu.asu.conceptpower.app.exceptions.LuceneException; +import edu.asu.conceptpower.app.users.IUserManager; +import edu.asu.conceptpower.app.util.IURIHelper; +import edu.asu.conceptpower.app.wrapper.ConceptEntryWrapper; +import edu.asu.conceptpower.app.wrapper.IConceptWrapperCreator; import edu.asu.conceptpower.core.ConceptEntry; -import edu.asu.conceptpower.root.IURIHelper; -import edu.asu.conceptpower.servlet.core.Constants; -import edu.asu.conceptpower.servlet.core.IConceptManager; -import edu.asu.conceptpower.servlet.core.IConceptTypeManger; -import edu.asu.conceptpower.servlet.exceptions.LuceneException; -import edu.asu.conceptpower.servlet.users.IUserManager; -import edu.asu.conceptpower.servlet.wrapper.ConceptEntryWrapper; -import edu.asu.conceptpower.servlet.wrapper.IConceptWrapperCreator; /** * This class provides methods required for creation concept wrappers @@ -24,7 +25,7 @@ */ @Component public class ConceptEntryWrapperCreator implements IConceptWrapperCreator { - + @Autowired private IConceptManager conceptManager; @@ -33,17 +34,16 @@ public class ConceptEntryWrapperCreator implements IConceptWrapperCreator { @Autowired private IUserManager usersManager; - + @Autowired private IURIHelper helper; - + /** * This method creates wrappers for the concept entries passed as parameter * * @param entries * Holds the concept entries to be wrapped * @return - * @throws LuceneException */ @Override public List createWrappers(ConceptEntry[] entries) throws LuceneException { @@ -53,7 +53,7 @@ public List createWrappers(ConceptEntry[] entries) throws L return foundConcepts; for (ConceptEntry entry : entries) { - + ConceptEntryWrapper wrapper = new ConceptEntryWrapper(entry); wrapper.setUri(helper.getURI(entry)); if (entry.getTypeId() != null && !entry.getTypeId().isEmpty()) @@ -64,16 +64,13 @@ public List createWrappers(ConceptEntry[] entries) throws L // if entry wraps a wordnet concepts, add it here List wordnetEntries = new ArrayList(); - String wordnetIds = (entry.getWordnetId() != null ? entry - .getWordnetId() : ""); + String wordnetIds = (entry.getWordnetId() != null ? entry.getWordnetId() : ""); { - String[] ids = wordnetIds.trim().split( - Constants.CONCEPT_SEPARATOR); + String[] ids = wordnetIds.trim().split(Constants.CONCEPT_SEPARATOR); if (ids != null) { for (String id : ids) { if (id != null && !id.trim().isEmpty()) { - ConceptEntry wordnetEntry = conceptManager - .getWordnetConceptEntry(id); + ConceptEntry wordnetEntry = conceptManager.getWordnetConceptEntry(id); if (wordnetEntry != null) wordnetEntries.add(wordnetEntry); } @@ -98,19 +95,27 @@ public List createWrappers(ConceptEntry[] entries) throws L wrapper.setDescription(sb.toString()); List synonyms = new ArrayList(); - String synonymIds = (entry.getSynonymIds() != null ? entry - .getSynonymIds() : ""); + String synonymIds = (entry.getSynonymIds() != null ? entry.getSynonymIds() : ""); if (synonymIds != null) { - String[] ids = synonymIds.trim().split( - Constants.SYNONYM_SEPARATOR); + String[] ids = synonymIds.trim().split(Constants.SYNONYM_SEPARATOR); if (ids != null) { for (String id : ids) { if (id != null && !id.trim().isEmpty()) { - ConceptEntry synonym = conceptManager - .getConceptEntry(id); - if (synonym != null) - synonyms.add(synonym); + try { + ConceptEntry synonym = conceptManager.getConceptEntry(id); + if (synonym != null) + synonyms.add(synonym); + } catch (IllegalArgumentException ie) { + if (wrapper.isError()) { + wrapper.setErrorMsg( + StringEscapeUtils.escapeXml10(wrapper.getErrorMsg() + "," + id)); + } else { + wrapper.setErrorMsg( + "The following synonym ids do not seem to exist in the database: " + id); + wrapper.setError(true); + } + } } } wrapper.setSynonyms(synonyms); @@ -121,4 +126,5 @@ public List createWrappers(ConceptEntry[] entries) throws L return foundConcepts; } + } diff --git a/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/core/ConceptEntry.java b/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/core/ConceptEntry.java index b2ce25163..759c850bb 100644 --- a/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/core/ConceptEntry.java +++ b/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/core/ConceptEntry.java @@ -1,14 +1,21 @@ package edu.asu.conceptpower.core; import java.io.Serializable; +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashSet; +import java.util.List; +import java.util.Set; import javax.persistence.Entity; import javax.persistence.Id; -import edu.asu.conceptpower.servlet.reflect.LuceneField; -import edu.asu.conceptpower.servlet.reflect.SearchField; -import edu.asu.conceptpower.servlet.rest.LuceneFieldNames; -import edu.asu.conceptpower.servlet.rest.SearchFieldNames; +import edu.asu.conceptpower.app.constants.LuceneFieldNames; +import edu.asu.conceptpower.app.constants.SearchFieldNames; +import edu.asu.conceptpower.app.reflect.LuceneField; +import edu.asu.conceptpower.app.reflect.SearchField; +import edu.asu.conceptpower.servlet.core.ChangeEvent; +import edu.asu.conceptpower.servlet.core.ChangeEvent.ChangeEventTypes; /** * This class represents one entry in the authority file. @@ -22,43 +29,43 @@ public class ConceptEntry implements Serializable { private static final long serialVersionUID = 4569090620671054560L; @Id - @LuceneField(lucenefieldName = LuceneFieldNames.ID, isIndexable = false) + @LuceneField(lucenefieldName = LuceneFieldNames.ID, isTokenized = false, isMultiple = false) private String id; @SearchField(fieldName = SearchFieldNames.WORDNETID) - @LuceneField(lucenefieldName = LuceneFieldNames.WORDNETID, isIndexable = true) + @LuceneField(lucenefieldName = LuceneFieldNames.WORDNETID, isTokenized = false, isMultiple = true) private String wordnetId; @SearchField(fieldName = SearchFieldNames.WORD) - @LuceneField(lucenefieldName = LuceneFieldNames.WORD, isIndexable = true) + @LuceneField(lucenefieldName = LuceneFieldNames.WORD, isTokenized = true, isMultiple = false) private String word; @SearchField(fieldName = SearchFieldNames.DESCRIPTION) - @LuceneField(lucenefieldName = LuceneFieldNames.DESCRIPTION, isIndexable = true) + @LuceneField(lucenefieldName = LuceneFieldNames.DESCRIPTION, isTokenized = true, isMultiple = false) private String description; @SearchField(fieldName = SearchFieldNames.POS) - @LuceneField(lucenefieldName = LuceneFieldNames.POS, isIndexable = true) + @LuceneField(lucenefieldName = LuceneFieldNames.POS, isTokenized = true, isMultiple = false) private String pos; @SearchField(fieldName = SearchFieldNames.CONCEPT_LIST) - @LuceneField(lucenefieldName = LuceneFieldNames.CONCEPT_LIST, isIndexable = true) + @LuceneField(lucenefieldName = LuceneFieldNames.CONCEPT_LIST, isTokenized = false, isMultiple = false) private String conceptList; @SearchField(fieldName = SearchFieldNames.TYPE_ID) - @LuceneField(lucenefieldName = LuceneFieldNames.TYPE_ID, isIndexable = false) + @LuceneField(lucenefieldName = LuceneFieldNames.TYPE_ID, isTokenized = false, isMultiple = false) private String typeId; - @SearchField(fieldName = SearchFieldNames.EQUALS_TO) - @LuceneField(lucenefieldName = LuceneFieldNames.EQUALS_TO, isIndexable = true) + @SearchField(fieldName = SearchFieldNames.EQUAL_TO) + @LuceneField(lucenefieldName = LuceneFieldNames.EQUALS_TO, isTokenized = false, isMultiple = true) private String equalTo; @SearchField(fieldName = SearchFieldNames.SIMILAR_TO) - @LuceneField(lucenefieldName = LuceneFieldNames.SIMILAR_TO, isIndexable = true) + @LuceneField(lucenefieldName = LuceneFieldNames.SIMILAR_TO, isTokenized = false, isMultiple = true) private String similarTo; @SearchField(fieldName=SearchFieldNames.SYNONYM_ID) - @LuceneField(lucenefieldName = LuceneFieldNames.SYNONYMID, isIndexable = true) + @LuceneField(lucenefieldName = LuceneFieldNames.SYNONYMID, isTokenized = false, isMultiple = true) private String synonymIds; private String synsetIds; @@ -68,17 +75,25 @@ public class ConceptEntry implements Serializable { private String broadens; @SearchField(fieldName = SearchFieldNames.CREATOR) - @LuceneField(lucenefieldName = LuceneFieldNames.CREATOR, isIndexable = false) + @LuceneField(lucenefieldName = LuceneFieldNames.CREATOR, isTokenized = false, isMultiple = false) private String creatorId; @SearchField(fieldName = SearchFieldNames.MODIFIED) - @LuceneField(lucenefieldName = LuceneFieldNames.MODIFIED, isIndexable = false) + @LuceneField(lucenefieldName = LuceneFieldNames.MODIFIED, isTokenized = false, isMultiple = false) private String modified; + @SearchField(fieldName = SearchFieldNames.MERGED_IDS) + @LuceneField(lucenefieldName = LuceneFieldNames.MERGED_IDS, isTokenized = false, isMultiple = true) + private String mergedIds; + private boolean isDeleted; private String modifiedUser; + private List changeEvents = new ArrayList(); + + private Set alternativeIds = new HashSet<>(); + public ConceptEntry() { } @@ -91,10 +106,28 @@ public ConceptEntry(String id, String word, String description) { /** * A string containing the id of the user who created an entry. * + * First check if creator is in change event list. If so fetch it Else fetch + * it from old db + * * @return the id of the user who created an entry */ public String getCreatorId() { + // This check has been introduced to make sure the existing concepts + // work fine. For existing concepts changeevents will be null in D/B. So + // if changevent is null in DB fetch creatorId directly + if (this.changeEvents != null && this.changeEvents.size() > 0) { + Collections.sort(this.changeEvents); + // Since the list is sorted, the first event will be a creation + // event. If the first event is not creation event, then it means + // some existing concept has been modified with this new change. So + // changevents will contain only the modified user id. In that case + // fetch from the creatorId itself as per the old design + if (ChangeEventTypes.CREATION == changeEvents.get(0).getType()) { + return changeEvents.get(0).getUserName(); + } + } return creatorId; + } public void setCreatorId(String creatorId) { @@ -104,7 +137,7 @@ public void setCreatorId(String creatorId) { /** * A string containing the ids of other conceptpower entries that are * synonyms for an entry. The synonym ids are speparated by - * {@link edu.asu.conceptpower.servlet.core.Constants.SYNONYM_SEPARATOR}. + * {@link edu.asu.conceptpower.app.core.Constants.SYNONYM_SEPARATOR}. */ public String getSynonymIds() { return synonymIds; @@ -264,6 +297,12 @@ public void setModified(String modified) { * A string containing a string describing who modified a concept and when. */ public String getModified() { + if (this.changeEvents != null && this.changeEvents.size() > 0) { + Collections.sort(this.changeEvents); + if (ChangeEventTypes.CREATION == changeEvents.get(changeEvents.size() - 1).getType()) { + return changeEvents.get(0).getUserName(); + } + } return modified; } @@ -340,6 +379,29 @@ public boolean equals(Object obj) { return true; } + public List getChangeEvents() { + // Creates a copy of changeevent + if (this.changeEvents != null) { + return new ArrayList<>(this.changeEvents); + } + return null; + } + + /** + * This method add the changeevent to the end of the list. The first element + * will always be a creator + * + * @param event + */ + public void addNewChangeEvent(ChangeEvent event) { + + if (changeEvents == null) { + this.changeEvents = new ArrayList(); + } + // Appends to the end of the list + this.changeEvents.add(event); + } + public String getModifiedUser() { return modifiedUser; } @@ -348,4 +410,22 @@ public void setModifiedUser(String modifiedUser) { this.modifiedUser = modifiedUser; } + public Set getAlternativeIds() { + if (this.alternativeIds == null) { + this.alternativeIds = new HashSet<>(); + } + return alternativeIds; + } + + public void setAlternativeIds(Set alternativeIds) { + this.alternativeIds = alternativeIds; + } + + public String getMergedIds() { + return mergedIds; + } + + public void setMergedIds(String mergedIds) { + this.mergedIds = mergedIds; + } } \ No newline at end of file diff --git a/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/core/IndexingEvent.java b/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/core/IndexingEvent.java index 93be387e7..0f17a7d67 100644 --- a/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/core/IndexingEvent.java +++ b/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/core/IndexingEvent.java @@ -1,7 +1,6 @@ package edu.asu.conceptpower.core; import java.io.Serializable; -import java.sql.Timestamp; import java.util.Date; public class IndexingEvent implements Serializable { diff --git a/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/rest/ConceptIDLookup.java b/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/rest/ConceptIDLookup.java new file mode 100644 index 000000000..82f98ed44 --- /dev/null +++ b/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/rest/ConceptIDLookup.java @@ -0,0 +1,101 @@ +package edu.asu.conceptpower.rest; + +import java.util.HashMap; +import java.util.Map; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.HttpStatus; +import org.springframework.http.MediaType; +import org.springframework.http.ResponseEntity; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.RequestHeader; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.ResponseBody; + +import com.fasterxml.jackson.core.JsonProcessingException; + +import edu.asu.conceptpower.app.core.IConceptManager; +import edu.asu.conceptpower.app.core.IConceptTypesService; +import edu.asu.conceptpower.app.db.TypeDatabaseClient; +import edu.asu.conceptpower.core.ConceptEntry; +import edu.asu.conceptpower.core.ConceptType; +import edu.asu.conceptpower.rest.msg.IConceptMessage; +import edu.asu.conceptpower.rest.msg.IMessageRegistry; + +/** + * This class provides a method to query concepts by their id. + * It answers requests of the form: + * "http://[server.url]/conceptpower/rest/Concept?id={URI or ID of concept}" + * + * @author Chetan, Julia Damerow + * + */ +@Controller +public class ConceptIDLookup { + + @Autowired + private IConceptManager conceptManager; + + @Autowired + private TypeDatabaseClient typeManager; + + @Autowired + private IMessageRegistry messageFactory; + + @Autowired + private IConceptTypesService conceptTypesService; + + private static final Logger logger = LoggerFactory.getLogger(ConceptIDLookup.class); + + /** + * This method provides concept information for the rest interface of the + * form + * "http://[server.url]/conceptpower/rest/Concept?id={URI or ID of concept}" + * + * @param req + * Holds the HTTP request information + * @return XML containing concept information + * @throws JsonProcessingException + */ + @RequestMapping(value = "/Concept", method = RequestMethod.GET, produces = { MediaType.APPLICATION_XML_VALUE, + MediaType.APPLICATION_JSON_VALUE }) + public @ResponseBody ResponseEntity getConceptById(@RequestParam String id, + @RequestHeader(value = "Accept", defaultValue = MediaType.APPLICATION_XML_VALUE) String acceptHeader) + throws JsonProcessingException { + + if (id == null || id.trim().isEmpty()) { + return new ResponseEntity(HttpStatus.BAD_REQUEST); + } + + String[] pathParts = id.split("/"); + int lastIndex = pathParts.length - 1; + String wordnetId = null; + if (lastIndex > -1) + wordnetId = pathParts[lastIndex]; + + if (wordnetId == null) { + return new ResponseEntity(HttpStatus.BAD_REQUEST); + } + ConceptEntry entry = conceptManager.getConceptEntry(wordnetId); + Map entryMap = new HashMap(); + + IConceptMessage msg = messageFactory.getMessageFactory(acceptHeader).createConceptMessage(); + + if (entry != null) { + + ConceptType type = null; + if (typeManager != null && entry.getTypeId() != null && !entry.getTypeId().trim().isEmpty()) { + type = typeManager.getType(entry.getTypeId()); + } + entryMap.put(entry, type); + } + + return new ResponseEntity(msg.getAllConceptEntriesAndPaginationDetails(entryMap, null), HttpStatus.OK); + + } + +} diff --git a/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/rest/ConceptLookup.java b/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/rest/ConceptLookup.java new file mode 100644 index 000000000..9b5da9504 --- /dev/null +++ b/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/rest/ConceptLookup.java @@ -0,0 +1,126 @@ +package edu.asu.conceptpower.rest; + +import java.util.HashMap; +import java.util.Map; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.HttpStatus; +import org.springframework.http.MediaType; +import org.springframework.http.ResponseEntity; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestHeader; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.bind.annotation.ResponseBody; + +import com.fasterxml.jackson.core.JsonProcessingException; + +import edu.asu.conceptpower.app.core.IConceptManager; +import edu.asu.conceptpower.app.db.TypeDatabaseClient; +import edu.asu.conceptpower.app.exceptions.IndexerRunningException; +import edu.asu.conceptpower.app.exceptions.LuceneException; +import edu.asu.conceptpower.app.rdf.RDFMessageFactory; +import edu.asu.conceptpower.core.ConceptEntry; +import edu.asu.conceptpower.core.ConceptType; +import edu.asu.conceptpower.rest.msg.IConceptMessage; +import edu.asu.conceptpower.rest.msg.IMessageRegistry; + +/** + * This class provides a method to retrieve all concepts for a given word and + * part of speech. It answers requests of the form: + * "http://[server.url]/conceptpower/rest/ConceptLookup/{word}/{pos}" + * + * @author Chetan, Julia Damerow + * + */ +@Controller +public class ConceptLookup { + + @Autowired + private IConceptManager dictManager; + + @Autowired + private TypeDatabaseClient typeManager; + + @Autowired + private IMessageRegistry messageFactory; + + @Autowired + private RDFMessageFactory rdfFactory; + + private static final Logger logger = LoggerFactory.getLogger(ConceptLookup.class); + + /** + * This method provides information of a concept for a rest interface of the + * form "http://[server.url]/conceptpower/rest/ConceptLookup/{word}/{pos}" + * + * @param word + * String value of concept to be looked + * @param pos + * String value of the POS of concept to be looked + * @return XML containing information of given concept for given POS + * @throws JsonProcessingException + * @throws IndexerRunningException + */ + @RequestMapping(value = "/ConceptLookup/{word}/{pos}", method = RequestMethod.GET, produces = { + MediaType.APPLICATION_XML_VALUE, MediaType.APPLICATION_JSON_VALUE }) + public @ResponseBody ResponseEntity getWordNetEntry(@PathVariable("word") String word, + @PathVariable("pos") String pos, + @RequestHeader(value = "Accept", defaultValue = MediaType.APPLICATION_XML_VALUE) String acceptHeader) + throws JsonProcessingException, IndexerRunningException { + ConceptEntry[] entries = null; + try { + entries = dictManager.getConceptListEntriesForWordPOS(word, pos, null); + } catch (LuceneException ex) { + logger.error("Lucene exception", ex); + return new ResponseEntity(ex.getMessage(), HttpStatus.INTERNAL_SERVER_ERROR); + } catch (IllegalAccessException e) { + logger.error("Illegal access exception", e); + return new ResponseEntity(e.getMessage(), HttpStatus.INTERNAL_SERVER_ERROR); + } + + if (entries == null) { + return new ResponseEntity("No search results.", HttpStatus.OK); + } + Map entryMap = generateEntryMap(entries); + IConceptMessage conceptMessage = messageFactory.getMessageFactory(acceptHeader).createConceptMessage(); + String xmlEntries = null; + if (entries != null) { + xmlEntries = conceptMessage.getAllConceptEntriesAndPaginationDetails(entryMap, null); + } + return new ResponseEntity(xmlEntries, HttpStatus.OK); + } + + private Map generateEntryMap(ConceptEntry[] entries) { + Map entryMap = new HashMap(); + + for (ConceptEntry entry : entries) { + ConceptType type = null; + if (typeManager != null && entry.getTypeId() != null && !entry.getTypeId().trim().isEmpty()) { + type = typeManager.getType(entry.getTypeId()); + } + entryMap.put(entry, type); + } + return entryMap; + } + + @RequestMapping(value = "/ConceptLookup/{word}/{pos}", method = RequestMethod.GET, produces = "application/rdf+xml") + public @ResponseBody ResponseEntity getWordNetEntryInRdf(@PathVariable("word") String word, + @PathVariable("pos") String pos) throws IndexerRunningException { + ConceptEntry[] entries = null; + try { + entries = dictManager.getConceptListEntriesForWordPOS(word, pos, null); + } catch (LuceneException ex) { + logger.error("Lucene Exception", ex); + return new ResponseEntity(ex.getMessage(), HttpStatus.INTERNAL_SERVER_ERROR); + } catch (IllegalAccessException e) { + logger.error("Illegal access exception", e); + return new ResponseEntity(e.getMessage(), HttpStatus.BAD_REQUEST); + } + return new ResponseEntity(rdfFactory.generateRDF(entries), HttpStatus.OK); + } + +} diff --git a/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/rest/ConceptSearch.java b/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/rest/ConceptSearch.java new file mode 100644 index 000000000..91b69c304 --- /dev/null +++ b/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/rest/ConceptSearch.java @@ -0,0 +1,160 @@ +package edu.asu.conceptpower.rest; + +import java.lang.reflect.Field; +import java.util.HashMap; +import java.util.LinkedHashMap; +import java.util.Map; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.context.annotation.PropertySource; +import org.springframework.http.HttpStatus; +import org.springframework.http.MediaType; +import org.springframework.http.ResponseEntity; +import org.springframework.stereotype.Controller; +import org.springframework.validation.BindingResult; +import org.springframework.validation.annotation.Validated; +import org.springframework.web.bind.WebDataBinder; +import org.springframework.web.bind.annotation.InitBinder; +import org.springframework.web.bind.annotation.RequestHeader; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.bind.annotation.ResponseBody; + +import com.fasterxml.jackson.core.JsonProcessingException; + +import edu.asu.conceptpower.app.core.IIndexService; +import edu.asu.conceptpower.app.db.TypeDatabaseClient; +import edu.asu.conceptpower.app.exceptions.IndexerRunningException; +import edu.asu.conceptpower.app.exceptions.LuceneException; +import edu.asu.conceptpower.app.util.URIHelper; +import edu.asu.conceptpower.core.ConceptEntry; +import edu.asu.conceptpower.core.ConceptType; +import edu.asu.conceptpower.rest.msg.IConceptMessage; +import edu.asu.conceptpower.rest.msg.IMessageRegistry; +import edu.asu.conceptpower.rest.msg.Pagination; + +/** + * This class provides a method to search concepts. It answers requests to: + * "http://[server.url]/conceptpower/rest/ConceptSearch?{list of fieldname=value}{operator=and/or}" + * + * @author Chetan, Julia Damerow + * + */ +@Controller +@PropertySource("classpath:config.properties") +public class ConceptSearch { + + @Autowired + private IIndexService manager; + + @Autowired + private TypeDatabaseClient typeManager; + + @Autowired + private IMessageRegistry messageFactory; + + @Autowired + private URIHelper uriHelper; + + @Value("${default_page_size}") + private int numberOfRecordsPerPage; + + @Autowired + private ConceptSearchParameterValidator validator; + + @InitBinder + private void initBinder(WebDataBinder binder) { + binder.setValidator(validator); + } + + private static final Logger logger = LoggerFactory.getLogger(ConceptSearch.class); + + /** + * This method provides information of a concept for a rest interface of the + * form + * "http://[server.url]/conceptpower/rest/Type?id={URI or ID of concept}" + * + * @param req + * Holds HTTP request information + * @return + * @throws JsonProcessingException + * @throws IndexerRunningException + */ + @RequestMapping(value = "/ConceptSearch", method = RequestMethod.GET, produces = { MediaType.APPLICATION_XML_VALUE, + MediaType.APPLICATION_JSON_VALUE }) + public @ResponseBody ResponseEntity searchConcept( + @Validated ConceptSearchParameters conceptSearchParameters, BindingResult result, + @RequestHeader(value = "Accept", defaultValue = MediaType.APPLICATION_XML_VALUE) String acceptHeader) + throws JsonProcessingException, IllegalArgumentException, IllegalAccessException, + IndexerRunningException { + + if (result.hasErrors()) { + IConceptMessage msg = messageFactory.getMessageFactory(acceptHeader).createConceptMessage(); + String errorMessage = msg.getErrorMessages(result.getAllErrors()); + return new ResponseEntity(errorMessage, HttpStatus.BAD_REQUEST); + } + Map searchFields = new HashMap(); + String operator = SearchParamters.OP_AND; + + int page = 1; + + for (Field field : conceptSearchParameters.getClass().getDeclaredFields()) { + field.setAccessible(true); + if (field.getName().equalsIgnoreCase("type_uri")) { + if (field.get(conceptSearchParameters) != null) { + searchFields.put("type_id", + uriHelper.getTypeId(String.valueOf(field.get(conceptSearchParameters)))); + } + } else if (SearchParamters.OPERATOR.equalsIgnoreCase(field.getName())) { + // If the value is null, then operator will be OR by default + if (field.get(conceptSearchParameters) != null) { + operator = String.valueOf(field.get(conceptSearchParameters)).toUpperCase(); + } + } else if (SearchParamters.PAGE.equalsIgnoreCase(field.getName())) { + page = field.get(conceptSearchParameters) != null ? (Integer) field.get(conceptSearchParameters) : page; + } else if (SearchParamters.NUMBER_OF_RECORDS_PER_PAGE.equalsIgnoreCase(field.getName())) { + numberOfRecordsPerPage = field.get(conceptSearchParameters) != null + ? (Integer) field.get(conceptSearchParameters) : numberOfRecordsPerPage; + } else if (field.get(conceptSearchParameters) != null) { + searchFields.put(field.getName().trim(), String.valueOf(field.get(conceptSearchParameters)).trim()); + } + } + + ConceptEntry[] searchResults = null; + int totalNumberOfRecords = 0; + try { + totalNumberOfRecords = manager.getTotalNumberOfRecordsForSearch(searchFields, operator); + searchResults = manager.searchForConceptByPageNumberAndFieldMap(searchFields, operator, page, + numberOfRecordsPerPage); + } catch (LuceneException ex) { + logger.error("Lucene Exception", ex); + return new ResponseEntity(ex.getMessage(), HttpStatus.INTERNAL_SERVER_ERROR); + } + + if (searchResults == null || searchResults.length == 0) { + // Data is not found but still returning OK as per review comments + IConceptMessage msg = messageFactory.getMessageFactory(acceptHeader).createConceptMessage(); + return new ResponseEntity(msg.getErrorMessage("No records found for the search condition."), + HttpStatus.OK); + } + Map entryMap = new LinkedHashMap(); + IConceptMessage msg = messageFactory.getMessageFactory(acceptHeader).createConceptMessage(); + createEntryMap(searchResults, entryMap); + Pagination pagination = new Pagination(page, totalNumberOfRecords); + return new ResponseEntity(msg.getAllConceptEntriesAndPaginationDetails(entryMap, pagination), + HttpStatus.OK); + } + + private void createEntryMap(ConceptEntry[] searchResults, Map entryMap) { + for (ConceptEntry entry : searchResults) { + ConceptType type = null; + if (typeManager != null && entry.getTypeId() != null && !entry.getTypeId().trim().isEmpty()) { + type = typeManager.getType(entry.getTypeId()); + } + entryMap.put(entry, type); + } + } +} diff --git a/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/rest/ConceptSearchParameterValidator.java b/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/rest/ConceptSearchParameterValidator.java new file mode 100644 index 000000000..c7feb19ff --- /dev/null +++ b/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/rest/ConceptSearchParameterValidator.java @@ -0,0 +1,39 @@ +package edu.asu.conceptpower.rest; + +import org.springframework.stereotype.Component; +import org.springframework.validation.Errors; +import org.springframework.validation.Validator; + +import edu.asu.conceptpower.app.core.POS; + +/** + * This class validates the Conceptpower search parameters. Checks whether a + * user has submitted word and pos details when searching for a concept. In + * addition, the validator checks for the operators (OR and AND). + * + * @author karthikeyanmohan + * + */ +@Component +public class ConceptSearchParameterValidator implements Validator { + + @Override + public boolean supports(Class clazz) { + return ConceptSearchParameters.class.isAssignableFrom(clazz); + } + + @Override + public void validate(Object target, Errors errors) { + ConceptSearchParameters conceptSearchParameter = (ConceptSearchParameters) target; + if (conceptSearchParameter.getPos() != null && !POS.posValues.contains(conceptSearchParameter.getPos().toLowerCase())) { + errors.reject("pos", "Please enter correct pos value."); + } + if (conceptSearchParameter.getOperator() != null) { + if (!SearchParamters.OP_OR.equalsIgnoreCase(conceptSearchParameter.getOperator()) + && !SearchParamters.OP_AND.equalsIgnoreCase(conceptSearchParameter.getOperator())) { + errors.reject("operator", "Please enter correct operator value."); + } + } + } + +} diff --git a/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/rest/ConceptSearchParameters.java b/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/rest/ConceptSearchParameters.java new file mode 100644 index 000000000..01b7d440b --- /dev/null +++ b/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/rest/ConceptSearchParameters.java @@ -0,0 +1,144 @@ +package edu.asu.conceptpower.rest; + +public class ConceptSearchParameters { + + private String type_uri; + private String operator; + private Integer page; + private String equal_to; + private String similar_to; + private String description; + private String word; + private String pos; + private String concept_list; + private String type_id; + private String creator; + private String modified_by; + private Integer number_of_records_per_page; + + public String getType_uri() { + return type_uri; + } + + public void setType_uri(String type_uri) { + this.type_uri = type_uri; + } + + public String getOperator() { + return operator; + } + + public void setOperator(String operator) { + this.operator = operator; + } + + public Integer getPage() { + return page; + } + + public void setPage(Integer page) { + if (page != null) { + this.page = page; + } + } + + public String getSimilar_to() { + return similar_to; + } + + public void setSimilar_to(String similar_to) { + this.similar_to = similar_to; + } + + public String getDescription() { + return description; + } + + public void setDescription(String description) { + this.description = description; + } + + /** + * This method returns the search term for the field + * word. The method automatically lowercases the + * search term. + * + * @return + */ + public String getWord() { + if (word != null) { + return word.toLowerCase(); + } + return word; + } + + public void setWord(String word) { + this.word = word; + } + + /** + * This method return the search term for the field pos + * (part of speech). It automatically lowercases the search term. + * @return + */ + public String getPos() { + if (pos != null) { + return pos.toLowerCase(); + } + return pos; + } + + public void setPos(String pos) { + this.pos = pos; + } + + public String getConcept_list() { + return concept_list; + } + + public void setConcept_list(String concept_list) { + this.concept_list = concept_list; + } + + public String getType_id() { + return type_id; + } + + public void setType_id(String type_id) { + this.type_id = type_id; + } + + public String getCreator() { + return creator; + } + + public void setCreator(String creator) { + this.creator = creator; + } + + public String getModified_by() { + return modified_by; + } + + public void setModified_by(String modified_by) { + this.modified_by = modified_by; + } + + public Integer getNumber_of_records_per_page() { + return number_of_records_per_page; + } + + public void setNumber_of_records_per_page(Integer number_of_records_per_page) { + if (number_of_records_per_page != null) { + this.number_of_records_per_page = number_of_records_per_page; + } + } + + public String getEqual_to() { + return equal_to; + } + + public void setEqual_to(String equal_to) { + this.equal_to = equal_to; + } +} diff --git a/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/rest/Concepts.java b/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/rest/Concepts.java similarity index 53% rename from Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/rest/Concepts.java rename to Conceptpower+Spring/src/main/java/edu/asu/conceptpower/rest/Concepts.java index 71c7415d3..a8e5a5340 100644 --- a/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/rest/Concepts.java +++ b/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/rest/Concepts.java @@ -1,8 +1,10 @@ -package edu.asu.conceptpower.servlet.rest; +package edu.asu.conceptpower.rest; import java.io.IOException; import java.io.StringReader; import java.security.Principal; +import java.util.Arrays; +import java.util.List; import java.util.ListIterator; import org.json.simple.JSONArray; @@ -21,16 +23,20 @@ import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; - +import org.springframework.web.bind.annotation.ResponseBody; + +import edu.asu.conceptpower.app.core.Constants; +import edu.asu.conceptpower.app.core.IConceptManager; +import edu.asu.conceptpower.app.core.IConceptTypeManger; +import edu.asu.conceptpower.app.core.POS; +import edu.asu.conceptpower.app.exceptions.DictionaryDoesNotExistException; +import edu.asu.conceptpower.app.exceptions.DictionaryModifyException; +import edu.asu.conceptpower.app.exceptions.IndexerRunningException; +import edu.asu.conceptpower.app.exceptions.LuceneException; +import edu.asu.conceptpower.app.util.URIHelper; import edu.asu.conceptpower.core.ConceptEntry; import edu.asu.conceptpower.core.ConceptType; -import edu.asu.conceptpower.servlet.core.IConceptManager; -import edu.asu.conceptpower.servlet.core.IConceptTypeManger; -import edu.asu.conceptpower.servlet.core.POS; -import edu.asu.conceptpower.servlet.exceptions.DictionaryDoesNotExistException; -import edu.asu.conceptpower.servlet.exceptions.DictionaryModifyException; -import edu.asu.conceptpower.servlet.exceptions.IndexerRunningException; -import edu.asu.conceptpower.servlet.exceptions.LuceneException; +import edu.mit.jwi.item.WordID; @Controller public class Concepts { @@ -41,11 +47,57 @@ public class Concepts { @Autowired private IConceptTypeManger typeManager; + @Autowired + private URIHelper uriHelper; + private static final Logger logger = LoggerFactory.getLogger(Concepts.class); + /** + * This method creates concepts as well as concept wrappers. This is decided + * based on the request parameter. If the request parameter contains one or + * more wordnet ids then concept wrapper is created else a new concept is + * created. + * + * Sample input for creating a concept wrapper: + * + * { + * "wordnetIds": + * "WID-00450866-N-01-pony-trekking,WID-03981924-N-01-pony_cart", + * "synonymids" : "WID-02380464-N-01-polo_pony,WID-04206225-N-03-pony", + * "conceptlist" : "FirstList-1", + * "type" : "88bea1dc-1443-4296-8315-715c71128b01", + * "description" : "Description", + * "equal_to" : "http://viaf.org/viaf/38882290", + * "similarTo" : "http://viaf.org/viaf/43723621" + * } + * + * Please note any word or pos passed during concept wrapper creation will + * be ignored. Word and pos details are fetched from wordnet. In case POS is + * entered by user, the code validates with the wordnet POS and throws an + * error if POS is not matching with wordnet + * + * Sample input for creating a concept: + * + * { + * "word": "kitty", + * "pos": "noun", + * "conceptlist": "mylist", + * "description": "Soft kitty, sleepy kitty, little ball of fur.", + * "type": "3b755111-545a-4c1c-929c-a2c0d4c3913b" + * } + * + * @param body + * @param principal + * @return + * @throws IndexerRunningException + * @throws LuceneException + * @throws IllegalAccessException + * @throws POSMismatchException + */ @PreAuthorize("isAuthenticated()") - @RequestMapping(value = "rest/concept/add", method = RequestMethod.POST) - public ResponseEntity addConcept(@RequestBody String body, Principal principal) { + @RequestMapping(value = "/concept/add", method = RequestMethod.POST) + public @ResponseBody ResponseEntity addConcept(@RequestBody String body, Principal principal) + throws IllegalAccessException, LuceneException, IndexerRunningException { StringReader reader = new StringReader(body); JSONParser jsonParser = new JSONParser(); @@ -65,11 +117,25 @@ public ResponseEntity addConcept(@RequestBody String body, Principal pri } JsonValidationResult result = checkJsonObject(jsonObject); - if (!result.isValid()) + + if (result.isValid() && jsonObject.get(JsonFields.WORDNET_ID) != null) { + result = checkJsonObjectForWrapper(jsonObject); + } + + if (!result.isValid()) { return new ResponseEntity(result.getMessage(), HttpStatus.BAD_REQUEST); + } ConceptEntry conceptEntry = createEntry(jsonObject, principal.getName()); + if (jsonObject.get(JsonFields.WORDNET_ID) != null) { + result = validatePOS(jsonObject, conceptEntry); + } + + if (!result.isValid()) { + return new ResponseEntity(result.getMessage(), HttpStatus.BAD_REQUEST); + } + // check type String typeId = conceptEntry.getTypeId(); ConceptType type = typeManager.getType(typeId); @@ -78,9 +144,8 @@ public ResponseEntity addConcept(@RequestBody String body, Principal pri HttpStatus.BAD_REQUEST); } - String id = null; try { - id = conceptManager.addConceptListEntry(conceptEntry); + conceptEntry.setId(conceptManager.addConceptListEntry(conceptEntry, principal.getName())); } catch (DictionaryDoesNotExistException e) { logger.error("Error creating concept from REST call.", e); return new ResponseEntity("Specified concept list does not exist in Conceptpower.", @@ -90,15 +155,14 @@ public ResponseEntity addConcept(@RequestBody String body, Principal pri return new ResponseEntity("Specified concept list can't be modified.", HttpStatus.BAD_REQUEST); } catch (LuceneException le) { logger.error("Error creating concept from REST call.", le); - return new ResponseEntity("Concept Cannot be added", HttpStatus.BAD_REQUEST); + return new ResponseEntity("Concept Cannot be added", HttpStatus.INTERNAL_SERVER_ERROR); } catch (IllegalAccessException e) { logger.error("Error creating concept from REST call.", e); return new ResponseEntity("Illegal Access", HttpStatus.BAD_REQUEST); - } catch (IndexerRunningException ir) { - return new ResponseEntity(jsonObject.toJSONString(), HttpStatus.CONFLICT); } - jsonObject.put("id", id); + jsonObject.put(JsonFields.ID, conceptEntry.getId()); + jsonObject.put(JsonFields.URI, uriHelper.getURI(conceptEntry)); HttpHeaders responseHeaders = new HttpHeaders(); responseHeaders.add("Content-Type", MediaType.APPLICATION_JSON_VALUE + "; charset=utf-8"); @@ -108,8 +172,9 @@ public ResponseEntity addConcept(@RequestBody String body, Principal pri } @PreAuthorize("isAuthenticated()") - @RequestMapping(value = "rest/concepts/add", method = RequestMethod.POST) - public ResponseEntity addConcepts(@RequestBody String body, Principal principal) { + @RequestMapping(value = "/concepts/add", method = RequestMethod.POST) + public ResponseEntity addConcepts(@RequestBody String body, Principal principal) + throws IllegalAccessException, LuceneException, IndexerRunningException { StringReader reader = new StringReader(body); JSONParser jsonParser = new JSONParser(); @@ -127,7 +192,20 @@ public ResponseEntity addConcepts(@RequestBody String body, Principal pr JSONObject jsonObject = listIt.next(); JsonValidationResult result = checkJsonObject(jsonObject); + + if (result.isValid() && jsonObject.get(JsonFields.WORDNET_ID) != null) { + result = checkJsonObjectForWrapper(jsonObject); + } + if (!result.isValid()) { + return new ResponseEntity(result.getMessage(), HttpStatus.BAD_REQUEST); + } + + ConceptEntry conceptEntry = createEntry(jsonObject, principal.getName()); + + if (jsonObject.get(JsonFields.WORDNET_ID) != null) { + validatePOS(jsonObject, conceptEntry); + } JSONObject responseObj = new JSONObject(); responseObj.put(JsonFields.WORD, jsonObject.get(JsonFields.WORD)); responseObj.put("validation", result.getMessage() != null ? result.getMessage() : "OK"); @@ -139,12 +217,10 @@ public ResponseEntity addConcepts(@RequestBody String body, Principal pr continue; } - ConceptEntry conceptEntry = createEntry(jsonObject, principal.getName()); - - String id = null; try { - id = conceptManager.addConceptListEntry(conceptEntry); - responseObj.put(JsonFields.ID, id); + conceptEntry.setId(conceptManager.addConceptListEntry(conceptEntry, principal.getName())); + responseObj.put(JsonFields.ID, conceptEntry.getId()); + responseObj.put(JsonFields.URI, uriHelper.getURI(conceptEntry)); responseObj.put("success", true); } catch (DictionaryDoesNotExistException e) { logger.error("Error creating concept from REST call.", e); @@ -156,14 +232,11 @@ public ResponseEntity addConcepts(@RequestBody String body, Principal pr responseObj.put("error_message", "Specified dictionary can't be modified."); } catch (LuceneException le) { logger.error("Error creating concept from REST call.", le); - return new ResponseEntity("Concept Cannot be added", HttpStatus.BAD_REQUEST); + return new ResponseEntity("Concept Cannot be added", HttpStatus.INTERNAL_SERVER_ERROR); } catch (IllegalAccessException e) { logger.error("Error creating concept from REST call.", e); return new ResponseEntity("Illegal Access", HttpStatus.BAD_REQUEST); - } catch (IndexerRunningException ir) { - return new ResponseEntity(jsonObject.toJSONString(), HttpStatus.CONFLICT); } - } HttpHeaders responseHeaders = new HttpHeaders(); @@ -173,22 +246,30 @@ public ResponseEntity addConcepts(@RequestBody String body, Principal pr HttpStatus.OK); } - private JsonValidationResult checkJsonObject(JSONObject jsonObject) { + private JsonValidationResult checkJsonObject(JSONObject jsonObject) + throws IllegalAccessException, LuceneException, IndexerRunningException { if (jsonObject.get(JsonFields.POS) == null) { return new JsonValidationResult("Error parsing request: please provide a POS ('pos' attribute).", jsonObject, false); } + String pos = jsonObject.get(JsonFields.POS).toString(); + if (!POS.posValues.contains(pos)) { + logger.debug("Error creating concept from REST call. " + pos + " does not exist."); + return new JsonValidationResult("Error parsing request: please provide a valid POS ('pos' attribute).", + jsonObject, false); + } + if (jsonObject.get(JsonFields.WORD) == null) { return new JsonValidationResult( "Error parsing request: please provide a word for the concept ('word' attribute).", jsonObject, false); } - if (jsonObject.get(JsonFields.DESCRIPTION) == null) { + if (jsonObject.get(JsonFields.CONCEPT_LIST) == null) { return new JsonValidationResult( - "Error parsing request: please provide a description for the concept ('description' attribute).", - jsonObject, false); + "Error parsing request: please provide a list name for the concept ('list' attribute).", jsonObject, + false); } if (jsonObject.get(JsonFields.TYPE) == null) { @@ -197,35 +278,79 @@ private JsonValidationResult checkJsonObject(JSONObject jsonObject) { false); } - if (jsonObject.get(JsonFields.CONCEPT_LIST) == null) { - return new JsonValidationResult( - "Error parsing request: please provide a concept list for the concept ('conceptlist' attribute).", - jsonObject, false); - } + return new JsonValidationResult(null, jsonObject, true); + } - String pos = jsonObject.get(JsonFields.POS).toString(); - if (!POS.posValues.contains(pos)) { - logger.error("Error creating concept from REST call. " + pos + " does not exist."); - return new JsonValidationResult("POS '" + pos + "' does not exist.", jsonObject, false); + private JsonValidationResult checkJsonObjectForWrapper(JSONObject jsonObject) + throws IllegalAccessException, LuceneException, IndexerRunningException { + + // Validation to check if wordnet ids are seperated by comma + if (jsonObject.get(JsonFields.WORDNET_ID) != null) { + String wordnetIds = jsonObject.get(JsonFields.WORDNET_ID).toString(); + List wordnetIdsList = Arrays + .asList(wordnetIds.split("\\s*" + Constants.CONCEPT_SEPARATOR + "\\s*")); + for (String wordNetId : wordnetIdsList) { + try{ + WordID.parseWordID(wordNetId); + } catch (IllegalArgumentException ex) { + return new JsonValidationResult( + "Error parsing request: please provide a valid list of wordnet ids seperated by commas. Wordnet id " + + wordNetId + " doesn't exist.", + jsonObject, false); + } + } + + // Check if there is an existing wrapper concept if so throw error + for (String wordNetId : wordnetIdsList) { + if (conceptManager.getConceptWrappedEntryByWordNetId(wordNetId) != null) { + // This wordnet id is already wrapped. Throw error + return new JsonValidationResult( + "Error parsing request: the WordNet concept you are trying to wrap is already wrapped.", + jsonObject, false); + } + } } return new JsonValidationResult(null, jsonObject, true); } + private JsonValidationResult validatePOS(JSONObject jsonObject, ConceptEntry entry) { + // In case user has entered a POS value. Validate whether POS is + // same as wordnet POS + if (!entry.getPos().equalsIgnoreCase(jsonObject.get(JsonFields.POS).toString())) { + return new JsonValidationResult( + "Error parsing request: please enter POS that matches with the wordnet POS " + entry.getPos(), + jsonObject, false); + } + return new JsonValidationResult(null, jsonObject, true); + } + private ConceptEntry createEntry(JSONObject jsonObject, String username) { ConceptEntry conceptEntry = new ConceptEntry(); - conceptEntry.setCreatorId(username); - conceptEntry.setSynonymIds(jsonObject.get(JsonFields.SYNONYM_IDS) != null ? jsonObject.get( - JsonFields.SYNONYM_IDS).toString() : ""); - conceptEntry.setWord(jsonObject.get(JsonFields.WORD).toString()); + if (jsonObject.get(JsonFields.WORDNET_ID) != null) { + conceptEntry.setWordnetId(jsonObject.get(JsonFields.WORDNET_ID).toString()); + String[] wrappers = jsonObject.get(JsonFields.WORDNET_ID).toString().split(Constants.CONCEPT_SEPARATOR); + if (wrappers.length > 0) { + ConceptEntry existingConceptEntry = conceptManager.getConceptEntry(wrappers[0]); + conceptEntry.setWord(existingConceptEntry.getWord().replace("_", " ")); + conceptEntry.setPos(existingConceptEntry.getPos()); + } + } else { + conceptEntry.setWord(jsonObject.get(JsonFields.WORD).toString()); + conceptEntry.setPos(jsonObject.get(JsonFields.POS).toString()); + } conceptEntry.setConceptList(jsonObject.get(JsonFields.CONCEPT_LIST).toString()); - conceptEntry.setPos(jsonObject.get(JsonFields.POS).toString()); - conceptEntry.setDescription(jsonObject.get(JsonFields.DESCRIPTION).toString()); - conceptEntry.setEqualTo(jsonObject.get(JsonFields.EQUALS) != null ? jsonObject.get(JsonFields.EQUALS) - .toString() : ""); - conceptEntry.setSimilarTo(jsonObject.get(JsonFields.SIMILAR) != null ? jsonObject.get(JsonFields.SIMILAR) - .toString() : ""); + conceptEntry.setCreatorId(username); + conceptEntry.setSynonymIds(jsonObject.get(JsonFields.SYNONYM_IDS) != null + ? jsonObject.get(JsonFields.SYNONYM_IDS).toString() : ""); + conceptEntry.setDescription(jsonObject.get(JsonFields.DESCRIPTION) != null + ? jsonObject.get(JsonFields.DESCRIPTION).toString() : ""); + conceptEntry.setEqualTo( + jsonObject.get(JsonFields.EQUALS) != null ? jsonObject.get(JsonFields.EQUALS).toString() : ""); + conceptEntry.setSimilarTo( + jsonObject.get(JsonFields.SIMILAR) != null ? jsonObject.get(JsonFields.SIMILAR).toString() : ""); conceptEntry.setTypeId(jsonObject.get(JsonFields.TYPE).toString()); + return conceptEntry; } diff --git a/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/rest/JsonFields.java b/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/rest/JsonFields.java similarity index 75% rename from Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/rest/JsonFields.java rename to Conceptpower+Spring/src/main/java/edu/asu/conceptpower/rest/JsonFields.java index 12615e314..22751ceaf 100644 --- a/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/rest/JsonFields.java +++ b/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/rest/JsonFields.java @@ -1,4 +1,4 @@ -package edu.asu.conceptpower.servlet.rest; +package edu.asu.conceptpower.rest; /** * Field names used for JSON payload and response when adding concepts through @@ -15,7 +15,9 @@ public interface JsonFields { public final static String CONCEPT_LIST = "conceptlist"; public final static String POS = "pos"; public final static String DESCRIPTION = "description"; - public final static String EQUALS = "equals"; + public final static String EQUALS = "equal_to"; public final static String SIMILAR = "similar"; public final static String TYPE = "type"; + public final static String URI = "uri"; + public final static String WORDNET_ID = "wordnetIds"; } \ No newline at end of file diff --git a/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/rest/SearchParamters.java b/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/rest/SearchParamters.java new file mode 100644 index 000000000..24a822f62 --- /dev/null +++ b/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/rest/SearchParamters.java @@ -0,0 +1,10 @@ +package edu.asu.conceptpower.rest; + +public interface SearchParamters { + + public final static String OPERATOR = "operator"; + public final static String OP_AND = "AND"; + public final static String OP_OR = "OR"; + public final static String PAGE = "page"; + public final static String NUMBER_OF_RECORDS_PER_PAGE = "number_of_records_per_page"; +} diff --git a/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/rest/SynonymSearch.java b/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/rest/SynonymSearch.java new file mode 100644 index 000000000..5e248d3bc --- /dev/null +++ b/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/rest/SynonymSearch.java @@ -0,0 +1,111 @@ +package edu.asu.conceptpower.rest; + +import java.util.HashMap; +import java.util.Map; + +import javax.servlet.http.HttpServletRequest; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.HttpHeaders; +import org.springframework.http.HttpStatus; +import org.springframework.http.MediaType; +import org.springframework.http.ResponseEntity; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.RequestHeader; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.bind.annotation.ResponseBody; + +import com.fasterxml.jackson.core.JsonProcessingException; + +import edu.asu.conceptpower.app.core.IConceptManager; +import edu.asu.conceptpower.app.db.TypeDatabaseClient; +import edu.asu.conceptpower.app.exceptions.LuceneException; +import edu.asu.conceptpower.core.ConceptEntry; +import edu.asu.conceptpower.core.ConceptType; +import edu.asu.conceptpower.rest.msg.IConceptMessage; +import edu.asu.conceptpower.rest.msg.IMessageRegistry; + +/** + * This class provides a method to retrieve all synonyms for a given concept + * identified by its id. It answers requests to: + * "http://[server.url]/conceptpower/rest/SynonymSearch?id={URI or ID of concept + * you want synonyms for}" + * + * @author Julia Damero, Chetan + * + */ +@Controller +public class SynonymSearch { + + @Autowired + private IConceptManager dictManager; + + @Autowired + private TypeDatabaseClient typeManager; + + @Autowired + private IMessageRegistry messageFactory; + + private static final Logger logger = LoggerFactory.getLogger(SynonymSearch.class); + + /** + * This method provides information of synonyms of a word for a rest + * interface of the form + * "http://[server.url]/conceptpower/rest/SynonymSearch?id={URI or ID of + * concept you want synonyms for}" + * + * @param req + * @return + * @throws JsonProcessingException + */ + @RequestMapping(value = "/SynonymSearch", method = RequestMethod.GET, produces = { MediaType.APPLICATION_XML_VALUE, + MediaType.APPLICATION_JSON_VALUE }) + public @ResponseBody ResponseEntity getSynonymsForId(HttpServletRequest req, + @RequestHeader(value = "Accept", defaultValue = MediaType.APPLICATION_XML_VALUE) String acceptHeader) + throws JsonProcessingException { + + // construct the URL to the Wordnet dictionary directory + String id = req.getParameter("id"); + if (id == null || id.trim().isEmpty()) { + return new ResponseEntity(HttpStatus.BAD_REQUEST); + } + + String[] pathParts = id.split("/"); + int lastIndex = pathParts.length - 1; + String wordnetId = null; + if (lastIndex > -1) + wordnetId = pathParts[lastIndex]; + + if (wordnetId == null) { + return new ResponseEntity(HttpStatus.BAD_REQUEST); + } + + ConceptEntry[] synonyms = null; + try { + synonyms = dictManager.getSynonymsForConcept(wordnetId); + } catch (LuceneException ex) { + logger.error("Lucene exception", ex); + return new ResponseEntity(ex.getMessage(), HttpStatus.INTERNAL_SERVER_ERROR); + } + String entries = null; + Map entryMap = new HashMap(); + + IConceptMessage msg = messageFactory.getMessageFactory(acceptHeader).createConceptMessage(); + for (ConceptEntry entry : synonyms) { + ConceptType type = null; + if (typeManager != null && entry.getTypeId() != null && !entry.getTypeId().trim().isEmpty()) { + type = typeManager.getType(entry.getTypeId()); + } + entryMap.put(entry, type); + entries = msg.getAllConceptEntriesAndPaginationDetails(entryMap, null); + } + + HttpHeaders responseHeaders = new HttpHeaders(); + responseHeaders.add("Content-Type", "text/html; charset=utf-8"); + + return new ResponseEntity(entries, responseHeaders, HttpStatus.OK); + } +} diff --git a/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/rest/TypeIdLookup.java b/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/rest/TypeIdLookup.java new file mode 100644 index 000000000..ada9ed7f7 --- /dev/null +++ b/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/rest/TypeIdLookup.java @@ -0,0 +1,91 @@ +package edu.asu.conceptpower.rest; + +import javax.servlet.http.HttpServletRequest; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.HttpStatus; +import org.springframework.http.MediaType; +import org.springframework.http.ResponseEntity; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.RequestHeader; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.bind.annotation.ResponseBody; + +import com.fasterxml.jackson.core.JsonProcessingException; + +import edu.asu.conceptpower.app.db.TypeDatabaseClient; +import edu.asu.conceptpower.core.ConceptType; +import edu.asu.conceptpower.rest.msg.IMessageRegistry; +import edu.asu.conceptpower.rest.msg.ITypeMessage; +import edu.asu.conceptpower.rest.msg.xml.XMLConstants; + +/** + * This class provides a method to query types by their ids. It answers requests + * to: "http://[server.url]/conceptpower/rest/Type?id={URI or ID of concept}" + * + * @author Julia Damerow, Chetan + * + */ +@Controller +public class TypeIdLookup { + + @Autowired + private TypeDatabaseClient typeManager; + + @Autowired + private IMessageRegistry messageFactory; + + /** + * This method provides information of a type for a rest interface of the + * form "http://[server.url]/conceptpower/rest/Type?id={URI or ID of + * concept}" + * + * @param req + * Holds HTTP request information + * @return + * @throws JsonProcessingException + */ + @RequestMapping(value = "/Type", method = RequestMethod.GET, produces = { MediaType.APPLICATION_XML_VALUE, + MediaType.APPLICATION_JSON_VALUE }) + public @ResponseBody ResponseEntity getTypeById(HttpServletRequest req, + @RequestHeader(value = "Accept", defaultValue = MediaType.APPLICATION_XML_VALUE) String acceptHeader) + throws JsonProcessingException { + + String id = req.getParameter("id"); + if (id == null) { + return new ResponseEntity(HttpStatus.BAD_REQUEST); + } + // get type id if URI is given + + String[] pathParts = id.split("/"); + int lastIndex = pathParts.length - 1; + String typeId = null; + if (lastIndex > -1) + typeId = pathParts[lastIndex]; + + if (typeId == null) { + return new ResponseEntity(HttpStatus.BAD_REQUEST); + } + + if (typeId.startsWith(XMLConstants.TYPE_PREFIX)) { + typeId = typeId.substring(XMLConstants.TYPE_PREFIX.length()); + } + + ConceptType type = typeManager.getType(typeId); + + ITypeMessage typeMessage = messageFactory.getMessageFactory(acceptHeader).createTypeMessage(); + + String entry = null; + if (type != null) { + ConceptType superType = null; + if (type.getSupertypeId() != null && !type.getSupertypeId().trim().isEmpty()) + superType = typeManager.getType(type.getSupertypeId().trim()); + entry = typeMessage.getConceptTypeMessage(type, superType); + } else { + return new ResponseEntity(HttpStatus.NOT_FOUND); + } + + return new ResponseEntity(entry, HttpStatus.OK); + } +} diff --git a/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/rest/msg/IConceptMessage.java b/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/rest/msg/IConceptMessage.java new file mode 100644 index 000000000..138fb0898 --- /dev/null +++ b/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/rest/msg/IConceptMessage.java @@ -0,0 +1,54 @@ +package edu.asu.conceptpower.rest.msg; + +import java.util.List; +import java.util.Map; + +import org.springframework.validation.ObjectError; + +import com.fasterxml.jackson.core.JsonProcessingException; + +import edu.asu.conceptpower.core.ConceptEntry; +import edu.asu.conceptpower.core.ConceptType; + +/** + * This class acts as an interface for all concept messages. Currently concepts + * are returned in json and xml format. So we have XmlConceptMessage and + * JsonConceptMessage implementing this class + * + * @author karthik + * + */ +public interface IConceptMessage { + + /** + * This method fetches the concept entries with the specified pagination. + * + * @param entries + * @param pagination + * @return + * @throws JsonProcessingException + */ + public String getAllConceptEntriesAndPaginationDetails(Map entries, + Pagination pagination) throws JsonProcessingException; + + /** + * This method provides the error messages in JSON and XML format + * respectively with the supplied error details. + * + * @param errors + * @return + * @throws JsonProcessingException + */ + public String getErrorMessages(List errors) throws JsonProcessingException; + + /** + * This method provides the error message in JSON and XML format. + * + * @param errorMessage + * @return + * @throws JsonProcessingException + */ + public String getErrorMessage(String errorMessage) throws JsonProcessingException; + +} + diff --git a/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/rest/msg/IMessageConverter.java b/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/rest/msg/IMessageConverter.java new file mode 100644 index 000000000..051bcc42e --- /dev/null +++ b/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/rest/msg/IMessageConverter.java @@ -0,0 +1,36 @@ +package edu.asu.conceptpower.rest.msg; + +/** + * This interface is implemented across all message converters in the + * application. Currently we have XML and JSON converters. These message + * converters are loaded from message registry. + * + * @author karthik + * + */ +public interface IMessageConverter { + + /** + * This method returns the instance of concept message based on the message + * converter. + * + * @return + */ + public IConceptMessage createConceptMessage(); + + /** + * This method returns the instance of concept type based on message + * converter. + * + * @return + */ + public ITypeMessage createTypeMessage(); + + /** + * This method returns the message converter type. + * + * @return + */ + public String getMediaType(); + +} diff --git a/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/rest/msg/IMessageRegistry.java b/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/rest/msg/IMessageRegistry.java new file mode 100644 index 000000000..890646efb --- /dev/null +++ b/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/rest/msg/IMessageRegistry.java @@ -0,0 +1,21 @@ +package edu.asu.conceptpower.rest.msg; + +/** + * This interface provide methods for obtaining message factory objects. + * + * @author karthik + * + */ +public interface IMessageRegistry { + + /** + * This method returns the message converter object based on the media type. + * Valid values for media types are defined by the registered message converters. + * Currently, registered media types are for XML or JSON. + * + * @param mediaType application/xml or application/json + * @return Message converter according to provided media type or null. + */ + public IMessageConverter getMessageFactory(String mediaType); + +} diff --git a/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/rest/msg/ITypeMessage.java b/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/rest/msg/ITypeMessage.java new file mode 100644 index 000000000..08cbc930e --- /dev/null +++ b/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/rest/msg/ITypeMessage.java @@ -0,0 +1,27 @@ +package edu.asu.conceptpower.rest.msg; + +import com.fasterxml.jackson.core.JsonProcessingException; + +import edu.asu.conceptpower.core.ConceptType; + +/** + * This interface provides method for converting the concept type to JSON or XML + * format. + * + * @author karthik + * + */ +public interface ITypeMessage { + + /** + * This method is used for converting the concept type and its corresponding + * super type to JSON or XML format. + * + * @param type + * @param supertype + * @return + * @throws JsonProcessingException + */ + public String getConceptTypeMessage(ConceptType type, ConceptType supertype) throws JsonProcessingException; + +} diff --git a/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/rest/msg/MessageRegistry.java b/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/rest/msg/MessageRegistry.java new file mode 100644 index 000000000..5f56b91ef --- /dev/null +++ b/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/rest/msg/MessageRegistry.java @@ -0,0 +1,57 @@ +package edu.asu.conceptpower.rest.msg; + + +import java.util.HashMap; +import java.util.Iterator; +import java.util.Map; + +import javax.annotation.PostConstruct; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.ApplicationContext; +import org.springframework.stereotype.Component; + +@Component +public class MessageRegistry implements IMessageRegistry { + + @Autowired + private ApplicationContext ctx; + + @Autowired + private IMessageConverter defaultMessageFactory; + + private Map messageConverterMap; + + /** + * Instantiates all the message converter services and loads into + * messageConverterMap with key as media type and value as the message + * converter service object. + * + */ + @PostConstruct + public void init() { + + messageConverterMap = new HashMap<>(); + Map messageConverterCtxMap = ctx.getBeansOfType(IMessageConverter.class); + Iterator converterIter = messageConverterCtxMap.entrySet().iterator(); + + while (converterIter.hasNext()) { + Map.Entry mEntry = (Map.Entry) converterIter.next(); + IMessageConverter serviceObject = (IMessageConverter) mEntry.getValue(); + messageConverterMap.put(serviceObject.getMediaType(), serviceObject); + } + } + + /** + * This method returns the message converter object based on the media type. + * Valid values for media type are accept headers of XML and JSON. Accept + * header of XML is application/xml and Accept header of JSON is + * application/json. + */ + public IMessageConverter getMessageFactory(String mediaType) { + if (messageConverterMap.get(mediaType) != null) { + return messageConverterMap.get(mediaType); + } + return defaultMessageFactory; + } +} diff --git a/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/rest/msg/Pagination.java b/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/rest/msg/Pagination.java new file mode 100644 index 000000000..efbab19ba --- /dev/null +++ b/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/rest/msg/Pagination.java @@ -0,0 +1,35 @@ +package edu.asu.conceptpower.rest.msg; + +/** + * This class contains the pagination details. This class will be serialized + * using Jackson + * + * @author karthikeyanmohan + * + */ +public class Pagination { + + private Integer pageNumber; + private Integer totalNumberOfRecords; + + public Pagination(Integer pageNumber, Integer totalNumberOfRecords) { + this.pageNumber = pageNumber; + this.totalNumberOfRecords = totalNumberOfRecords; + } + + public Integer getPageNumber() { + return pageNumber; + } + + public void setPageNumber(Integer pageNumber) { + this.pageNumber = pageNumber; + } + + public Integer getTotalNumberOfRecords() { + return totalNumberOfRecords; + } + + public void setTotalNumberOfRecords(Integer totalNumberOfRecords) { + this.totalNumberOfRecords = totalNumberOfRecords; + } +} diff --git a/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/rest/msg/json/AlternativeId.java b/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/rest/msg/json/AlternativeId.java new file mode 100644 index 000000000..24a3d779e --- /dev/null +++ b/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/rest/msg/json/AlternativeId.java @@ -0,0 +1,30 @@ +package edu.asu.conceptpower.rest.msg.json; + +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonInclude.Include; +import com.fasterxml.jackson.annotation.JsonProperty; + +@JsonInclude(Include.NON_NULL) +public class AlternativeId { + + @JsonProperty("concept_id") + private String conceptId; + @JsonProperty("concept_uri") + private String conceptUri; + + public String getConceptId() { + return conceptId; + } + + public void setConceptId(String conceptId) { + this.conceptId = conceptId; + } + + public String getConceptUri() { + return conceptUri; + } + + public void setConceptUri(String conceptUri) { + this.conceptUri = conceptUri; + } +} diff --git a/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/rest/msg/json/ConceptEntryMessage.java b/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/rest/msg/json/ConceptEntryMessage.java new file mode 100644 index 000000000..7e7a73fb9 --- /dev/null +++ b/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/rest/msg/json/ConceptEntryMessage.java @@ -0,0 +1,174 @@ +package edu.asu.conceptpower.rest.msg.json; + +import java.util.List; + +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonInclude.Include; +import com.fasterxml.jackson.annotation.JsonProperty; + +/** + * This class is used for serializing the concept entry details. This class will + * be serialized using Jackson + * + * @author karthikeyanmohan + * + */ +@JsonInclude(Include.NON_NULL) +public class ConceptEntryMessage { + + private String id; + + @JsonProperty("concept_uri") + private String conceptUri; + + private String lemma; + private String pos; + private String description; + private String conceptList; + + @JsonProperty("creator_id") + private String creatorId; + + @JsonProperty("equal_to") + private String equalTo; + + @JsonProperty("modified_by") + private String modifiedBy; + + @JsonProperty("similar_to") + private String similarTo; + + @JsonProperty("synonym_ids") + private String synonymIds; + + private ConceptTypeMessage type; + + private boolean deleted; + + @JsonProperty("wordnet_id") + private String wordnetId; + + @JsonProperty("alternativeIds") + private List alternativeIds; + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + public String getLemma() { + return lemma; + } + + public void setLemma(String lemma) { + this.lemma = lemma; + } + + public String getPos() { + return pos; + } + + public void setPos(String pos) { + this.pos = pos; + } + + public String getDescription() { + return description; + } + + public void setDescription(String description) { + this.description = description; + } + + public String getConceptList() { + return conceptList; + } + + public void setConceptList(String conceptList) { + this.conceptList = conceptList; + } + + public String getCreatorId() { + return creatorId; + } + + public void setCreatorId(String creatorId) { + this.creatorId = creatorId; + } + + public String getEqualTo() { + return equalTo; + } + + public void setEqualTo(String equalTo) { + this.equalTo = equalTo; + } + + public String getModifiedBy() { + return modifiedBy; + } + + public void setModifiedBy(String modifiedBy) { + this.modifiedBy = modifiedBy; + } + + public String getSimilarTo() { + return similarTo; + } + + public void setSimilarTo(String similarTo) { + this.similarTo = similarTo; + } + + public String getSynonymIds() { + return synonymIds; + } + + public void setSynonymIds(String synonymIds) { + this.synonymIds = synonymIds; + } + + public ConceptTypeMessage getType() { + return type; + } + + public void setType(ConceptTypeMessage type) { + this.type = type; + } + + public String getWordnetId() { + return wordnetId; + } + + public void setWordnetId(String wordnetId) { + this.wordnetId = wordnetId; + } + + public List getAlternativeIds() { + return alternativeIds; + } + + public void setAlternativeIds(List alternativeIds) { + this.alternativeIds = alternativeIds; + } + + public boolean isDeleted() { + return deleted; + } + + public void setDeleted(boolean deleted) { + this.deleted = deleted; + } + + public String getConceptUri() { + return conceptUri; + } + + public void setConceptUri(String conceptUri) { + this.conceptUri = conceptUri; + } + +} diff --git a/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/rest/msg/json/ConceptResult.java b/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/rest/msg/json/ConceptResult.java new file mode 100644 index 000000000..7854b9596 --- /dev/null +++ b/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/rest/msg/json/ConceptResult.java @@ -0,0 +1,37 @@ +package edu.asu.conceptpower.rest.msg.json; + +import java.util.List; + +import edu.asu.conceptpower.rest.msg.Pagination; + +/** + * This class will be serialized through Jackson for Json objects. This class + * will contain all the objects that need to be serialized. Currently, apart + * from ConceptMessage we have Pagination object, but in future if we introduce + * any new utilities that needs to be added to JSON, we can create that object + * and add it to the ConceptResult class. + * + * @author karthikeyanmohan + * + */ +public class ConceptResult { + + private List conceptEntries; + private Pagination pagination; + + public List getConceptEntries() { + return conceptEntries; + } + + public void setConceptEntries(List conceptEntries) { + this.conceptEntries = conceptEntries; + } + + public Pagination getPagination() { + return pagination; + } + + public void setPagination(Pagination pagination) { + this.pagination = pagination; + } +} diff --git a/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/rest/msg/json/ConceptTypeMessage.java b/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/rest/msg/json/ConceptTypeMessage.java new file mode 100644 index 000000000..546a58675 --- /dev/null +++ b/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/rest/msg/json/ConceptTypeMessage.java @@ -0,0 +1,94 @@ +package edu.asu.conceptpower.rest.msg.json; + +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonInclude.Include; +import com.fasterxml.jackson.annotation.JsonProperty; + +@JsonInclude(Include.NON_NULL) +public class ConceptTypeMessage { + + @JsonProperty("type_id") + private String typeId; + + @JsonProperty("type_uri") + private String typeUri; + + @JsonProperty("type_name") + private String typeName; + + private String description; + + @JsonProperty("creator_id") + private String creatorId; + + private String matches; + + private ConceptTypeMessage superType; + + @JsonProperty("modified_by") + private String modifiedBy; + + public String getTypeId() { + return typeId; + } + + public void setTypeId(String typeId) { + this.typeId = typeId; + } + + public String getTypeUri() { + return typeUri; + } + + public void setTypeUri(String typeUri) { + this.typeUri = typeUri; + } + + public String getTypeName() { + return typeName; + } + + public void setTypeName(String typeName) { + this.typeName = typeName; + } + + public String getDescription() { + return description; + } + + public void setDescription(String description) { + this.description = description; + } + + public String getCreatorId() { + return creatorId; + } + + public void setCreatorId(String creatorId) { + this.creatorId = creatorId; + } + + public String getMatches() { + return matches; + } + + public void setMatches(String matches) { + this.matches = matches; + } + + public String getModifiedBy() { + return modifiedBy; + } + + public void setModifiedBy(String modifiedBy) { + this.modifiedBy = modifiedBy; + } + + public ConceptTypeMessage getSuperType() { + return superType; + } + + public void setSuperType(ConceptTypeMessage superType) { + this.superType = superType; + } +} diff --git a/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/rest/msg/json/ErrorMessage.java b/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/rest/msg/json/ErrorMessage.java new file mode 100644 index 000000000..220cbeb1f --- /dev/null +++ b/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/rest/msg/json/ErrorMessage.java @@ -0,0 +1,18 @@ +package edu.asu.conceptpower.rest.msg.json; + +public class ErrorMessage { + + private String message; + + public ErrorMessage(String message) { + this.message = message; + } + + public String getMessage() { + return message; + } + + public void setMessage(String message) { + this.message = message; + } +} diff --git a/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/rest/msg/json/JsonConceptMessage.java b/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/rest/msg/json/JsonConceptMessage.java new file mode 100644 index 000000000..61db350e0 --- /dev/null +++ b/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/rest/msg/json/JsonConceptMessage.java @@ -0,0 +1,132 @@ +package edu.asu.conceptpower.rest.msg.json; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.Map; + +import org.springframework.validation.ObjectError; + +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.ObjectMapper; + +import edu.asu.conceptpower.app.util.URIHelper; +import edu.asu.conceptpower.core.ConceptEntry; +import edu.asu.conceptpower.core.ConceptType; +import edu.asu.conceptpower.rest.msg.IConceptMessage; +import edu.asu.conceptpower.rest.msg.Pagination; +import edu.asu.conceptpower.servlet.core.ChangeEvent; + +/** + * This class helps to convert the given object to json. This class loads the + * data from concept entry to concept message. If pagination details are passed, + * then pagination details and concept message details are added to + * ConceptMessagePagination class and final json is created. + * + * @author karthikeyanmohan + * + */ +public class JsonConceptMessage implements IConceptMessage { + + private URIHelper uriCreator; + + public JsonConceptMessage(URIHelper uriCreator) { + this.uriCreator = uriCreator; + } + + private ConceptEntryMessage getConceptMessage(ConceptEntry entry, ConceptType type) { + + ConceptEntryMessage json = new ConceptEntryMessage(); + + json.setId(entry.getId()); + json.setConceptUri(uriCreator.getURI(entry)); + json.setLemma(entry.getWord()); + json.setPos(entry.getPos()); + json.setDescription(entry.getDescription()); + json.setConceptList(entry.getConceptList()); + + if (entry.getChangeEvents() != null && !entry.getChangeEvents().isEmpty()) { + List changeEvents = entry.getChangeEvents(); + Collections.sort(changeEvents); + json.setCreatorId( + changeEvents.get(0).getUserName() != null ? changeEvents.get(0).getUserName().trim() : ""); + } else { + json.setCreatorId(entry.getCreatorId() != null ? entry.getCreatorId().trim() : ""); + } + + json.setEqualTo(entry.getEqualTo() != null ? entry.getEqualTo().trim() : ""); + json.setModifiedBy(entry.getModified() != null ? entry.getModified().trim() : ""); + json.setSimilarTo(entry.getSimilarTo() != null ? entry.getSimilarTo().trim() : ""); + json.setSynonymIds(entry.getSynonymIds() != null ? entry.getSynonymIds().trim() : ""); + + if (type != null) { + ConceptTypeMessage jsonType = new ConceptTypeMessage(); + jsonType.setTypeId(type.getTypeId()); + jsonType.setTypeUri(uriCreator.getTypeURI(type)); + jsonType.setTypeName(type.getTypeName()); + + json.setType(jsonType); + } + + json.setDeleted(entry.isDeleted()); + json.setWordnetId(entry.getWordnetId() != null ? entry.getWordnetId().trim() : ""); + + if (entry.getAlternativeIds() != null && !entry.getAlternativeIds().isEmpty()) { + Map uriMap = uriCreator.getUrisBasedOnIds(entry.getAlternativeIds()); + if (uriMap != null && !uriMap.isEmpty()) { + List alternativeIds = new ArrayList<>(); + for (Map.Entry uri : uriMap.entrySet()) { + AlternativeId alternativeId = new AlternativeId(); + alternativeId.setConceptId(uri.getKey()); + alternativeId.setConceptUri(uri.getValue()); + alternativeIds.add(alternativeId); + } + json.setAlternativeIds(alternativeIds); + } + } + return json; + } + + @Override + public String getErrorMessages(List errors) throws JsonProcessingException { + List errorMessages = new ArrayList<>(); + for (ObjectError error : errors) { + ErrorMessage errorMessage = new ErrorMessage(error.getDefaultMessage()); + errorMessages.add(errorMessage); + } + ObjectMapper mapper = new ObjectMapper(); + return mapper.writeValueAsString(errorMessages); + } + + @Override + public String getErrorMessage(String errorMessage) throws JsonProcessingException { + ErrorMessage errorMessageObj = new ErrorMessage(errorMessage); + ObjectMapper mapper = new ObjectMapper(); + return mapper.writeValueAsString(errorMessageObj); + } + + @Override + public String getAllConceptEntriesAndPaginationDetails(Map entries, + Pagination pagination) throws JsonProcessingException { + + if (entries == null || entries.isEmpty()) { + ErrorMessage errorMessage = new ErrorMessage("No concept entry found."); + ObjectMapper mapper = new ObjectMapper(); + return mapper.writeValueAsString(errorMessage); + } + + List conceptMessages = new ArrayList<>(); + for (ConceptEntry entry : entries.keySet()) { + conceptMessages.add(getConceptMessage(entry, entries.get(entry))); + } + + ConceptResult conceptResult = new ConceptResult(); + conceptResult.setConceptEntries(conceptMessages); + if (pagination != null) { + conceptResult.setPagination(pagination); + } + ObjectMapper mapper = new ObjectMapper(); + return mapper.writeValueAsString(conceptResult); + } + +} diff --git a/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/rest/msg/json/JsonMessageFactory.java b/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/rest/msg/json/JsonMessageFactory.java new file mode 100644 index 000000000..8809bcbdb --- /dev/null +++ b/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/rest/msg/json/JsonMessageFactory.java @@ -0,0 +1,32 @@ +package edu.asu.conceptpower.rest.msg.json; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.MediaType; +import org.springframework.stereotype.Component; + +import edu.asu.conceptpower.app.util.URIHelper; +import edu.asu.conceptpower.rest.msg.IConceptMessage; +import edu.asu.conceptpower.rest.msg.IMessageConverter; +import edu.asu.conceptpower.rest.msg.ITypeMessage; + +@Component +public class JsonMessageFactory implements IMessageConverter { + + @Autowired + private URIHelper uriCreator; + + public IConceptMessage createConceptMessage() { + return new JsonConceptMessage(uriCreator); + } + + @Override + public ITypeMessage createTypeMessage() { + return new JsonTypeMessage(uriCreator); + } + + @Override + public String getMediaType() { + return MediaType.APPLICATION_JSON_VALUE; + } + +} diff --git a/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/rest/msg/json/JsonTypeMessage.java b/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/rest/msg/json/JsonTypeMessage.java new file mode 100644 index 000000000..0f3328f16 --- /dev/null +++ b/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/rest/msg/json/JsonTypeMessage.java @@ -0,0 +1,44 @@ +package edu.asu.conceptpower.rest.msg.json; + +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.ObjectMapper; + +import edu.asu.conceptpower.app.util.URIHelper; +import edu.asu.conceptpower.core.ConceptType; +import edu.asu.conceptpower.rest.msg.ITypeMessage; + +public class JsonTypeMessage implements ITypeMessage { + + private URIHelper uriCreator; + + public JsonTypeMessage(URIHelper uriCreator) { + this.uriCreator = uriCreator; + } + + @Override + public String getConceptTypeMessage(ConceptType type, ConceptType supertype) throws JsonProcessingException { + + ConceptTypeMessage jsonType = new ConceptTypeMessage(); + if (type != null) { + jsonType.setTypeId(type.getTypeId()); + jsonType.setTypeUri(uriCreator.getTypeURI(type)); + } + jsonType.setDescription(type.getDescription()); + jsonType.setCreatorId( + type.getCreatorId() != null ? type.getCreatorId().trim() : ""); + jsonType.setMatches(type.getMatches() != null ? type.getMatches().trim() : ""); + jsonType.setModifiedBy(type.getModified() != null ? type.getModified().trim() : ""); + // supertype + if (supertype != null) { + ConceptTypeMessage superTypeJson = new ConceptTypeMessage(); + superTypeJson.setTypeId(supertype.getTypeId()); + superTypeJson.setTypeUri(uriCreator.getTypeURI(supertype)); + superTypeJson.setTypeName(supertype.getTypeName() != null ? supertype.getTypeName() : ""); + jsonType.setSuperType(superTypeJson); + } + + ObjectMapper mapper = new ObjectMapper(); + return mapper.writeValueAsString(jsonType); + } + +} diff --git a/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/rest/msg/xml/XMLConceptMessage.java b/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/rest/msg/xml/XMLConceptMessage.java new file mode 100644 index 000000000..1adf56911 --- /dev/null +++ b/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/rest/msg/xml/XMLConceptMessage.java @@ -0,0 +1,212 @@ +package edu.asu.conceptpower.rest.msg.xml; + +import java.util.Collections; +import java.util.List; +import java.util.Map; + +import org.apache.commons.lang3.StringEscapeUtils; +import org.springframework.validation.ObjectError; + +import edu.asu.conceptpower.app.util.URIHelper; +import edu.asu.conceptpower.core.ConceptEntry; +import edu.asu.conceptpower.core.ConceptType; +import edu.asu.conceptpower.rest.msg.IConceptMessage; +import edu.asu.conceptpower.rest.msg.Pagination; +import edu.asu.conceptpower.servlet.core.ChangeEvent; + +/** + * This class is used to build XML messages that are sent back as responses to + * the client. The classes collections concepts and transforms them into XML. + * + * @author Julia Damerow + * + */ +public class XMLConceptMessage implements IConceptMessage { + + private URIHelper uriCreator; + + public XMLConceptMessage(URIHelper uriCreator) { + this.uriCreator = uriCreator; + } + + /** + * This method fetches all the concept entries with the specified pagination + * details. If pagination is not specified then only the concept entries + * messages are returned. + */ + @Override + public String getAllConceptEntriesAndPaginationDetails(Map entries, + Pagination pagination) { + StringBuffer sb = new StringBuffer(""); + sb.append("<" + XMLConstants.CONCEPTPOWER_ANSWER + " xmlns:" + XMLConstants.NAMESPACE_PREFIX + "=\"" + + XMLConstants.NAMESPACE + "\">"); + sb.append(getAllConceptEntries(entries)); + if (pagination != null) { + sb.append(appendPaginationDetails(pagination.getTotalNumberOfRecords(), pagination.getPageNumber())); + } + sb.append(""); + return sb.toString(); + } + + private String getAllConceptEntries(Map entries) { + if (entries == null || entries.isEmpty()) { + return getErrorMessage("No concept entry found."); + } + StringBuilder xmlEntries = new StringBuilder(); + for (ConceptEntry entry : entries.keySet()) + xmlEntries.append(getConceptMessage(entry, entries.get(entry))); + return xmlEntries.toString(); + } + + private String getConceptMessage(ConceptEntry entry, ConceptType type) { + StringBuffer sb = new StringBuffer(); + + sb.append("<" + XMLConstants.NAMESPACE_PREFIX + ":" + XMLConstants.CONCEPT_ENTRY + ">"); + + // id + sb.append("<" + XMLConstants.NAMESPACE_PREFIX + ":" + XMLConstants.ID + " "); + sb.append(XMLConstants.CONCEPT_ID + "=\"" + entry.getId() + "\" "); + sb.append(XMLConstants.CONCEPT_URI + "=\"" + uriCreator.getURI(entry) + "\""); + sb.append(">"); + sb.append(uriCreator.getURI(entry)); + sb.append(""); + + // lemma + sb.append("<" + XMLConstants.NAMESPACE_PREFIX + ":" + XMLConstants.LEMMA + ">"); + sb.append(StringEscapeUtils.escapeXml10(entry.getWord())); + sb.append(""); + + // pos + sb.append("<" + XMLConstants.NAMESPACE_PREFIX + ":" + XMLConstants.POS + ">"); + sb.append(entry.getPos()); + sb.append(""); + + // description + sb.append("<" + XMLConstants.NAMESPACE_PREFIX + ":" + XMLConstants.DESCRIPTION + ">"); + sb.append(StringEscapeUtils.escapeXml10(entry.getDescription())); + sb.append(""); + + // concept list + sb.append("<" + XMLConstants.NAMESPACE_PREFIX + ":" + XMLConstants.CONCEPT_LIST + ">"); + sb.append(StringEscapeUtils.escapeXml10(entry.getConceptList())); + sb.append(""); + + // creator id + if (entry.getChangeEvents() != null && !entry.getChangeEvents().isEmpty()) { + List changeEvents = entry.getChangeEvents(); + Collections.sort(changeEvents); + sb.append("<" + XMLConstants.NAMESPACE_PREFIX + ":" + XMLConstants.CREATOR_ID + ">"); + sb.append(StringEscapeUtils.escapeXml10( + changeEvents.get(0).getUserName() != null ? changeEvents.get(0).getUserName().trim() : "")); + sb.append(""); + } else { + // creator id + sb.append("<" + XMLConstants.NAMESPACE_PREFIX + ":" + XMLConstants.CREATOR_ID + ">"); + sb.append(StringEscapeUtils.escapeXml10(entry.getCreatorId() != null ? entry.getCreatorId().trim() : "")); + sb.append(""); + } + + // equal to + sb.append("<" + XMLConstants.NAMESPACE_PREFIX + ":" + XMLConstants.EQUAL_TO + ">"); + sb.append(StringEscapeUtils.escapeXml10(entry.getEqualTo() != null ? entry.getEqualTo().trim() : "")); + sb.append(""); + + // modified by + sb.append("<" + XMLConstants.NAMESPACE_PREFIX + ":" + XMLConstants.MODIFIED_BY + ">"); + sb.append(StringEscapeUtils.escapeXml10(entry.getModified() != null ? entry.getModified().trim() : "")); + sb.append(""); + + // similar to + sb.append("<" + XMLConstants.NAMESPACE_PREFIX + ":" + XMLConstants.SIMILAR_TO + ">"); + sb.append(StringEscapeUtils.escapeXml10(entry.getSimilarTo() != null ? entry.getSimilarTo().trim() : "")); + sb.append(""); + + // synonym ids + sb.append("<" + XMLConstants.NAMESPACE_PREFIX + ":" + XMLConstants.SYNONYM_IDS + ">"); + sb.append(StringEscapeUtils.escapeXml10(entry.getSynonymIds() != null ? entry.getSynonymIds().trim() : "")); + sb.append(""); + + // type + sb.append("<" + XMLConstants.NAMESPACE_PREFIX + ":" + XMLConstants.TYPE + " "); + if (type != null) { + sb.append(XMLConstants.TYPE_ID_ATTR + "=\"" + type.getTypeId() + "\" "); + sb.append(XMLConstants.TYPE_URI_ATTR + "=\"" + uriCreator.getTypeURI(type) + "\""); + } + sb.append(">"); + if (type != null) + sb.append(StringEscapeUtils.escapeXml10(type.getTypeName())); + sb.append(""); + + // is deleted + sb.append("<" + XMLConstants.NAMESPACE_PREFIX + ":" + XMLConstants.IS_DELETED + ">"); + sb.append(entry.isDeleted() + ""); + sb.append(""); + + // wordnet id + sb.append("<" + XMLConstants.NAMESPACE_PREFIX + ":" + XMLConstants.WORDNET_ID + ">"); + sb.append(StringEscapeUtils.escapeXml10(entry.getWordnetId() != null ? entry.getWordnetId().trim() : "")); + sb.append(""); + + // Adding alternative ids and their corresponding uris + if (entry.getAlternativeIds() != null && !entry.getAlternativeIds().isEmpty()) { + Map uriMap = uriCreator.getUrisBasedOnIds(entry.getAlternativeIds()); + if (uriMap != null && !uriMap.isEmpty()) { + sb.append("<" + XMLConstants.NAMESPACE_PREFIX + ":" + XMLConstants.ALTERNATIVE_IDS + ">"); + for (Map.Entry uri : uriMap.entrySet()) { + sb.append("<" + XMLConstants.NAMESPACE_PREFIX + ":" + XMLConstants.ID + " "); + sb.append(XMLConstants.CONCEPT_ID + "=\"" + uri.getKey() + "\" "); + sb.append(XMLConstants.CONCEPT_URI + "=\"" + uri.getValue() + "\""); + sb.append(">"); + sb.append(uri.getValue()); + sb.append(""); + } + sb.append(""); + } + + } + + sb.append(""); + + return sb.toString(); + } + + @Override + public String getErrorMessages(List errors) { + + StringBuilder sb = new StringBuilder(); + sb.append("<" + XMLConstants.CONCEPTPOWER_ANSWER + " xmlns:" + XMLConstants.NAMESPACE_PREFIX + "=\"" + + XMLConstants.NAMESPACE + "\">"); + for (ObjectError error : errors) { + sb.append("<" + XMLConstants.NAMESPACE_PREFIX + ":" + XMLConstants.ERROR + " "); + sb.append(XMLConstants.ERROR_MESSAGE + "=\"" + error.getDefaultMessage() + "\" "); + sb.append(">"); + sb.append(""); + } + sb.append(""); + return sb.toString(); + + } + + @Override + public String getErrorMessage(String errorMessage) { + StringBuilder sb = new StringBuilder(); + sb.append("<" + XMLConstants.CONCEPTPOWER_ANSWER + " xmlns:" + XMLConstants.NAMESPACE_PREFIX + "=\"" + + XMLConstants.NAMESPACE + "\">"); + sb.append("<" + XMLConstants.NAMESPACE_PREFIX + ":" + XMLConstants.ERROR + " "); + sb.append(XMLConstants.ERROR_MESSAGE + "=\"" + errorMessage + "\" "); + sb.append(">"); + sb.append(""); + sb.append(""); + return sb.toString(); + } + + private String appendPaginationDetails(int numberOfRecords, int pageNumber) { + StringBuilder sb = new StringBuilder(); + sb.append("<" + XMLConstants.NAMESPACE_PREFIX + ":" + XMLConstants.PAGINATION + " "); + sb.append(XMLConstants.NUMBER_OF_RECORDS + "=\"" + numberOfRecords + "\" "); + sb.append(XMLConstants.PAGE_NUMBER + "=\"" + pageNumber + "\" "); + sb.append(">"); + sb.append(""); + return sb.toString(); + } +} diff --git a/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/rest/msg/xml/XMLConstants.java b/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/rest/msg/xml/XMLConstants.java new file mode 100644 index 000000000..77d40173c --- /dev/null +++ b/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/rest/msg/xml/XMLConstants.java @@ -0,0 +1,44 @@ +package edu.asu.conceptpower.rest.msg.xml; + +public interface XMLConstants { + + public final static String NAMESPACE = "http://www.digitalhps.org/"; + public final static String NAMESPACE_PREFIX = "digitalHPS"; + public final static String ID_NAMESPACE = "http://www.digitalhps.org/concepts/"; + public final static String TYPE_NAMESPACE = "http://www.digitalhps.org/types/"; + public final static String TYPE_PREFIX = "TYPE_"; + public final static String LIST_NAMESPACE = "http://www.digitalhps.org/lists/"; + public final static String WORDNET_NAMESPACE = "http://www.digitalhps.org/wordnet/"; + + // nodes + public final static String CONCEPTPOWER_ANSWER = "conceptpowerReply"; + public final static String CONCEPT_ENTRY = "conceptEntry"; + public final static String TYPE_ENTRY = "type_entry"; + public final static String PAGINATION = "pagination"; + public final static String ERROR = "error"; + + public final static String ID = "id"; + public final static String CONCEPT_URI = "concept_uri"; + public final static String CONCEPT_ID = "concept_id"; + + public final static String POS = "pos"; + public final static String LEMMA = "lemma"; + public final static String DESCRIPTION = "description"; + public final static String CONCEPT_LIST = "conceptList"; + public final static String CREATOR_ID = "creator_id"; + public final static String EQUAL_TO = "equal_to"; + public final static String MODIFIED_BY = "modified_by"; + public final static String SIMILAR_TO = "similar_to"; + public final static String SYNONYM_IDS = "synonym_ids"; + public final static String IS_DELETED = "deleted"; + public final static String WORDNET_ID = "wordnet_id"; + public final static String TYPE = "type"; + public final static String SUPERTYPE = "supertype"; + public final static String TYPE_ID_ATTR = "type_id"; + public final static String TYPE_URI_ATTR = "type_uri"; + public final static String MATCHES = "matches"; + public final static String NUMBER_OF_RECORDS = "number_of_records"; + public final static String PAGE_NUMBER = "page_number"; + public final static String ERROR_MESSAGE = "error_message"; + public final static String ALTERNATIVE_IDS = "alternativeIds"; +} diff --git a/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/rest/msg/xml/XMLMessageFactory.java b/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/rest/msg/xml/XMLMessageFactory.java new file mode 100644 index 000000000..6a657a7b7 --- /dev/null +++ b/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/rest/msg/xml/XMLMessageFactory.java @@ -0,0 +1,31 @@ +package edu.asu.conceptpower.rest.msg.xml; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.annotation.Primary; +import org.springframework.http.MediaType; +import org.springframework.stereotype.Component; + +import edu.asu.conceptpower.app.util.URIHelper; +import edu.asu.conceptpower.rest.msg.IConceptMessage; +import edu.asu.conceptpower.rest.msg.IMessageConverter; + +@Primary +@Component +public class XMLMessageFactory implements IMessageConverter { + + @Autowired + private URIHelper uriCreator; + + public IConceptMessage createConceptMessage() { + return new XMLConceptMessage(uriCreator); + } + + public XMLTypeMessage createTypeMessage() { + return new XMLTypeMessage(uriCreator); + } + + @Override + public String getMediaType() { + return MediaType.APPLICATION_XML_VALUE; + } +} diff --git a/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/rest/msg/xml/XMLTypeMessage.java b/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/rest/msg/xml/XMLTypeMessage.java new file mode 100644 index 000000000..05d5840bd --- /dev/null +++ b/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/rest/msg/xml/XMLTypeMessage.java @@ -0,0 +1,92 @@ +package edu.asu.conceptpower.rest.msg.xml; + +import org.apache.commons.lang3.StringEscapeUtils; + +import edu.asu.conceptpower.app.util.URIHelper; +import edu.asu.conceptpower.core.ConceptType; +import edu.asu.conceptpower.rest.msg.ITypeMessage; + +/** + * This class is used to create XML responses for + * type queries. + * + * @author Julia Damerow + * + */ +public class XMLTypeMessage implements ITypeMessage { + + private URIHelper uriCreator; + + public XMLTypeMessage(URIHelper uriCreator) { + this.uriCreator = uriCreator; + } + + public String getConceptTypeMessage(ConceptType type, ConceptType supertype) { + + StringBuffer sb = new StringBuffer(); + + sb.append("<" + XMLConstants.CONCEPTPOWER_ANSWER + " xmlns:" + XMLConstants.NAMESPACE_PREFIX + "=\"" + + XMLConstants.NAMESPACE + "\">"); + + // start entry + sb.append("<" + XMLConstants.NAMESPACE_PREFIX + ":" + XMLConstants.TYPE_ENTRY + ">"); + + // type uri, id + sb.append("<" + XMLConstants.NAMESPACE_PREFIX + ":" + XMLConstants.TYPE + + " "); + if (type != null) { + sb.append(XMLConstants.TYPE_ID_ATTR + "=\"" + type.getTypeId() + + "\" "); + sb.append(XMLConstants.TYPE_URI_ATTR + "=\"" + + uriCreator.getTypeURI(type) + "\""); + } + sb.append(">"); + if (type != null) + sb.append(StringEscapeUtils.escapeXml10(type.getTypeName())); + sb.append(""); + + // type description + sb.append("<" + XMLConstants.NAMESPACE_PREFIX + ":" + XMLConstants.DESCRIPTION + ">"); + sb.append(StringEscapeUtils.escapeXml10(type.getDescription())); + sb.append(""); + + // creator id + sb.append("<" + XMLConstants.NAMESPACE_PREFIX + ":" + XMLConstants.CREATOR_ID + ">"); + sb.append(StringEscapeUtils.escapeXml10(type.getCreatorId() != null ? type + .getCreatorId().trim() : "")); + sb.append(""); + + // matches + sb.append("<" + XMLConstants.NAMESPACE_PREFIX + ":" + XMLConstants.MATCHES + ">"); + sb.append(StringEscapeUtils.escapeXml10(type.getMatches() != null ? type + .getMatches().trim() : "")); + sb.append(""); + + // modified by + sb.append("<" + XMLConstants.NAMESPACE_PREFIX + ":" + XMLConstants.MODIFIED_BY + ">"); + sb.append(StringEscapeUtils.escapeXml10(type.getModified() != null ? type + .getModified().trim() : "")); + sb.append(""); + + // supertype + if (supertype != null) { + sb.append("<" + XMLConstants.NAMESPACE_PREFIX + ":" + XMLConstants.SUPERTYPE + " "); + + sb.append(XMLConstants.TYPE_ID_ATTR + "=\"" + supertype.getTypeId() + + "\" "); + sb.append(XMLConstants.TYPE_URI_ATTR + "=\"" + + uriCreator.getTypeURI(supertype) + "\""); + + sb.append(">"); + sb.append(StringEscapeUtils.escapeXml10(supertype.getTypeName())); + sb.append(""); + } + + // end entry + sb.append(""); + + sb.append(""); + + return sb.toString(); + } +} diff --git a/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/rest/util/RestExceptionHandler.java b/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/rest/util/RestExceptionHandler.java new file mode 100644 index 000000000..13abd4c8d --- /dev/null +++ b/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/rest/util/RestExceptionHandler.java @@ -0,0 +1,68 @@ +package edu.asu.conceptpower.rest.util; + +import javax.servlet.http.HttpServletRequest; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.security.access.AccessDeniedException; +import org.springframework.security.authentication.BadCredentialsException; +import org.springframework.web.bind.annotation.ControllerAdvice; + +import com.fasterxml.jackson.core.JsonProcessingException; + +import edu.asu.conceptpower.app.exceptions.IndexerRunningException; +import edu.asu.conceptpower.rest.msg.IConceptMessage; +import edu.asu.conceptpower.rest.msg.IMessageRegistry; + +/** + * This class handles the exceptions from rest interface calls. + * + * @author karthikeyanmohan + * + */ +@ControllerAdvice +public class RestExceptionHandler { + + @Autowired + private IMessageRegistry messageRegistry; + + private static final Logger logger = LoggerFactory.getLogger(RestExceptionHandler.class); + + @org.springframework.web.bind.annotation.ExceptionHandler(value = IllegalArgumentException.class) + public ResponseEntity handleIllegalArgumentException(IllegalArgumentException ex) { + logger.error("Illegal argument exception.", ex); + return new ResponseEntity(HttpStatus.INTERNAL_SERVER_ERROR); + } + + @org.springframework.web.bind.annotation.ExceptionHandler(value = IllegalAccessException.class) + public ResponseEntity handleIllegalAccessException(IllegalAccessException ex) { + logger.error("Illegal access exception.", ex); + return new ResponseEntity(HttpStatus.INTERNAL_SERVER_ERROR); + } + + @org.springframework.web.bind.annotation.ExceptionHandler(value = BadCredentialsException.class) + public ResponseEntity handleAuthenticationFailure(BadCredentialsException ex) { + return new ResponseEntity(HttpStatus.UNAUTHORIZED); + } + + @org.springframework.web.bind.annotation.ExceptionHandler(value = AccessDeniedException.class) + public ResponseEntity handleAccessDenied(AccessDeniedException ex) { + return new ResponseEntity(HttpStatus.UNAUTHORIZED); + } + + @org.springframework.web.bind.annotation.ExceptionHandler(value = JsonProcessingException.class) + public ResponseEntity handleJsonProcessingException(JsonProcessingException ex) { + return new ResponseEntity("Problems in processing json.", HttpStatus.INTERNAL_SERVER_ERROR); + } + + @org.springframework.web.bind.annotation.ExceptionHandler(value = IndexerRunningException.class) + public ResponseEntity handleIndexerRunningException(HttpServletRequest req, IndexerRunningException ex) + throws JsonProcessingException { + logger.info("Indexer running exception", ex); + IConceptMessage msg = messageRegistry.getMessageFactory(req.getHeader("Accept")).createConceptMessage(); + return new ResponseEntity(msg.getErrorMessage(ex.getMessage()), HttpStatus.SERVICE_UNAVAILABLE); + } +} diff --git a/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/root/DatabaseManager.java b/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/root/DatabaseManager.java deleted file mode 100644 index 7257dc229..000000000 --- a/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/root/DatabaseManager.java +++ /dev/null @@ -1,55 +0,0 @@ -package edu.asu.conceptpower.root; - -import java.io.Serializable; - -import com.db4o.ObjectContainer; -import com.db4o.ObjectServer; -import com.db4o.cs.Db4oClientServer; -import com.db4o.cs.config.ServerConfiguration; - -import edu.asu.conceptpower.core.ConceptEntry; - -public class DatabaseManager implements Serializable { - - /** - * - */ - private static final long serialVersionUID = -3325272288078647257L; - private ObjectServer server; - private String databasePath; - - public void init() { - close(); - ServerConfiguration configuration = Db4oClientServer - .newServerConfiguration(); - configuration.file().blockSize(80); - configuration.common().objectClass(ConceptEntry.class).objectField("wordnetId").indexed(true); - configuration.common().objectClass(ConceptEntry.class).objectField("id").indexed(true); - server = Db4oClientServer.openServer(configuration, databasePath, 0); - - } - - public ObjectContainer getClient() { - ObjectContainer container = server.openClient(); - return container; - } - - public String getDatabasePath() { - return databasePath; - } - - public void setDatabasePath(String databasePath) { - this.databasePath = databasePath; - } - - private void close() { - if (server != null) { - server.close(); - } - server = null; - } - - public void shutdown() { - close(); - } -} diff --git a/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/root/TypeDatabaseClient.java b/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/root/TypeDatabaseClient.java deleted file mode 100644 index 61b6935bf..000000000 --- a/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/root/TypeDatabaseClient.java +++ /dev/null @@ -1,90 +0,0 @@ -package edu.asu.conceptpower.root; - -import javax.annotation.PostConstruct; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.annotation.Qualifier; -import org.springframework.stereotype.Component; - -import com.db4o.ObjectContainer; -import com.db4o.ObjectSet; - -import edu.asu.conceptpower.core.ConceptType; - -@Component -public class TypeDatabaseClient { - - private ObjectContainer client; - - @Autowired - @Qualifier("typesDatabaseManager") - private DatabaseManager typeDatabase; - - @Autowired - private URIHelper uriHelper; - - @PostConstruct - public void init() { - this.client = typeDatabase.getClient(); - } - - public ConceptType getType(String uriOrId) { - String id = uriHelper.getTypeId(uriOrId); - ConceptType user = new ConceptType(id); - ObjectSet results = client.queryByExample(user); - - // there should only be exactly one object with this id - if (results.size() == 1) - return results.get(0); - - return null; - } - - public ConceptType findType(String name) { - ConceptType user = new ConceptType(); - user.setTypeName(name); - - ObjectSet results = client.queryByExample(user); - // there should only be exactly one object with this id - if (results.size() >= 1) - return results.get(0); - - return null; - } - - public ConceptType[] getAllTypes() { - ObjectSet results = client.query(ConceptType.class); - return results.toArray(new ConceptType[results.size()]); - } - - public ConceptType addType(ConceptType user) { - client.store(user); - client.commit(); - return user; - } - - public void deleteType(String id) { - ConceptType user = new ConceptType(); - user.setTypeId(id); - - ObjectSet results = client.queryByExample(user); - for (ConceptType res : results) { - client.delete(res); - client.commit(); - } - } - - public void update(ConceptType type) { - ConceptType toBeUpdated = getType(type.getTypeId()); - toBeUpdated.setCreatorId(type.getCreatorId()); - toBeUpdated.setDescription(type.getDescription()); - toBeUpdated.setMatches(type.getMatches()); - toBeUpdated.setModified(type.getModified()); - toBeUpdated.setSupertypeId(type.getSupertypeId()); - toBeUpdated.setTypeId(type.getTypeId()); - toBeUpdated.setTypeName(type.getTypeName()); - client.store(toBeUpdated); - client.commit(); - } - -} diff --git a/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/root/URIHelper.java b/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/root/URIHelper.java deleted file mode 100644 index dc7e12428..000000000 --- a/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/root/URIHelper.java +++ /dev/null @@ -1,44 +0,0 @@ -package edu.asu.conceptpower.root; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Service; - -import edu.asu.conceptpower.core.ConceptEntry; -import edu.asu.conceptpower.core.ConceptType; -import edu.asu.conceptpower.servlet.xml.XMLConstants; - -/** - * This class creates URIs for concepts and types based on the - * in xml-config.xml configured URI prefixes. - */ -@Service -public class URIHelper implements IURIHelper{ - - @Autowired - private XMLConfig xmlConfig; - - public String getURI(ConceptEntry entry) { - - String uriPrefix = xmlConfig.getUriPrefix(); - - if (entry.getId() != null && !entry.getId().isEmpty()) - return uriPrefix + entry.getId(); - - else - return uriPrefix + entry.getWordnetId(); - } - - public String getTypeURI(ConceptType type) { - - return XMLConstants.TYPE_NAMESPACE + XMLConstants.TYPE_PREFIX - + type.getTypeId(); - } - - public String getTypeId(String typeUriOrId) { - if (!typeUriOrId.startsWith(XMLConstants.TYPE_NAMESPACE + XMLConstants.TYPE_PREFIX)) { - return typeUriOrId; - } - - return typeUriOrId.substring((XMLConstants.TYPE_NAMESPACE + XMLConstants.TYPE_PREFIX).length()); - } -} diff --git a/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/core/ChangeEvent.java b/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/core/ChangeEvent.java new file mode 100644 index 000000000..b0d84aeda --- /dev/null +++ b/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/core/ChangeEvent.java @@ -0,0 +1,63 @@ +package edu.asu.conceptpower.servlet.core; + +import java.util.Date; + +public class ChangeEvent implements Comparable { + + public enum ChangeEventTypes { + MODIFICATION, CREATION, DELETION + } + + /** + * Stores the username of the creator or modified userName + */ + private String userName; + + /** + * Stores the time of change + */ + private Date date; + + /** + * Stores the type as Creation, Modification, Deletion + */ + private ChangeEventTypes type; + + public ChangeEvent() { + } + + public ChangeEvent(String userName, Date date, ChangeEventTypes type) { + this.userName = userName; + this.date = date; + this.type = type; + } + + public String getUserName() { + return userName; + } + + public void setUserName(String userName) { + this.userName = userName; + } + + public Date getDate() { + return date; + } + + public void setDate(Date date) { + this.date = date; + } + + @Override + public int compareTo(ChangeEvent changeEvent) { + return date.before(changeEvent.getDate()) ? 1 : 0; + } + + public ChangeEventTypes getType() { + return type; + } + + public void setType(ChangeEventTypes type) { + this.type = type; + } +} \ No newline at end of file diff --git a/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/core/Constants.java b/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/core/Constants.java deleted file mode 100644 index 22d5a15e3..000000000 --- a/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/core/Constants.java +++ /dev/null @@ -1,7 +0,0 @@ -package edu.asu.conceptpower.servlet.core; - -public interface Constants { - - public final static String SYNONYM_SEPARATOR = ","; - public final static String CONCEPT_SEPARATOR = ","; -} diff --git a/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/core/IConceptManager.java b/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/core/IConceptManager.java deleted file mode 100644 index a60894c83..000000000 --- a/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/core/IConceptManager.java +++ /dev/null @@ -1,121 +0,0 @@ -package edu.asu.conceptpower.servlet.core; - -import java.util.List; -import java.util.Map; - -import edu.asu.conceptpower.core.ConceptEntry; -import edu.asu.conceptpower.servlet.exceptions.DictionaryDoesNotExistException; -import edu.asu.conceptpower.servlet.exceptions.DictionaryEntryExistsException; -import edu.asu.conceptpower.servlet.exceptions.DictionaryModifyException; -import edu.asu.conceptpower.servlet.exceptions.IndexerRunningException; -import edu.asu.conceptpower.servlet.exceptions.LuceneException; - -public interface IConceptManager { - - /** - * Return entry given its ID. First the additional concepts are queried, - * then WordNet. - * - * @param id - * of entry - * @return Entry for ID or null. - */ - public abstract ConceptEntry getConceptEntry(String id)throws LuceneException; - - /** - * Get an entry from WordNet given its WordNet ID. - * - * @param wordnetId - * Id of concept in WordNet. - * @return concept for ID or null - */ - public abstract ConceptEntry getWordnetConceptEntry(String wordnetId)throws LuceneException; - - /** - * Get all entries for a word and its POS. - * - * @param word - * Word looked for. Additional concepts will be queried with - * "contains", WordNet concepts will be queried using - * "equals exactly". - * @param pos - * Part of speech of word (noun, verb, adjective, adverb). - * @return matching concepts - */ - public abstract ConceptEntry[] getConceptListEntriesForWord(String word, - String pos,String conceptType)throws LuceneException,IllegalAccessException, IndexerRunningException; - - /** - * Searches in all additional concepts for in the given fields for the given - * values. The results for each field/value pair are joined with "or". - * - * @param fieldMap - * map of field/value pairs - * @return matching concepts - */ - public abstract ConceptEntry[] searchForConceptsConnectedByOr( - Map fieldMap)throws LuceneException; - - /** - * Searches in all additional concepts for in the given fields for the given - * values. The results for each field/value pair are joined with "and". - * - * @param fieldMap - * map of field/value pairs - * @return matching concepts - */ - public abstract ConceptEntry[] searchForConceptsConnectedByAnd( - Map fieldMap)throws LuceneException; - - /** - * Given a concept id this method returns an array of concepts that are - * listed as synonyms for the concept with the given id. - * - * @param id - * The id of the concept that synonyms should be retrieved for. - * @return An array of concept entries that are synonyms for the concept - * with the given id. This method will never return null only filled - * or empty arrays. - */ - public abstract ConceptEntry[] getSynonymsForConcept(String id)throws LuceneException; - - /** - * This method returns an array of concept entries that have words that - * contain the given word. E.g. if the given word is "horse" this method - * would return concepts such as "horse" or "horseback riding". - * - * @param word - * The word that should be contained in the word field of a - * concept. - * @return An array list with matching concepts. This method never returns - * null only empty or filled arrays. - */ - public abstract ConceptEntry[] getConceptListEntriesForWord(String word)throws LuceneException,IllegalAccessException, IndexerRunningException; - - public abstract List getConceptListEntries(String conceptList)throws LuceneException; - - public abstract void addConceptListEntry(String word, String pos, - String description, String conceptListName, String typeId, - String equalTo, String similarTo, String synonymIds, - String synsetIds, String narrows, String broadens) - throws DictionaryDoesNotExistException, DictionaryModifyException, - DictionaryEntryExistsException; - - /** - * Stores the given entry in the database and return the new id - * that was generated for the entry. - * @param entry the {@link ConceptEntry} to be stored. - * @return Id of stored entry. - * @throws DictionaryDoesNotExistException If the entry has a concept list - * specified that doesn't exist. - * @throws DictionaryModifyException If the specified concept list in the - * concept is the Wordnet list. - */ - public abstract String addConceptListEntry(ConceptEntry entry) - throws DictionaryDoesNotExistException, DictionaryModifyException,LuceneException,IllegalAccessException, IndexerRunningException; - - public abstract void storeModifiedConcept(ConceptEntry entry)throws LuceneException,IllegalAccessException, IndexerRunningException; - - public abstract void deleteConcept(String id) throws LuceneException, IndexerRunningException; - -} \ No newline at end of file diff --git a/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/core/IConceptTypeManger.java b/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/core/IConceptTypeManger.java deleted file mode 100644 index d8c1c4120..000000000 --- a/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/core/IConceptTypeManger.java +++ /dev/null @@ -1,30 +0,0 @@ -package edu.asu.conceptpower.servlet.core; - -import edu.asu.conceptpower.core.ConceptType; - -/** - * This class is the manager class for concept types. It provides methods - * for adding, updating, deleting, and retrieving concepts. - * - * @author jdamerow - * - */ -public interface IConceptTypeManger { - - public void addConceptType(ConceptType type); - - public void storeModifiedConceptType(ConceptType type); - - public ConceptType[] getAllTypes(); - - /** - * This method retrieves a type by the provided type ID. Returns null if there - * is not such type. - * @param id ID of the type to be retrieved. - * @return The corresponding type or null if there is no type for th ID. - */ - public ConceptType getType(String id); - - public void deleteType(String id); - -} diff --git a/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/core/IIndexService.java b/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/core/IIndexService.java deleted file mode 100644 index 7e33ce0b4..000000000 --- a/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/core/IIndexService.java +++ /dev/null @@ -1,26 +0,0 @@ -package edu.asu.conceptpower.servlet.core; - -import java.util.Map; - -import edu.asu.conceptpower.core.ConceptEntry; -import edu.asu.conceptpower.core.IndexingEvent; -import edu.asu.conceptpower.servlet.exceptions.IndexerRunningException; -import edu.asu.conceptpower.servlet.exceptions.LuceneException; - -public interface IIndexService { - - public ConceptEntry[] searchForConcepts(Map fieldMap, String operator) - throws LuceneException, IllegalAccessException,IndexerRunningException; - - public void insertConcept(ConceptEntry entry) throws IllegalAccessException, LuceneException,IndexerRunningException; - - public void deleteById(String id) throws LuceneException, IndexerRunningException; - - public void deleteIndexes() throws LuceneException, IndexerRunningException; - - public void indexConcepts() throws LuceneException, IllegalArgumentException, IllegalAccessException, IndexerRunningException; - - public boolean isIndexerRunning(); - - public IndexingEvent getTotalNumberOfWordsIndexed(); -} diff --git a/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/core/POS.java b/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/core/POS.java deleted file mode 100644 index e436f0d75..000000000 --- a/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/core/POS.java +++ /dev/null @@ -1,16 +0,0 @@ -package edu.asu.conceptpower.servlet.core; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; - -public interface POS { - - public final static String NOUN = "noun"; - public final static String VERB = "verb"; - public final static String ADVERB = "adverb"; - public final static String ADJECTIVE = "adjective"; - public final static String OTHER = "other"; - - public final static List posValues = new ArrayList(Arrays.asList(new String[] {POS.NOUN, POS.VERB, POS.ADVERB, POS.ADJECTIVE, POS.OTHER})); -} diff --git a/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/core/impl/ConceptTypesManager.java b/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/core/impl/ConceptTypesManager.java deleted file mode 100644 index 7175089f7..000000000 --- a/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/core/impl/ConceptTypesManager.java +++ /dev/null @@ -1,69 +0,0 @@ -package edu.asu.conceptpower.servlet.core.impl; - -import java.util.UUID; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Service; - -import edu.asu.conceptpower.core.ConceptType; -import edu.asu.conceptpower.root.TypeDatabaseClient; -import edu.asu.conceptpower.servlet.core.IConceptTypeManger; - -@Service -public class ConceptTypesManager implements IConceptTypeManger { - - @Autowired - private TypeDatabaseClient client; - - /* (non-Javadoc) - * @see edu.asu.conceptpower.core.IConceptTypeManger#addConceptType(edu.asu.conceptpower.core.ConceptType) - */ - @Override - public void addConceptType(ConceptType type) { - - String id = null; - while (true) { - id = UUID.randomUUID().toString(); - ConceptType exist = client.getType(id); - if (exist == null) - break; - } - - type.setTypeId(id); - - client.addType(type); - } - - /* (non-Javadoc) - * @see edu.asu.conceptpower.core.IConceptTypeManger#storeModifiedConceptType(edu.asu.conceptpower.core.ConceptType) - */ - @Override - public void storeModifiedConceptType(ConceptType type) { - client.update(type); - } - - /* (non-Javadoc) - * @see edu.asu.conceptpower.core.IConceptTypeManger#getAllTypes() - */ - @Override - public ConceptType[] getAllTypes() { - return client.getAllTypes(); - } - - /* (non-Javadoc) - * @see edu.asu.conceptpower.core.IConceptTypeManger#getType(java.lang.String) - */ - @Override - public ConceptType getType(String id) { - return client.getType(id); - } - - /* (non-Javadoc) - * @see edu.asu.conceptpower.core.IConceptTypeManger#deleteType(java.lang.String) - */ - @Override - public void deleteType(String id){ - client.deleteType(id); - } - -} diff --git a/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/core/impl/IndexService.java b/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/core/impl/IndexService.java deleted file mode 100644 index b23aea54a..000000000 --- a/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/core/impl/IndexService.java +++ /dev/null @@ -1,123 +0,0 @@ -package edu.asu.conceptpower.servlet.core.impl; - -import java.util.Map; -import java.util.concurrent.atomic.AtomicBoolean; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.annotation.Qualifier; -import org.springframework.beans.factory.annotation.Value; -import org.springframework.stereotype.Service; - -import edu.asu.conceptpower.core.ConceptEntry; -import edu.asu.conceptpower.core.IndexingEvent; -import edu.asu.conceptpower.servlet.core.IIndexService; -import edu.asu.conceptpower.servlet.exceptions.IndexerRunningException; -import edu.asu.conceptpower.servlet.exceptions.LuceneException; -import edu.asu.conceptpower.servlet.lucene.ILuceneDAO; -import edu.asu.conceptpower.servlet.lucene.impl.LuceneUtility; - -/** - * This class acts as a single point of access to lucene. This class performs - * searching, insertion, deletion and indexing in lucene - * - * @author karthikeyanmohan - * - */ -@Service -public class IndexService implements IIndexService { - - @Autowired - private LuceneUtility luceneUtility; - - @Autowired - @Qualifier("luceneDAO") - private ILuceneDAO dao; - - @Value("#{messages['INDEXER_RUNNING']}") - private String indexerRunning; - - /** - * This field makes sure indexer runs only once when two different admins - * gives index command at same time - */ - private AtomicBoolean indexerRunningFlag = new AtomicBoolean(false); - - /** - * This method searches in lucene on a particular condition fed through - * fieldMap - */ - @Override - public ConceptEntry[] searchForConcepts(Map fieldMap, String operator) - throws LuceneException, IllegalAccessException, IndexerRunningException { - - if (indexerRunningFlag.get()) { - throw new IndexerRunningException(indexerRunning); - } - - return luceneUtility.queryIndex(fieldMap, operator); - } - - /** - * This method inserts concepts into lucene - * - * @throws IndexerRunningException - */ - @Override - public void insertConcept(ConceptEntry entry) - throws IllegalAccessException, LuceneException, IndexerRunningException { - if (indexerRunningFlag.get()) { - throw new IndexerRunningException(indexerRunning); - - } - luceneUtility.insertConcept(entry); - } - - /** - * This method deletes the concept in lucene index based on id of the - * concept - */ - @Override - public void deleteById(String id) throws LuceneException, IndexerRunningException { - if (indexerRunningFlag.get()) { - throw new IndexerRunningException(indexerRunning); - } - luceneUtility.deleteById(id); - - } - - /** - * This method deletes the index in lucene - */ - @Override - public void deleteIndexes() throws LuceneException, IndexerRunningException { - if (!indexerRunningFlag.compareAndSet(false, true)) { - throw new IndexerRunningException(indexerRunning); - } - luceneUtility.deleteIndexes(); - indexerRunningFlag.set(false); - } - - /** - * This method indexes concepts in lucene and runs indexer only once - */ - @Override - public void indexConcepts() - throws LuceneException, IllegalArgumentException, IllegalAccessException, IndexerRunningException { - if (!indexerRunningFlag.compareAndSet(false, true)) { - throw new IndexerRunningException(indexerRunning); - } - luceneUtility.indexConcepts(); - indexerRunningFlag.set(false); - } - - @Override - public boolean isIndexerRunning() { - return indexerRunningFlag.get(); - } - - @Override - public IndexingEvent getTotalNumberOfWordsIndexed() { - return dao.getTotalNumberOfWordsIndexed(); - } - -} diff --git a/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/lucene/ILuceneUtility.java b/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/lucene/ILuceneUtility.java deleted file mode 100644 index a006d2746..000000000 --- a/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/lucene/ILuceneUtility.java +++ /dev/null @@ -1,21 +0,0 @@ -package edu.asu.conceptpower.servlet.lucene; - -import java.util.Map; - -import edu.asu.conceptpower.core.ConceptEntry; -import edu.asu.conceptpower.servlet.exceptions.LuceneException; - -public interface ILuceneUtility { - - public void deleteById(String id) throws LuceneException; - - public void insertConcept(ConceptEntry entry) throws LuceneException, IllegalAccessException; - - public void deleteIndexes() throws LuceneException; - - public void indexConcepts() throws LuceneException, IllegalArgumentException, IllegalAccessException; - - public ConceptEntry[] queryIndex(Map fieldMap, String operator) - throws LuceneException, IllegalAccessException; - -} \ No newline at end of file diff --git a/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/rest/ConceptIDLookup.java b/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/rest/ConceptIDLookup.java deleted file mode 100644 index d0f2a6bb8..000000000 --- a/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/rest/ConceptIDLookup.java +++ /dev/null @@ -1,98 +0,0 @@ -package edu.asu.conceptpower.servlet.rest; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import javax.servlet.http.HttpServletRequest; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.http.HttpHeaders; -import org.springframework.http.HttpStatus; -import org.springframework.http.MediaType; -import org.springframework.http.ResponseEntity; -import org.springframework.stereotype.Controller; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestMethod; -import org.springframework.web.bind.annotation.ResponseBody; - -import edu.asu.conceptpower.core.ConceptEntry; -import edu.asu.conceptpower.core.ConceptType; -import edu.asu.conceptpower.root.TypeDatabaseClient; -import edu.asu.conceptpower.servlet.core.IConceptManager; -import edu.asu.conceptpower.servlet.exceptions.LuceneException; -import edu.asu.conceptpower.servlet.xml.XMLConceptMessage; -import edu.asu.conceptpower.servlet.xml.XMLMessageFactory; - -/** - * This class provides a method to query concepts by their id. - * It answers requests of the form: - * "http://[server.url]/conceptpower/rest/Concept?id={URI or ID of concept}" - * - * @author Chetan, Julia Damerow - * - */ -@Controller -public class ConceptIDLookup { - - @Autowired - private IConceptManager dictManager; - - @Autowired - private TypeDatabaseClient typeManager; - - @Autowired - private XMLMessageFactory messageFactory; - - /** - * This method provides concept information for the rest interface of the - * form - * "http://[server.url]/conceptpower/rest/Concept?id={URI or ID of concept}" - * - * @param req - * Holds the HTTP request information - * @return XML containing concept information - */ - @RequestMapping(value = "rest/Concept", method = RequestMethod.GET, produces = MediaType.APPLICATION_XML_VALUE + "; charset=utf-8") - public @ResponseBody ResponseEntity getConceptById(HttpServletRequest req) { - - String id = req.getParameter("id"); - if (id == null || id.trim().isEmpty()) { - return new ResponseEntity(HttpStatus.BAD_REQUEST); - } - - String[] pathParts = id.split("/"); - int lastIndex = pathParts.length - 1; - String wordnetId = null; - if (lastIndex > -1) - wordnetId = pathParts[lastIndex]; - - if (wordnetId == null) { - return new ResponseEntity(HttpStatus.BAD_REQUEST); - } - ConceptEntry entry = null; - try { - entry = dictManager.getConceptEntry(wordnetId); - } catch (LuceneException ex) { - return new ResponseEntity(ex.getMessage(), HttpStatus.BAD_REQUEST); - } - Map entryMap = new HashMap(); - List xmlEntries = new ArrayList(); - - XMLConceptMessage msg = messageFactory.createXMLConceptMessage(); - - if (entry != null) { - - ConceptType type = null; - - if (typeManager != null && entry.getTypeId() != null && !entry.getTypeId().trim().isEmpty()) { - type = typeManager.getType(entry.getTypeId()); - } - entryMap.put(entry, type); - xmlEntries = msg.appendEntries(entryMap); - } - - return new ResponseEntity(msg.getXML(xmlEntries), HttpStatus.OK); - } -} diff --git a/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/rest/ConceptLookup.java b/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/rest/ConceptLookup.java deleted file mode 100644 index 361b55751..000000000 --- a/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/rest/ConceptLookup.java +++ /dev/null @@ -1,90 +0,0 @@ -package edu.asu.conceptpower.servlet.rest; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.http.HttpHeaders; -import org.springframework.http.HttpStatus; -import org.springframework.http.MediaType; -import org.springframework.http.ResponseEntity; -import org.springframework.stereotype.Controller; -import org.springframework.web.bind.annotation.PathVariable; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestMethod; -import org.springframework.web.bind.annotation.ResponseBody; - -import edu.asu.conceptpower.core.ConceptEntry; -import edu.asu.conceptpower.core.ConceptType; -import edu.asu.conceptpower.root.TypeDatabaseClient; -import edu.asu.conceptpower.servlet.core.IConceptManager; -import edu.asu.conceptpower.servlet.exceptions.IndexerRunningException; -import edu.asu.conceptpower.servlet.exceptions.LuceneException; -import edu.asu.conceptpower.servlet.xml.XMLConceptMessage; -import edu.asu.conceptpower.servlet.xml.XMLMessageFactory; - -/** - * This class provides a method to retrieve all concepts - * for a given word and part of speech. It answers requests of the form: - * "http://[server.url]/conceptpower/rest/ConceptLookup/{word}/{pos}" - * - * @author Chetan, Julia Damerow - * - */ -@Controller -public class ConceptLookup { - - @Autowired - private IConceptManager dictManager; - - @Autowired - private TypeDatabaseClient typeManager; - - @Autowired - private XMLMessageFactory messageFactory; - - /** - * This method provides information of a concept for a rest interface of the - * form "http://[server.url]/conceptpower/rest/ConceptLookup/{word}/{pos}" - * - * @param word - * String value of concept to be looked - * @param pos - * String value of the POS of concept to be looked - * @return XML containing information of given concept for given POS - */ - @RequestMapping(value = "rest/ConceptLookup/{word}/{pos}", method = RequestMethod.GET, produces = "application/xml; charset=utf-8") - public @ResponseBody ResponseEntity getWordNetEntry(@PathVariable("word") String word, - @PathVariable("pos") String pos) { - ConceptEntry[] entries = null; - try { - entries = dictManager.getConceptListEntriesForWord(word, pos, null); - } catch (LuceneException ex) { - return new ResponseEntity(ex.getMessage(), HttpStatus.BAD_REQUEST); - } catch (IllegalAccessException e) { - return new ResponseEntity(e.getMessage(), HttpStatus.BAD_REQUEST); - } catch(IndexerRunningException ie){ - return new ResponseEntity(ie.getMessage(), HttpStatus.OK); - } - - Map entryMap = new HashMap(); - - for (ConceptEntry entry : entries) { - ConceptType type = null; - if (typeManager != null && entry.getTypeId() != null && !entry.getTypeId().trim().isEmpty()) { - type = typeManager.getType(entry.getTypeId()); - } - entryMap.put(entry, type); - } - - XMLConceptMessage returnMsg = messageFactory.createXMLConceptMessage(); - List xmlEntries = new ArrayList(); - if (entries != null) { - xmlEntries = returnMsg.appendEntries(entryMap); - } - - return new ResponseEntity(returnMsg.getXML(xmlEntries), HttpStatus.OK); - } -} diff --git a/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/rest/ConceptSearch.java b/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/rest/ConceptSearch.java deleted file mode 100644 index cfd3fa6dc..000000000 --- a/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/rest/ConceptSearch.java +++ /dev/null @@ -1,96 +0,0 @@ -package edu.asu.conceptpower.servlet.rest; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import javax.servlet.http.HttpServletRequest; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.http.HttpStatus; -import org.springframework.http.ResponseEntity; -import org.springframework.stereotype.Controller; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestMethod; -import org.springframework.web.bind.annotation.ResponseBody; - -import edu.asu.conceptpower.core.ConceptEntry; -import edu.asu.conceptpower.core.ConceptType; -import edu.asu.conceptpower.root.TypeDatabaseClient; -import edu.asu.conceptpower.root.URIHelper; -import edu.asu.conceptpower.servlet.core.IIndexService; -import edu.asu.conceptpower.servlet.exceptions.IndexerRunningException; -import edu.asu.conceptpower.servlet.exceptions.LuceneException; -import edu.asu.conceptpower.servlet.xml.XMLConceptMessage; -import edu.asu.conceptpower.servlet.xml.XMLMessageFactory; - -/** - * This class provides a method to search concepts. It answers requests to: - * "http://[server.url]/conceptpower/rest/ConceptSearch?{list of fieldname=value}{operator=and/or}" - * - * @author Chetan, Julia Damerow - * - */ -@Controller -public class ConceptSearch { - - @Autowired - private IIndexService manager; - - @Autowired - private TypeDatabaseClient typeManager; - - @Autowired - private XMLMessageFactory messageFactory; - - @Autowired - private URIHelper uriHelper; - - /** - * This method provides information of a concept for a rest interface of the - * form - * "http://[server.url]/conceptpower/rest/Type?id={URI or ID of concept}" - * - * @param req - * Holds HTTP request information - * @return - */ - @RequestMapping(value = "rest/ConceptSearch", method = RequestMethod.GET, produces = "application/xml; charset=utf-8") - public @ResponseBody ResponseEntity searchConcept(HttpServletRequest req) { - Map queryParams = req.getParameterMap(); - Map searchFields = new HashMap(); - String operator = SearchParamters.OP_OR; - for (String key : queryParams.keySet()) { - if (key.trim().equals(SearchParamters.OPERATOR) && !queryParams.get(key)[0].trim().isEmpty()) { - operator = queryParams.get(key)[0].trim(); - } else if (key.trim().equalsIgnoreCase(SearchFieldNames.TYPE_URI)) { - searchFields.put("type_id", uriHelper.getTypeId(queryParams.get(key)[0])); - } else { - searchFields.put(key.trim(), queryParams.get(key)[0]); - } - } - ConceptEntry[] searchResults = null; - - try { - searchResults = manager.searchForConcepts(searchFields, operator); - } catch (LuceneException | IllegalAccessException | IndexerRunningException ex) { - return new ResponseEntity(ex.getMessage(), HttpStatus.BAD_REQUEST); - } - - List xmlEntries = new ArrayList(); - Map entryMap = new HashMap(); - - XMLConceptMessage msg = messageFactory.createXMLConceptMessage(); - for (ConceptEntry entry : searchResults) { - ConceptType type = null; - if (typeManager != null && entry.getTypeId() != null && !entry.getTypeId().trim().isEmpty()) { - type = typeManager.getType(entry.getTypeId()); - } - entryMap.put(entry, type); - xmlEntries = msg.appendEntries(entryMap); - } - - return new ResponseEntity(msg.getXML(xmlEntries), HttpStatus.OK); - } -} diff --git a/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/rest/LuceneFieldNames.java b/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/rest/LuceneFieldNames.java deleted file mode 100644 index 7ba5509c1..000000000 --- a/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/rest/LuceneFieldNames.java +++ /dev/null @@ -1,18 +0,0 @@ -package edu.asu.conceptpower.servlet.rest; - -public interface LuceneFieldNames { - - public final static String EQUALS_TO = "equalTo"; - public final static String SIMILAR_TO = "similar"; - public final static String DESCRIPTION = "description"; - public final static String WORD = "word"; - public final static String POS = "pos"; - public final static String CONCEPT_LIST = "listName"; - public final static String TYPE_ID = "types"; - public final static String CREATOR = "creatorId"; - public final static String MODIFIED = "modifiedId"; - public final static String SYNONYMID = "synonymId"; - public final static String ID = "id"; - public final static String WORDNETID = "wordnetid"; - public final static String CONCEPTTYPE = "conceptType"; -} diff --git a/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/rest/SearchFieldNames.java b/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/rest/SearchFieldNames.java deleted file mode 100644 index 1bd2cdf85..000000000 --- a/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/rest/SearchFieldNames.java +++ /dev/null @@ -1,19 +0,0 @@ -package edu.asu.conceptpower.servlet.rest; - -public interface SearchFieldNames { - - public final static String EQUALS_TO = "equals_to"; - public final static String SIMILAR_TO = "similar_to"; - public final static String DESCRIPTION = "description"; - public final static String WORD = "word"; - public final static String POS = "pos"; - public final static String CONCEPT_LIST = "concept_list"; - public final static String TYPE_ID = "type_id"; - public final static String CREATOR = "creator"; - public final static String MODIFIED = "modified_by"; - public final static String WORDNETID = "wordnetid"; - public final static String ID = "id"; - public final static String ISCHECKED = "isChecked"; - public final static String TYPE_URI = "type_uri"; - public final static String SYNONYM_ID = "synonymId"; -} diff --git a/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/rest/SynonymSearch.java b/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/rest/SynonymSearch.java deleted file mode 100644 index 034c3c244..000000000 --- a/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/rest/SynonymSearch.java +++ /dev/null @@ -1,101 +0,0 @@ -package edu.asu.conceptpower.servlet.rest; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import javax.servlet.http.HttpServletRequest; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.http.HttpHeaders; -import org.springframework.http.HttpStatus; -import org.springframework.http.ResponseEntity; -import org.springframework.stereotype.Controller; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestMethod; -import org.springframework.web.bind.annotation.ResponseBody; - -import edu.asu.conceptpower.core.ConceptEntry; -import edu.asu.conceptpower.core.ConceptType; -import edu.asu.conceptpower.root.TypeDatabaseClient; -import edu.asu.conceptpower.servlet.core.IConceptManager; -import edu.asu.conceptpower.servlet.exceptions.LuceneException; -import edu.asu.conceptpower.servlet.xml.XMLConceptMessage; -import edu.asu.conceptpower.servlet.xml.XMLMessageFactory; - -/** - * This class provides a method to retrieve all synonyms for a given concept - * identified by its id. - * It answers requests to: - * "http://[server.url]/conceptpower/rest/SynonymSearch?id={URI or ID of concept you want synonyms for}" - * - * @author Julia Damero, Chetan - * - */ -@Controller -public class SynonymSearch { - - @Autowired - private IConceptManager dictManager; - - @Autowired - private TypeDatabaseClient typeManager; - - @Autowired - private XMLMessageFactory messageFactory; - - /** - * This method provides information of synonyms of a word for a rest - * interface of the form - * "http://[server.url]/conceptpower/rest/SynonymSearch?id={URI or ID of concept you want synonyms for}" - * - * @param req - * @return - */ - @RequestMapping(value = "rest/SynonymSearch", method = RequestMethod.GET, produces = "application/xml") - public @ResponseBody ResponseEntity getSynonymsForId(HttpServletRequest req) { - - // construct the URL to the Wordnet dictionary directory - String id = req.getParameter("id"); - if (id == null || id.trim().isEmpty()) { - return new ResponseEntity(HttpStatus.BAD_REQUEST); - } - - String[] pathParts = id.split("/"); - int lastIndex = pathParts.length - 1; - String wordnetId = null; - if (lastIndex > -1) - wordnetId = pathParts[lastIndex]; - - if (wordnetId == null) { - return new ResponseEntity(HttpStatus.BAD_REQUEST); - } - - - ConceptEntry[] synonyms = null; - try { - synonyms = dictManager.getSynonymsForConcept(wordnetId); - } catch (LuceneException ex) { - return new ResponseEntity(ex.getMessage(), HttpStatus.BAD_REQUEST); - } - List xmlEntries = new ArrayList(); - Map entryMap = new HashMap(); - - XMLConceptMessage msg = messageFactory.createXMLConceptMessage(); - for (ConceptEntry entry : synonyms) { - ConceptType type = null; - if (typeManager != null && entry.getTypeId() != null - && !entry.getTypeId().trim().isEmpty()) { - type = typeManager.getType(entry.getTypeId()); - } - entryMap.put(entry, type); - xmlEntries = msg.appendEntries(entryMap); - } - - HttpHeaders responseHeaders = new HttpHeaders(); - responseHeaders.add("Content-Type", "text/html; charset=utf-8"); - - return new ResponseEntity(msg.getXML(xmlEntries), responseHeaders, HttpStatus.OK); - } -} diff --git a/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/rest/TypeIdLookup.java b/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/rest/TypeIdLookup.java deleted file mode 100644 index b05af7b90..000000000 --- a/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/rest/TypeIdLookup.java +++ /dev/null @@ -1,92 +0,0 @@ -package edu.asu.conceptpower.servlet.rest; - -import java.util.List; - -import javax.servlet.http.HttpServletRequest; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.http.HttpHeaders; -import org.springframework.http.HttpStatus; -import org.springframework.http.ResponseEntity; -import org.springframework.stereotype.Controller; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestMethod; -import org.springframework.web.bind.annotation.ResponseBody; - -import edu.asu.conceptpower.core.ConceptType; -import edu.asu.conceptpower.root.TypeDatabaseClient; -import edu.asu.conceptpower.servlet.xml.XMLConstants; -import edu.asu.conceptpower.servlet.xml.XMLMessageFactory; -import edu.asu.conceptpower.servlet.xml.XMLTypeMessage; - -/** - * This class provides a method to query types by their ids. It - * answers requests to: - * "http://[server.url]/conceptpower/rest/Type?id={URI or ID of concept}" - * - * @author Julia Damerow, Chetan - * - */ -@Controller -public class TypeIdLookup { - - @Autowired - private TypeDatabaseClient typeManager; - - @Autowired - private XMLMessageFactory messageFactory; - - /** - * This method provides information of a type for a rest interface of the - * form - * "http://[server.url]/conceptpower/rest/Type?id={URI or ID of concept}" - * - * @param req - * Holds HTTP request information - * @return - */ - @RequestMapping(value = "rest/Type", method = RequestMethod.GET, produces = "application/xml") - public @ResponseBody ResponseEntity getTypeById(HttpServletRequest req) { - - String id = req.getParameter("id"); - if (id == null) { - return new ResponseEntity(HttpStatus.BAD_REQUEST); - } - // get type id if URI is given - - String[] pathParts = id.split("/"); - int lastIndex = pathParts.length - 1; - String typeId = null; - if (lastIndex > -1) - typeId = pathParts[lastIndex]; - - if (typeId == null) { - return new ResponseEntity(HttpStatus.BAD_REQUEST); - } - - if (typeId.startsWith(XMLConstants.TYPE_PREFIX)) { - typeId = typeId.substring(XMLConstants.TYPE_PREFIX.length()); - } - - ConceptType type = typeManager.getType(typeId); - - XMLTypeMessage msg = messageFactory.createXMLTypeMessage(); - List xmlEntry = null; - if (type != null) { - ConceptType superType = null; - if (type.getSupertypeId() != null - && !type.getSupertypeId().trim().isEmpty()) - superType = typeManager.getType(type.getSupertypeId().trim()); - xmlEntry = msg.appendEntry(type, superType); - } - else { - return new ResponseEntity(HttpStatus.NOT_FOUND); - } - - - HttpHeaders responseHeaders = new HttpHeaders(); - responseHeaders.add("Content-Type", "text/html; charset=utf-8"); - - return new ResponseEntity(msg.getXML(xmlEntry), responseHeaders, HttpStatus.OK); - } -} diff --git a/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/users/CPUserDetails.java b/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/users/CPUserDetails.java deleted file mode 100644 index 0b3cdac6d..000000000 --- a/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/users/CPUserDetails.java +++ /dev/null @@ -1,80 +0,0 @@ -package edu.asu.conceptpower.servlet.users; - -import java.util.Collection; -import java.util.List; - -import org.springframework.security.core.GrantedAuthority; -import org.springframework.security.core.userdetails.UserDetails; - -/** - * UserDetails implementation for Conceptpower. - * @author Julia Damerow - * - */ -class CPUserDetails implements UserDetails { - - /** - * - */ - private static final long serialVersionUID = -2936283695620688432L; - - private String username; - private String name; - private String password; - private List authorities; - private String email; - - public CPUserDetails(String username, String name, String password, - List authorities, String email) { - super(); - this.username = username; - this.name = name; - this.password = password; - this.authorities = authorities; - this.email = email; - } - - @Override - public Collection getAuthorities() { - return authorities; - } - - @Override - public String getPassword() { - return password; - } - - @Override - public String getUsername() { - return username; - } - - public String getName() { - return name; - } - - public String getEmail() { - return email; - } - - @Override - public boolean isAccountNonExpired() { - return true; - } - - @Override - public boolean isAccountNonLocked() { - return true; - } - - @Override - public boolean isCredentialsNonExpired() { - return true; - } - - @Override - public boolean isEnabled() { - return true; - } - -} \ No newline at end of file diff --git a/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/util/ExceptionHandler.java b/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/util/ExceptionHandler.java deleted file mode 100644 index 94d37a880..000000000 --- a/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/util/ExceptionHandler.java +++ /dev/null @@ -1,40 +0,0 @@ -package edu.asu.conceptpower.servlet.util; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.http.HttpStatus; -import org.springframework.http.ResponseEntity; -import org.springframework.security.access.AccessDeniedException; -import org.springframework.security.authentication.BadCredentialsException; -import org.springframework.web.bind.annotation.ControllerAdvice; - -/** - * This class handle exceptions thrown in the controllers. So far, there - * is only one exception page shown if something goes wrong. - * - * @author Julia Damerow - * - */ -@ControllerAdvice -public class ExceptionHandler { - - private static final Logger logger = LoggerFactory - .getLogger(ExceptionHandler.class); - - @org.springframework.web.bind.annotation.ExceptionHandler(value = BadCredentialsException.class) - public ResponseEntity handleAuthenticationFailure(BadCredentialsException ex) { - return new ResponseEntity(HttpStatus.UNAUTHORIZED); - } - - @org.springframework.web.bind.annotation.ExceptionHandler(value = AccessDeniedException.class) - public ResponseEntity handleAccessDenied(AccessDeniedException ex) { - return new ResponseEntity(HttpStatus.UNAUTHORIZED); - } - - @org.springframework.web.bind.annotation.ExceptionHandler(value = Exception.class) - public String handle(Exception e) { - logger.error("ExceptionHandler caught exception.", e); - return "exception"; - } - -} diff --git a/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/web/ConceptAddController.java b/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/web/ConceptAddController.java deleted file mode 100644 index 5a64d5240..000000000 --- a/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/web/ConceptAddController.java +++ /dev/null @@ -1,227 +0,0 @@ -package edu.asu.conceptpower.servlet.web; - -import java.io.IOException; -import java.security.Principal; -import java.util.Arrays; -import java.util.LinkedHashMap; -import java.util.List; -import java.util.Map; - -import javax.servlet.http.HttpServletRequest; - -import org.apache.commons.lang.ArrayUtils; -import org.codehaus.jackson.JsonGenerationException; -import org.codehaus.jackson.map.JsonMappingException; -import org.codehaus.jackson.map.ObjectMapper; -import org.codehaus.jackson.map.ObjectWriter; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.annotation.Value; -import org.springframework.http.HttpStatus; -import org.springframework.http.ResponseEntity; -import org.springframework.stereotype.Controller; -import org.springframework.ui.ModelMap; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestMethod; -import org.springframework.web.bind.annotation.RequestParam; -import org.springframework.web.bind.annotation.ResponseBody; - -import edu.asu.conceptpower.core.ConceptEntry; -import edu.asu.conceptpower.core.ConceptList; -import edu.asu.conceptpower.core.ConceptType; -import edu.asu.conceptpower.servlet.core.IConceptListManager; -import edu.asu.conceptpower.servlet.core.IConceptManager; -import edu.asu.conceptpower.servlet.core.IConceptTypeManger; -import edu.asu.conceptpower.servlet.core.IIndexService; -import edu.asu.conceptpower.servlet.exceptions.DictionaryDoesNotExistException; -import edu.asu.conceptpower.servlet.exceptions.DictionaryModifyException; -import edu.asu.conceptpower.servlet.exceptions.IndexerRunningException; -import edu.asu.conceptpower.servlet.exceptions.LuceneException; -import edu.asu.conceptpower.servlet.profile.impl.ServiceBackBean; -import edu.asu.conceptpower.servlet.profile.impl.ServiceRegistry; -import edu.asu.conceptpower.servlet.web.backing.SearchResultBackBeanForm; - -/** - * This class provides all the methods required for new concept creation - * - * @author Chetan - * - */ -@Controller -public class ConceptAddController { - - private static final Logger logger = LoggerFactory - .getLogger(ConceptAddController.class); - - @Autowired - private IConceptManager conceptManager; - - @Autowired - private IConceptListManager conceptListManager; - - @Autowired - private IConceptTypeManger conceptTypesManager; - - @Autowired - private ServiceRegistry serviceRegistry; - - @Autowired - private IIndexService indexService; - - @Value("#{messages['INDEXER_RUNNING']}") - private String indexerRunning; - - /** - * This method provides initial types and list model elements - * - * @param model - * A generic model holder for Servlet - * @return returns string which redirects to concept creation page - */ - @RequestMapping(value = "auth/conceptlist/addconcept") - public String prepareConceptAdd(ModelMap model) { - - model.addAttribute("ServiceBackBean", new ServiceBackBean()); - Map serviceNameIdMap = serviceRegistry - .getServiceNameIdMap(); - model.addAttribute("serviceNameIdMap", serviceNameIdMap); - model.addAttribute("SearchResultBackBeanForm", - new SearchResultBackBeanForm()); - - ConceptType[] allTypes = conceptTypesManager.getAllTypes(); - Map types = new LinkedHashMap(); - for (ConceptType conceptType : allTypes) { - types.put(conceptType.getTypeId(), conceptType.getTypeName()); - } - - model.addAttribute("types", types); - - List allLists = conceptListManager.getAllConceptLists(); - Map lists = new LinkedHashMap(); - for (ConceptList conceptList : allLists) { - lists.put(conceptList.getConceptListName(), - conceptList.getConceptListName()); - } - model.addAttribute("lists", lists); - - return "/auth/conceptlist/addconcept"; - } - - /** - * This method prepares a new concept and stores it using concept manager - * - * @param req - * Holds http request object information - * @param principal - * holds log in information - * @return returns string which redirects to concept list page - * @throws LuceneException - * @throws DictionaryModifyException - * @throws DictionaryDoesNotExistException - * @throws IllegalAccessException - * @throws IndexerRunningException - */ - @RequestMapping(value = "auth/conceptlist/addconcept/add", method = RequestMethod.POST) - public String addConcept(HttpServletRequest req, Principal principal, ModelMap model) throws LuceneException, DictionaryDoesNotExistException, DictionaryModifyException, IllegalAccessException, IndexerRunningException { - - ConceptEntry conceptEntry = new ConceptEntry(); - conceptEntry.setSynonymIds(req.getParameter("synonymsids")); - conceptEntry.setWord(req.getParameter("name")); - conceptEntry.setConceptList(req.getParameter("lists")); - conceptEntry.setPos(req.getParameter("pos")); - conceptEntry.setDescription(req.getParameter("description")); - conceptEntry.setEqualTo(req.getParameter("equals")); - conceptEntry.setSimilarTo(req.getParameter("similar")); - conceptEntry.setTypeId(req.getParameter("types")); - conceptEntry.setCreatorId(principal.getName()); - - //Checking if indexer is already running. - if(indexService.isIndexerRunning()){ - model.addAttribute("show_error_alert", true); - model.addAttribute("error_alert_msg", indexerRunning); - return "forward:/auth/conceptlist/addconcept"; - } - conceptManager.addConceptListEntry(conceptEntry); - return "redirect:/auth/" + req.getParameter("lists") + "/concepts"; - } - - /** - * This method provides array of concepts for a given string - * - * @param synonymname - * A synonym string for which we need to find existing concepts - * @return Returns array of concepts found for synonym name - * @throws IllegalAccessException - */ - @RequestMapping(method = RequestMethod.GET, value = "conceptAddSynonymView") - public @ResponseBody ResponseEntity getSynonyms(@RequestParam("synonymname") String synonymname, - @RequestParam("addedsynonym") String addedSynonnym) throws LuceneException, IllegalAccessException { - ConceptEntry[] entries = null; - try { - entries = conceptManager.getConceptListEntriesForWord(synonymname.trim()); - } catch (IndexerRunningException e1) { - return new ResponseEntity(e1.getMessage(), HttpStatus.CONFLICT); - } - List addedSynonymList = Arrays.asList(addedSynonnym.replaceAll("\\s", "").split(",")); - // Removing existing synonym from the entries. - int i = 0; - for (ConceptEntry concept : entries) { - if (addedSynonymList.contains(concept.getWordnetId())) { - entries = (ConceptEntry[]) ArrayUtils.remove(entries, i); - i--; - } - i++; - } - ObjectMapper mapper = new ObjectMapper(); - ObjectWriter writer = mapper.writer(); - try { - return new ResponseEntity(writer.writeValueAsString(entries), HttpStatus.OK); - } catch (JsonGenerationException e) { - logger.error("Couldn't parse results.", e); - return new ResponseEntity(HttpStatus.INTERNAL_SERVER_ERROR); - } catch (JsonMappingException e) { - logger.error("Couldn't parse results.", e); - return new ResponseEntity(HttpStatus.INTERNAL_SERVER_ERROR); - } catch (IOException e) { - logger.error("Couldn't parse results.", e); - return new ResponseEntity(HttpStatus.INTERNAL_SERVER_ERROR); - } - } - - /** - * This method provides array of existing concepts for a given string - * - * @param conceptname - * A string value for which we need to find existing concepts - * @return Returns existing concepts which contain conceptname - * @throws IllegalAccessException - */ - @RequestMapping(method = RequestMethod.GET, value = "getExistingConcepts") - public @ResponseBody ResponseEntity getExistingConcepts(@RequestParam("conceptname") String conceptname) - throws LuceneException, IllegalAccessException { - if (conceptname.isEmpty()) - return null; - ConceptEntry[] entries = null; - try { - entries = conceptManager.getConceptListEntriesForWord(conceptname.trim()); - } catch (IndexerRunningException e1) { - return new ResponseEntity(e1.getMessage(),HttpStatus.CONFLICT); - } - ObjectMapper mapper = new ObjectMapper(); - ObjectWriter writer = mapper.writer(); - try { - return new ResponseEntity(writer.writeValueAsString(entries), HttpStatus.OK); - } catch (JsonGenerationException e) { - logger.error("Couldn't parse results.", e); - return new ResponseEntity(HttpStatus.INTERNAL_SERVER_ERROR); - } catch (JsonMappingException e) { - logger.error("Couldn't parse results.", e); - return new ResponseEntity(HttpStatus.INTERNAL_SERVER_ERROR); - } catch (IOException e) { - logger.error("Couldn't parse results.", e); - return new ResponseEntity(HttpStatus.INTERNAL_SERVER_ERROR); - } - } - -} diff --git a/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/web/ConceptTypesController.java b/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/web/ConceptTypesController.java deleted file mode 100644 index ba22b096a..000000000 --- a/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/web/ConceptTypesController.java +++ /dev/null @@ -1,50 +0,0 @@ -package edu.asu.conceptpower.servlet.web; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Controller; -import org.springframework.ui.ModelMap; -import org.springframework.web.bind.annotation.RequestMapping; - -import edu.asu.conceptpower.core.ConceptType; -import edu.asu.conceptpower.servlet.core.IConceptTypeManger; - -/** - * This class provides methods for viewing concepts of a particular type - * - * @author Chetan - * - */ -@Controller -public class ConceptTypesController { - - @Autowired - private IConceptTypeManger conceptTypesManager; - - /** - * This method provides information about all the types for concept type - * view page - * - * @param model - * A generic model holder for Servlet - * @return String value to redirect user to concept type list page - */ - @RequestMapping(value = "auth/concepttype") - public String prepateShowConceptTypes(ModelMap model) { - - ConceptType[] types = conceptTypesManager.getAllTypes(); - - // to show super type name instead of type id in type list view - for (ConceptType type : types) { - if (type.getSupertypeId() != null - && !type.getSupertypeId().equals("")) { - ConceptType supertype = conceptTypesManager.getType(type - .getSupertypeId()); - if (supertype != null) - type.setSupertypeId(supertype.getTypeName()); - } - } - model.addAttribute("result", types); - - return "/auth/concepttype"; - } -} diff --git a/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/wrapper/ConceptEntryWrapper.java b/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/wrapper/ConceptEntryWrapper.java deleted file mode 100644 index 20704f9ae..000000000 --- a/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/wrapper/ConceptEntryWrapper.java +++ /dev/null @@ -1,89 +0,0 @@ -package edu.asu.conceptpower.servlet.wrapper; - -import java.io.Serializable; -import java.util.List; - -import edu.asu.conceptpower.core.ConceptEntry; -import edu.asu.conceptpower.core.ConceptType; -import edu.asu.conceptpower.users.User; - -/** - * This class describes the concept entry wrapper in concept power. It provides - * properties which are not available for the concept entries to be wrapped - * - * @author Julia Damerow - * - */ -public class ConceptEntryWrapper implements Serializable { - - private static final long serialVersionUID = -4261304897583134670L; - private ConceptEntry entry; - private List synonyms; - private ConceptType type; - private User creator; - private List wrappedWordnetEntries; - private String description; - private String uri; - - - public ConceptEntryWrapper(ConceptEntry entry) { - this.entry = entry; - } - - public ConceptEntry getEntry() { - return entry; - } - - public void setEntry(ConceptEntry entry) { - this.entry = entry; - } - - public List getSynonyms() { - return synonyms; - } - - public void setSynonyms(List synonyms) { - this.synonyms = synonyms; - } - - public ConceptType getType() { - return type; - } - - public void setType(ConceptType type) { - this.type = type; - } - - public User getCreator() { - return creator; - } - - public void setCreator(User creator) { - this.creator = creator; - } - - public void setWrappedWordnetEntries( - List wrappedWordnetEntries) { - this.wrappedWordnetEntries = wrappedWordnetEntries; - } - - public List getWrappedWordnetEntries() { - return wrappedWordnetEntries; - } - - public String getDescription() { - return description; - } - - public void setDescription(String description) { - this.description = description.replace("\n", "
"); - } - - public String getUri() { - return uri; - } - - public void setUri(String uri) { - this.uri = uri; - } -} diff --git a/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/xml/AXMLMessage.java b/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/xml/AXMLMessage.java deleted file mode 100644 index 94222ec49..000000000 --- a/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/xml/AXMLMessage.java +++ /dev/null @@ -1,23 +0,0 @@ -package edu.asu.conceptpower.servlet.xml; - -import java.util.List; - -public class AXMLMessage { - - public String getXML(List entries) { - StringBuffer sb = new StringBuffer(); - - sb.append("<" + XMLConstants.CONCEPTPOWER_ANSWER + " xmlns:" - + XMLConstants.NAMESPACE_PREFIX + "=\"" - + XMLConstants.NAMESPACE + "\">"); - - for (String entry : entries) { - sb.append(entry); - } - - sb.append(""); - - return sb.toString(); - } - -} \ No newline at end of file diff --git a/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/xml/NotImplementedException.java b/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/xml/NotImplementedException.java deleted file mode 100644 index 8a83eca05..000000000 --- a/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/xml/NotImplementedException.java +++ /dev/null @@ -1,10 +0,0 @@ -package edu.asu.conceptpower.servlet.xml; - -public class NotImplementedException extends Exception { - - /** - * - */ - private static final long serialVersionUID = 8773667213192837773L; - -} diff --git a/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/xml/XMLConceptMessage.java b/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/xml/XMLConceptMessage.java deleted file mode 100644 index 7c3cffa50..000000000 --- a/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/xml/XMLConceptMessage.java +++ /dev/null @@ -1,164 +0,0 @@ -package edu.asu.conceptpower.servlet.xml; - -import java.util.ArrayList; -import java.util.List; -import java.util.Map; - -import org.apache.commons.lang3.StringEscapeUtils; - -import edu.asu.conceptpower.core.ConceptEntry; -import edu.asu.conceptpower.core.ConceptList; -import edu.asu.conceptpower.core.ConceptType; -import edu.asu.conceptpower.root.URIHelper; - -/** - * This class is used to build XML messages that are sent - * back as responses to the client. The classes collections - * concepts and transforms them into XML. - * - * @author Julia Damerow - * - */ -public class XMLConceptMessage extends AXMLMessage { - - - private URIHelper uriCreator; - - public XMLConceptMessage(URIHelper uriCreator) { - this.uriCreator = uriCreator; - } - - public List appendEntries(Map entries) { - List xmlEntries = new ArrayList(); - for (ConceptEntry entry : entries.keySet()) - xmlEntries.add(getEntry(entry, entries.get(entry))); - - return xmlEntries; - } - - public String getEntry(ConceptEntry entry, ConceptType type) { - StringBuffer sb = new StringBuffer(); - - sb.append("<" + XMLConstants.NAMESPACE_PREFIX + ":" - + XMLConstants.CONCEPT_ENTRY + ">"); - - // id - sb.append("<" + XMLConstants.NAMESPACE_PREFIX + ":" + XMLConstants.ID - + " "); - sb.append(XMLConstants.CONCEPT_ID + "=\"" + entry.getId() + "\" "); - sb.append(XMLConstants.CONCEPT_URI + "=\"" + uriCreator.getURI(entry) - + "\""); - sb.append(">"); - sb.append(uriCreator.getURI(entry)); - sb.append(""); - - // lemma - sb.append("<" + XMLConstants.NAMESPACE_PREFIX + ":" - + XMLConstants.LEMMA + ">"); - sb.append(StringEscapeUtils.escapeXml10(entry.getWord())); - sb.append(""); - - // pos - sb.append("<" + XMLConstants.NAMESPACE_PREFIX + ":" + XMLConstants.POS - + ">"); - sb.append(entry.getPos()); - sb.append(""); - - // description - sb.append("<" + XMLConstants.NAMESPACE_PREFIX + ":" - + XMLConstants.DESCRIPTION + ">"); - sb.append(StringEscapeUtils.escapeXml10(entry.getDescription())); - sb.append(""); - - // concept list - sb.append("<" + XMLConstants.NAMESPACE_PREFIX + ":" - + XMLConstants.CONCEPT_LIST + ">"); - sb.append(StringEscapeUtils.escapeXml10(entry.getConceptList())); - sb.append(""); - - // creator id - sb.append("<" + XMLConstants.NAMESPACE_PREFIX + ":" - + XMLConstants.CREATOR_ID + ">"); - sb.append(StringEscapeUtils.escapeXml10(entry.getCreatorId() != null ? entry - .getCreatorId().trim() : "")); - sb.append(""); - - // equal to - sb.append("<" + XMLConstants.NAMESPACE_PREFIX + ":" - + XMLConstants.EQUAL_TO + ">"); - sb.append(StringEscapeUtils.escapeXml10(entry.getEqualTo() != null ? entry - .getEqualTo().trim() : "")); - sb.append(""); - - // modified by - sb.append("<" + XMLConstants.NAMESPACE_PREFIX + ":" - + XMLConstants.MODIFIED_BY + ">"); - sb.append(StringEscapeUtils.escapeXml10(entry.getModified() != null ? entry - .getModified().trim() : "")); - sb.append(""); - - // similar to - sb.append("<" + XMLConstants.NAMESPACE_PREFIX + ":" - + XMLConstants.SIMILAR_TO + ">"); - sb.append(StringEscapeUtils.escapeXml10(entry.getSimilarTo() != null ? entry - .getSimilarTo().trim() : "")); - sb.append(""); - - // synonym ids - sb.append("<" + XMLConstants.NAMESPACE_PREFIX + ":" - + XMLConstants.SYNONYM_IDS + ">"); - sb.append(StringEscapeUtils.escapeXml10(entry.getSynonymIds() != null ? entry - .getSynonymIds().trim() : "")); - sb.append(""); - - // type - sb.append("<" + XMLConstants.NAMESPACE_PREFIX + ":" + XMLConstants.TYPE - + " "); - if (type != null) { - sb.append(XMLConstants.TYPE_ID_ATTR + "=\"" + type.getTypeId() - + "\" "); - sb.append(XMLConstants.TYPE_URI_ATTR + "=\"" - + uriCreator.getTypeURI(type) + "\""); - } - sb.append(">"); - if (type != null) - sb.append(StringEscapeUtils.escapeXml10(type.getTypeName())); - sb.append(""); - - // is deleted - sb.append("<" + XMLConstants.NAMESPACE_PREFIX + ":" - + XMLConstants.IS_DELETED + ">"); - sb.append(entry.isDeleted() + ""); - sb.append(""); - - // wordnet id - sb.append("<" + XMLConstants.NAMESPACE_PREFIX + ":" - + XMLConstants.WORDNET_ID + ">"); - sb.append(StringEscapeUtils.escapeXml10(entry.getWordnetId() != null ? entry - .getWordnetId().trim() : "")); - sb.append(""); - - sb.append(""); - - return sb.toString(); - } - - public void appendDictionaries(List lists) - throws NotImplementedException { - throw new NotImplementedException(); - } -} diff --git a/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/xml/XMLConstants.java b/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/xml/XMLConstants.java deleted file mode 100644 index 464667379..000000000 --- a/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/xml/XMLConstants.java +++ /dev/null @@ -1,36 +0,0 @@ -package edu.asu.conceptpower.servlet.xml; - -public interface XMLConstants { - - public final static String NAMESPACE = "http://www.digitalhps.org/"; - public final static String NAMESPACE_PREFIX = "digitalHPS"; - public final static String ID_NAMESPACE = "http://www.digitalhps.org/concepts/"; - public final static String TYPE_NAMESPACE = "http://www.digitalhps.org/types/"; - public final static String TYPE_PREFIX = "TYPE_"; - - // nodes - public final static String CONCEPTPOWER_ANSWER = "conceptpowerReply"; - public final static String CONCEPT_ENTRY = "conceptEntry"; - public final static String TYPE_ENTRY = "type_entry"; - - public final static String ID = "id"; - public final static String CONCEPT_URI = "concept_uri"; - public final static String CONCEPT_ID = "concept_id"; - - public final static String POS = "pos"; - public final static String LEMMA = "lemma"; - public final static String DESCRIPTION = "description"; - public final static String CONCEPT_LIST = "conceptList"; - public final static String CREATOR_ID = "creator_id"; - public final static String EQUAL_TO = "equal_to"; - public final static String MODIFIED_BY = "modified_by"; - public final static String SIMILAR_TO = "similar_to"; - public final static String SYNONYM_IDS = "synonym_ids"; - public final static String IS_DELETED = "deleted"; - public final static String WORDNET_ID = "wordnet_id"; - public final static String TYPE = "type"; - public final static String SUPERTYPE = "supertype"; - public final static String TYPE_ID_ATTR = "type_id"; - public final static String TYPE_URI_ATTR = "type_uri"; - public final static String MATCHES = "matches"; -} diff --git a/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/xml/XMLMessageFactory.java b/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/xml/XMLMessageFactory.java deleted file mode 100644 index bde899ba3..000000000 --- a/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/xml/XMLMessageFactory.java +++ /dev/null @@ -1,21 +0,0 @@ -package edu.asu.conceptpower.servlet.xml; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Service; - -import edu.asu.conceptpower.root.URIHelper; - -@Service -public class XMLMessageFactory { - - @Autowired - private URIHelper uriCreator; - - public XMLConceptMessage createXMLConceptMessage() { - return new XMLConceptMessage(uriCreator); - } - - public XMLTypeMessage createXMLTypeMessage() { - return new XMLTypeMessage(uriCreator); - } -} diff --git a/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/xml/XMLTypeMessage.java b/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/xml/XMLTypeMessage.java deleted file mode 100644 index 134019a4c..000000000 --- a/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/xml/XMLTypeMessage.java +++ /dev/null @@ -1,105 +0,0 @@ -package edu.asu.conceptpower.servlet.xml; - -import java.util.ArrayList; -import java.util.List; - -import org.apache.commons.lang3.StringEscapeUtils; - -import edu.asu.conceptpower.core.ConceptType; -import edu.asu.conceptpower.root.URIHelper; - -/** - * This class is used to create XML responses for - * type queries. - * - * @author Julia Damerow - * - */ -public class XMLTypeMessage extends AXMLMessage { - - private URIHelper uriCreator; - - public XMLTypeMessage(URIHelper uriCreator) { - this.uriCreator = uriCreator; - } - - public List appendEntry(ConceptType type, ConceptType supertype) { - - List xmlEntries = new ArrayList(); - StringBuffer sb = new StringBuffer(); - - // start entry - sb.append("<" + XMLConstants.NAMESPACE_PREFIX + ":" - + XMLConstants.TYPE_ENTRY + ">"); - - // type uri, id - sb.append("<" + XMLConstants.NAMESPACE_PREFIX + ":" + XMLConstants.TYPE - + " "); - if (type != null) { - sb.append(XMLConstants.TYPE_ID_ATTR + "=\"" + type.getTypeId() - + "\" "); - sb.append(XMLConstants.TYPE_URI_ATTR + "=\"" - + uriCreator.getTypeURI(type) + "\""); - } - sb.append(">"); - if (type != null) - sb.append(StringEscapeUtils.escapeXml10(type.getTypeName())); - sb.append(""); - - // type description - sb.append("<" + XMLConstants.NAMESPACE_PREFIX + ":" - + XMLConstants.DESCRIPTION + ">"); - sb.append(StringEscapeUtils.escapeXml10(type.getDescription())); - sb.append(""); - - // creator id - sb.append("<" + XMLConstants.NAMESPACE_PREFIX + ":" - + XMLConstants.CREATOR_ID + ">"); - sb.append(StringEscapeUtils.escapeXml10(type.getCreatorId() != null ? type - .getCreatorId().trim() : "")); - sb.append(""); - - // matches - sb.append("<" + XMLConstants.NAMESPACE_PREFIX + ":" - + XMLConstants.MATCHES + ">"); - sb.append(StringEscapeUtils.escapeXml10(type.getMatches() != null ? type - .getMatches().trim() : "")); - sb.append(""); - - // modified by - sb.append("<" + XMLConstants.NAMESPACE_PREFIX + ":" - + XMLConstants.MODIFIED_BY + ">"); - sb.append(StringEscapeUtils.escapeXml10(type.getModified() != null ? type - .getModified().trim() : "")); - sb.append(""); - - // supertype - if (supertype != null) { - sb.append("<" + XMLConstants.NAMESPACE_PREFIX + ":" - + XMLConstants.SUPERTYPE + " "); - - sb.append(XMLConstants.TYPE_ID_ATTR + "=\"" + supertype.getTypeId() - + "\" "); - sb.append(XMLConstants.TYPE_URI_ATTR + "=\"" - + uriCreator.getTypeURI(supertype) + "\""); - - sb.append(">"); - sb.append(StringEscapeUtils.escapeXml10(supertype.getTypeName())); - sb.append(""); - } - - // end entry - sb.append(""); - - xmlEntries.add(sb.toString()); - - return xmlEntries; - } -} diff --git a/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/web/AddUserController.java b/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/web/AddUserController.java similarity index 92% rename from Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/web/AddUserController.java rename to Conceptpower+Spring/src/main/java/edu/asu/conceptpower/web/AddUserController.java index 6b9bea298..e51b133b9 100644 --- a/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/web/AddUserController.java +++ b/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/web/AddUserController.java @@ -1,4 +1,4 @@ -package edu.asu.conceptpower.servlet.web; +package edu.asu.conceptpower.web; import javax.servlet.http.HttpServletRequest; import org.springframework.beans.factory.annotation.Autowired; @@ -11,10 +11,10 @@ import org.springframework.web.bind.annotation.ModelAttribute; import org.springframework.web.bind.annotation.RequestMapping; -import edu.asu.conceptpower.servlet.users.IUserManager; -import edu.asu.conceptpower.servlet.validation.UserValidator; -import edu.asu.conceptpower.servlet.web.backing.UserBacking; +import edu.asu.conceptpower.app.users.IUserManager; +import edu.asu.conceptpower.app.validation.UserValidator; import edu.asu.conceptpower.users.User; +import edu.asu.conceptpower.web.backing.UserBacking; /** * This class provides methods for creating a user diff --git a/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/web/ConcepTypeDeleteController.java b/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/web/ConcepTypeDeleteController.java similarity index 73% rename from Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/web/ConcepTypeDeleteController.java rename to Conceptpower+Spring/src/main/java/edu/asu/conceptpower/web/ConcepTypeDeleteController.java index aff749633..11e2b437b 100644 --- a/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/web/ConcepTypeDeleteController.java +++ b/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/web/ConcepTypeDeleteController.java @@ -1,4 +1,4 @@ -package edu.asu.conceptpower.servlet.web; +package edu.asu.conceptpower.web; import java.util.List; @@ -9,14 +9,11 @@ import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; +import edu.asu.conceptpower.app.core.IConceptManager; +import edu.asu.conceptpower.app.core.IConceptTypeManger; +import edu.asu.conceptpower.app.exceptions.LuceneException; import edu.asu.conceptpower.core.ConceptEntry; -import edu.asu.conceptpower.core.ConceptList; import edu.asu.conceptpower.core.ConceptType; -import edu.asu.conceptpower.servlet.core.IConceptListManager; -import edu.asu.conceptpower.servlet.core.IConceptManager; -import edu.asu.conceptpower.servlet.core.IConceptTypeManger; -import edu.asu.conceptpower.servlet.exceptions.LuceneException; -import edu.asu.conceptpower.servlet.users.IUserManager; /** * This class provides methods for concept type deletion @@ -30,15 +27,9 @@ public class ConcepTypeDeleteController { @Autowired private IConceptTypeManger typeManager; - @Autowired - private IUserManager usersManager; - @Autowired private IConceptManager conceptManager; - @Autowired - private IConceptListManager conceptListManager; - /** * This method provides information of a type to be deleted to concept type * deletion page @@ -61,14 +52,9 @@ public String prepareDeleteType(@PathVariable("typeid") String typeid, ModelMap model.addAttribute("supertype", type.getSupertypeId()); // condition to check enable whether to delete the concepttype boolean enableDelete = true; - List conceptLists = conceptListManager.getAllConceptLists(); - for (ConceptList conceptList : conceptLists) { - List conceptEntries = conceptManager.getConceptListEntries(conceptList.getConceptListName()); - for (ConceptEntry conceptEntry : conceptEntries) { - if ((conceptEntry.getTypeId() != null) && (conceptEntry.getTypeId()).equals(typeid)) { - enableDelete = false; - } - } + List conceptEntries = conceptManager.getConceptEntryByTypeId(typeid); + if (conceptEntries.size() > 0) { + enableDelete = false; } model.addAttribute("enabledelete", enableDelete); diff --git a/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/web/ConceptAddController.java b/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/web/ConceptAddController.java new file mode 100644 index 000000000..6a1851154 --- /dev/null +++ b/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/web/ConceptAddController.java @@ -0,0 +1,251 @@ +package edu.asu.conceptpower.web; + +import java.io.IOException; +import java.security.Principal; +import java.util.Arrays; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; + +import javax.servlet.http.HttpServletRequest; + +import org.apache.commons.lang.ArrayUtils; +import org.codehaus.jackson.JsonGenerationException; +import org.codehaus.jackson.map.JsonMappingException; +import org.codehaus.jackson.map.ObjectMapper; +import org.codehaus.jackson.map.ObjectWriter; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.stereotype.Controller; +import org.springframework.ui.ModelMap; +import org.springframework.validation.BindingResult; +import org.springframework.validation.annotation.Validated; +import org.springframework.web.bind.WebDataBinder; +import org.springframework.web.bind.annotation.InitBinder; +import org.springframework.web.bind.annotation.ModelAttribute; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.ResponseBody; + +import edu.asu.conceptpower.app.core.IConceptListManager; +import edu.asu.conceptpower.app.core.IConceptManager; +import edu.asu.conceptpower.app.core.IConceptTypeManger; +import edu.asu.conceptpower.app.core.IIndexService; +import edu.asu.conceptpower.app.exceptions.DictionaryDoesNotExistException; +import edu.asu.conceptpower.app.exceptions.DictionaryModifyException; +import edu.asu.conceptpower.app.exceptions.IndexerRunningException; +import edu.asu.conceptpower.app.exceptions.LuceneException; +import edu.asu.conceptpower.app.profile.impl.ServiceRegistry; +import edu.asu.conceptpower.app.validation.ConceptAddValidator; +import edu.asu.conceptpower.core.ConceptEntry; +import edu.asu.conceptpower.core.ConceptList; +import edu.asu.conceptpower.core.ConceptType; +import edu.asu.conceptpower.web.backing.ConceptAddBean; + +/** + * This class provides all the methods required for new concept creation + * + * @author Chetan + * + */ +@Controller +public class ConceptAddController { + + private static final Logger logger = LoggerFactory.getLogger(ConceptAddController.class); + + @Autowired + private IConceptManager conceptManager; + + @Autowired + private IConceptListManager conceptListManager; + + @Autowired + private IConceptTypeManger conceptTypesManager; + + @Autowired + private ServiceRegistry serviceRegistry; + + @Autowired + private IIndexService indexService; + + @Value("#{messages['INDEXER_RUNNING']}") + private String indexerRunning; + + @Autowired + private ConceptAddValidator validator; + + @InitBinder + private void initBinder(WebDataBinder binder) { + binder.setValidator(validator); + } + + /** + * This method provides initial types and list model elements + * + * @param model + * A generic model holder for Servlet + * @return returns string which redirects to concept creation page + */ + @RequestMapping(value = "auth/conceptlist/addconcept") + public String prepareConceptAdd(ModelMap model, @ModelAttribute("conceptAddBean") ConceptAddBean conceptAddBean) { + + Map serviceNameIdMap = serviceRegistry.getServiceNameIdMap(); + conceptAddBean.setServiceNameIdMap(serviceNameIdMap); + ConceptType[] allTypes = conceptTypesManager.getAllTypes(); + Map types = new LinkedHashMap(); + for (ConceptType conceptType : allTypes) { + types.put(conceptType.getTypeId(), conceptType.getTypeName()); + } + + conceptAddBean.setTypes(types); + + List allLists = conceptListManager.getAllConceptLists(); + Map lists = new LinkedHashMap(); + for (ConceptList conceptList : allLists) { + lists.put(conceptList.getConceptListName(), conceptList.getConceptListName()); + } + conceptAddBean.setLists(lists); + + return "/auth/conceptlist/addconcept"; + } + + /** + * This method prepares a new concept and stores it using concept manager + * + * @param req + * Holds http request object information + * @param principal + * holds log in information + * @return returns string which redirects to concept list page + * @throws LuceneException + * @throws DictionaryModifyException + * @throws DictionaryDoesNotExistException + * @throws IllegalAccessException + * @throws IndexerRunningException + */ + @RequestMapping(value = "auth/conceptlist/addconcept/add", method = RequestMethod.POST) + public String addConcept(HttpServletRequest req, Principal principal, + @Validated @ModelAttribute("conceptAddBean") ConceptAddBean conceptAddBean, ModelMap model, + BindingResult result) throws LuceneException, DictionaryDoesNotExistException, DictionaryModifyException, + IllegalAccessException, IndexerRunningException { + if (result.hasErrors()) { + return "/auth/conceptlist/addconcept"; + } + ConceptEntry conceptEntry = new ConceptEntry(); + try { + conceptEntry.setSynonymIds(conceptAddBean.getSynonymsids()); + conceptEntry.setWord(conceptAddBean.getName()); + conceptEntry.setConceptList(conceptAddBean.getSelectedList()); + conceptEntry.setPos(conceptAddBean.getPos()); + conceptEntry.setDescription(conceptAddBean.getDescription()); + conceptEntry.setEqualTo(conceptAddBean.getEquals()); + conceptEntry.setSimilarTo(conceptAddBean.getSimilar()); + conceptEntry.setTypeId(conceptAddBean.getSelectedTypes()); + conceptEntry.setCreatorId(principal.getName()); + + // Checking if indexer is already running. + if ((indexService.isIndexerRunning())) { + model.addAttribute("show_error_alert", true); + model.addAttribute("error_alert_msg", indexerRunning); + return "forward:/auth/conceptlist/addconcept"; + } + conceptManager.addConceptListEntry(conceptEntry, principal.getName()); + + } catch (DictionaryDoesNotExistException e) { + logger.warn("Dictionary does not exists", e); + model.addAttribute("show_error_alert", true); + model.addAttribute("error_alert_msg", "Concept couldn't be added. Please try again."); + return "forward:/auth/conceptlist/addconcept"; + } catch (DictionaryModifyException dme) { + logger.warn("Dictionary modify exception", dme); + model.addAttribute("show_error_alert", true); + model.addAttribute("error_alert_msg", "Concept couldn't be added. Please try again."); + return "forward:/auth/conceptlist/addconcept"; + } + return "redirect:/auth/" + conceptAddBean.getSelectedList() + "/concepts"; + } + + /** + * This method provides array of concepts for a given string + * + * @param synonymname + * A synonym string for which we need to find existing concepts + * @return Returns array of concepts found for synonym name + * @throws IllegalAccessException + */ + @RequestMapping(method = RequestMethod.GET, value = "conceptAddSynonymView") + public @ResponseBody ResponseEntity getSynonyms(@RequestParam("synonymname") String synonymname, + @RequestParam("addedsynonym") String addedSynonnym) throws LuceneException, IllegalAccessException { + ConceptEntry[] entries = null; + try { + entries = conceptManager.getConceptListEntriesForWord(synonymname.trim()); + } catch (IndexerRunningException e1) { + return new ResponseEntity(e1.getMessage(), HttpStatus.SERVICE_UNAVAILABLE); + } + List addedSynonymList = Arrays.asList(addedSynonnym.replaceAll("\\s", "").split(",")); + // Removing existing synonym from the entries. + int i = 0; + for (ConceptEntry concept : entries) { + if (addedSynonymList.contains(concept.getWordnetId())) { + entries = (ConceptEntry[]) ArrayUtils.remove(entries, i); + i--; + } + i++; + } + ObjectMapper mapper = new ObjectMapper(); + ObjectWriter writer = mapper.writer(); + try { + return new ResponseEntity(writer.writeValueAsString(entries), HttpStatus.OK); + } catch (JsonGenerationException e) { + logger.error("Couldn't parse results.", e); + return new ResponseEntity(HttpStatus.INTERNAL_SERVER_ERROR); + } catch (JsonMappingException e) { + logger.error("Couldn't parse results.", e); + return new ResponseEntity(HttpStatus.INTERNAL_SERVER_ERROR); + } catch (IOException e) { + logger.error("Couldn't parse results.", e); + return new ResponseEntity(HttpStatus.INTERNAL_SERVER_ERROR); + } + } + + /** + * This method provides array of existing concepts for a given string + * + * @param conceptname + * A string value for which we need to find existing concepts + * @return Returns existing concepts which contain conceptname + * @throws IllegalAccessException + */ + @RequestMapping(method = RequestMethod.GET, value = "getExistingConcepts") + public @ResponseBody ResponseEntity getExistingConcepts(@RequestParam("conceptname") String conceptname) + throws LuceneException, IllegalAccessException { + if (conceptname.isEmpty()) + return null; + ConceptEntry[] entries = null; + try { + entries = conceptManager.getConceptListEntriesForWord(conceptname.trim()); + } catch (IndexerRunningException e1) { + return new ResponseEntity(e1.getMessage(), HttpStatus.SERVICE_UNAVAILABLE); + } + ObjectMapper mapper = new ObjectMapper(); + ObjectWriter writer = mapper.writer(); + try { + return new ResponseEntity(writer.writeValueAsString(entries), HttpStatus.OK); + } catch (JsonGenerationException e) { + logger.error("Couldn't parse results.", e); + return new ResponseEntity(HttpStatus.INTERNAL_SERVER_ERROR); + } catch (JsonMappingException e) { + logger.error("Couldn't parse results.", e); + return new ResponseEntity(HttpStatus.INTERNAL_SERVER_ERROR); + } catch (IOException e) { + logger.error("Couldn't parse results.", e); + return new ResponseEntity(HttpStatus.INTERNAL_SERVER_ERROR); + } + } + +} diff --git a/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/web/ConceptDeleteController.java b/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/web/ConceptDeleteController.java similarity index 60% rename from Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/web/ConceptDeleteController.java rename to Conceptpower+Spring/src/main/java/edu/asu/conceptpower/web/ConceptDeleteController.java index 09e4d95aa..91309edcd 100644 --- a/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/web/ConceptDeleteController.java +++ b/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/web/ConceptDeleteController.java @@ -1,26 +1,27 @@ -package edu.asu.conceptpower.servlet.web; +package edu.asu.conceptpower.web; +import java.security.Principal; import java.util.List; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Controller; import org.springframework.ui.ModelMap; -import org.springframework.validation.BindingResult; -import org.springframework.web.bind.annotation.ModelAttribute; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.servlet.ModelAndView; +import org.springframework.web.servlet.mvc.support.RedirectAttributes; +import edu.asu.conceptpower.app.core.IConceptManager; +import edu.asu.conceptpower.app.core.IIndexService; +import edu.asu.conceptpower.app.db4o.IConceptDBManager; +import edu.asu.conceptpower.app.exceptions.IndexerRunningException; +import edu.asu.conceptpower.app.exceptions.LuceneException; +import edu.asu.conceptpower.app.wrapper.ConceptEntryWrapper; +import edu.asu.conceptpower.app.wrapper.impl.ConceptEntryWrapperCreator; import edu.asu.conceptpower.core.ConceptEntry; -import edu.asu.conceptpower.servlet.core.IConceptManager; -import edu.asu.conceptpower.servlet.core.IIndexService; -import edu.asu.conceptpower.servlet.exceptions.IndexerRunningException; -import edu.asu.conceptpower.servlet.exceptions.LuceneException; -import edu.asu.conceptpower.servlet.wrapper.ConceptEntryWrapper; -import edu.asu.conceptpower.servlet.wrapper.impl.ConceptEntryWrapperCreator; /** * This class provides all the required methods for deleting a concept @@ -39,10 +40,10 @@ public class ConceptDeleteController { @Autowired private IIndexService indexService; - + @Value("#{messages['INDEXER_RUNNING']}") private String indexerRunning; - + /** * This method provides details of a concept to be deleted for concept * delete page @@ -52,11 +53,12 @@ public class ConceptDeleteController { * @param model * A generic model holder for Servlet * @return String value to redirect user to concept delete page + * @throws IndexerRunningException */ @RequestMapping(value = "auth/conceptlist/deleteconcept/{conceptid}", method = RequestMethod.GET) public String prepareDeleteConcept(@PathVariable("conceptid") String conceptid, ModelMap model, @RequestParam(value = "fromHomeScreenDelete", required = false) String fromHomeScreenDelete) - throws LuceneException { + throws LuceneException, IndexerRunningException { ConceptEntry concept = conceptManager.getConceptEntry(conceptid); model.addAttribute("word", concept.getWord()); model.addAttribute("description", concept.getDescription()); @@ -70,7 +72,6 @@ public String prepareDeleteConcept(@PathVariable("conceptid") String conceptid, model.addAttribute("user", concept.getModified()); model.addAttribute("modified", concept.getModified()); model.addAttribute("synonyms", concept.getSynonymIds()); - // conceptManager.deleteConcept(conceptid); if (fromHomeScreenDelete != null) { model.addAttribute("fromHomeScreenDelete", fromHomeScreenDelete); @@ -93,7 +94,8 @@ public String prepareDeleteConcept(@PathVariable("conceptid") String conceptid, @RequestMapping(value = "auth/concepts/canceldelete/{conceptList}", method = RequestMethod.GET) public String cancelDelete(@PathVariable("conceptList") String conceptList, ModelMap model) throws LuceneException { List foundConcepts = null; - List founds = conceptManager.getConceptListEntries(conceptList); + List founds = conceptManager.getConceptListEntries(conceptList, 1, -1, "id", + IConceptDBManager.DESCENDING); foundConcepts = wrapperCreator .createWrappers(founds != null ? founds.toArray(new ConceptEntry[founds.size()]) : new ConceptEntry[0]); @@ -109,55 +111,29 @@ public String cancelDelete(@PathVariable("conceptList") String conceptList, Mode * @param model * A generic model holder for Servlet * @return String value to redirect user to a particular concept list page - * @throws IndexerRunningException + * @throws IndexerRunningException */ - @RequestMapping(value = "auth/conceptlist/deleteconceptconfirm/{id}", method = RequestMethod.GET) - public ModelAndView confirmlDelete(@PathVariable("id") String id, - @RequestParam(value = "fromHomeScreenDelete") String fromHomeScreenDelete) - throws LuceneException, IndexerRunningException { - List foundConcepts = null; - ModelAndView model = new ModelAndView(); - ConceptEntry concept = conceptManager.getConceptEntry(id); - //Check if indexer is running - if (indexService.isIndexerRunning()) { - model.addObject("show_error_alert", true); - model.addObject("error_alert_msg", indexerRunning); - //Need to include command Object - model.setViewName("/auth/conceptlist/deleteconcept"); - return model; - } - - conceptManager.deleteConcept(id); - List founds = conceptManager.getConceptListEntries(concept.getConceptList()); - - foundConcepts = wrapperCreator - .createWrappers(founds != null ? founds.toArray(new ConceptEntry[founds.size()]) : new ConceptEntry[0]); - - model.addObject("result", foundConcepts); - if (fromHomeScreenDelete.equalsIgnoreCase("true")) { - model.setViewName("redirect:/login"); - return model; - } - model.setViewName("/auth/conceptlist/concepts"); - return model; - } - - @RequestMapping(value = "auth/conceptlist/deleteconcepts/{id}", method = RequestMethod.GET) - public ModelAndView deleteConcept(@PathVariable("id") String id, - @ModelAttribute("conceptSearchBean") ConceptSearchBean conceptSearchBean, BindingResult result) - throws LuceneException, IndexerRunningException { - ModelAndView model = new ModelAndView(); - // Check if indexer is running - if (indexService.isIndexerRunning()) { - model.addObject("show_error_alert", true); - model.addObject("error_alert_msg", indexerRunning); - // Need to include command Object - model.setViewName("welcome"); - return model; - } - conceptManager.deleteConcept(id); - model.setViewName("welome"); - return model; - } + @RequestMapping(value = "auth/conceptlist/deleteconceptconfirm/{id}", method = RequestMethod.POST) + public ModelAndView confirmDelete(@PathVariable("id") String id, + @RequestParam(value = "fromHomeScreenDelete") String fromHomeScreenDelete, + @RequestParam(value = "listName") String listName, Principal principal, + RedirectAttributes redirectAttributes) throws LuceneException, IndexerRunningException { + ModelAndView model = new ModelAndView(); + // Check if indexer is running + if (indexService.isIndexerRunning()) { + model.addObject("show_error_alert", true); + model.addObject("error_alert_msg", indexerRunning); + // Need to include command Object + model.setViewName("/auth/conceptlist/deleteconcept"); + return model; + } + conceptManager.deleteConcept(id, principal.getName()); + if (fromHomeScreenDelete.equalsIgnoreCase("true")) { + model.setViewName("redirect:/login"); + return model; + } + model.setViewName("redirect:/auth/" + listName + "/concepts"); + return model; + } } diff --git a/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/web/ConceptEditController.java b/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/web/ConceptEditController.java similarity index 84% rename from Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/web/ConceptEditController.java rename to Conceptpower+Spring/src/main/java/edu/asu/conceptpower/web/ConceptEditController.java index c91e1f1cd..eac29c94f 100644 --- a/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/web/ConceptEditController.java +++ b/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/web/ConceptEditController.java @@ -1,9 +1,10 @@ -package edu.asu.conceptpower.servlet.web; +package edu.asu.conceptpower.web; import java.security.Principal; import java.util.ArrayList; import java.util.Arrays; import java.util.List; +import java.util.concurrent.CopyOnWriteArrayList; import javax.servlet.http.HttpServletRequest; @@ -20,21 +21,23 @@ import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.ResponseBody; import org.springframework.web.servlet.ModelAndView; +import edu.asu.conceptpower.app.bean.ConceptEditBean; +import edu.asu.conceptpower.app.core.Constants; +import edu.asu.conceptpower.app.core.IConceptListManager; +import edu.asu.conceptpower.app.core.IConceptManager; +import edu.asu.conceptpower.app.core.IConceptTypeManger; +import edu.asu.conceptpower.app.core.IIndexService; +import edu.asu.conceptpower.app.exceptions.IndexerRunningException; +import edu.asu.conceptpower.app.exceptions.LuceneException; +import edu.asu.conceptpower.app.users.IUserManager; +import edu.asu.conceptpower.app.wrapper.ConceptEntryWrapper; +import edu.asu.conceptpower.app.wrapper.IConceptWrapperCreator; import edu.asu.conceptpower.core.ConceptEntry; import edu.asu.conceptpower.core.ConceptList; import edu.asu.conceptpower.core.ConceptType; -import edu.asu.conceptpower.servlet.bean.ConceptEditBean; -import edu.asu.conceptpower.servlet.core.Constants; -import edu.asu.conceptpower.servlet.core.IConceptListManager; -import edu.asu.conceptpower.servlet.core.IConceptManager; -import edu.asu.conceptpower.servlet.core.IConceptTypeManger; -import edu.asu.conceptpower.servlet.core.IIndexService; -import edu.asu.conceptpower.servlet.exceptions.IndexerRunningException; -import edu.asu.conceptpower.servlet.exceptions.LuceneException; -import edu.asu.conceptpower.servlet.users.IUserManager; -import edu.asu.conceptpower.servlet.wordnet.WordNetManager; /** * This method provides all the required methods for editing a concept @@ -52,13 +55,13 @@ public class ConceptEditController { private IConceptListManager conceptListManager; @Autowired - private IUserManager usersManager; + private IConceptWrapperCreator wrapperCreator; @Autowired - private IConceptTypeManger conceptTypesManager; + private IUserManager usersManager; @Autowired - private WordNetManager wordNetManger; + private IConceptTypeManger conceptTypesManager; @Autowired private IIndexService indexService; @@ -69,6 +72,8 @@ public class ConceptEditController { @Value("#{messages['INDEXERSTATUS']}") private String indexerStatus; + private static final int numberOfRecords = 20; + /** * This method provides information of a concept to be edited for concept * edit page @@ -106,6 +111,7 @@ public String prepareEditConcept(@PathVariable("conceptid") String conceptid, conceptEditBean.setSimilar(concept.getSimilarTo()); conceptEditBean.setConceptId(concept.getId()); conceptEditBean.setConceptEntryList(new ArrayList()); + conceptEditBean.setWordnetIds(concept.getWordnetId()); model.addAttribute("conceptId", concept.getId()); return "/auth/conceptlist/editconcept"; } @@ -147,6 +153,7 @@ public ModelAndView confirmEdit(@PathVariable("id") String id, HttpServletReques throws LuceneException, IllegalAccessException, IndexerRunningException { ConceptEntry conceptEntry = conceptManager.getConceptEntry(id); conceptEntry.setWord(conceptEditBean.getWord()); + conceptEntry.setWordnetId(conceptEditBean.getWordnetIds()); conceptEntry.setConceptList(conceptEditBean.getConceptListValue()); conceptEntry.setPos(conceptEditBean.getSelectedPosValue()); conceptEntry.setDescription(conceptEditBean.getDescription()); @@ -174,7 +181,7 @@ public ModelAndView confirmEdit(@PathVariable("id") String id, HttpServletReques return model; } - conceptManager.storeModifiedConcept(conceptEntry); + conceptManager.storeModifiedConcept(conceptEntry, principal.getName()); if (conceptEditBean.isFromHomeScreen()) { model.setViewName("redirect:/home/conceptsearch?word=" + conceptEditBean.getWord() + "&pos=" @@ -292,4 +299,34 @@ private String buildJSON(List synonyms, boolean posRequired, boole jsonStringBuilder.append("}"); return jsonStringBuilder.toString(); } + + @RequestMapping(method = RequestMethod.GET, value = "conceptEdit/search") + public @ResponseBody ResponseEntity searchConcept(@RequestParam("concept") String concept, + @RequestParam("pos") String pos) throws IllegalAccessException, LuceneException { + + List foundConcepts = null; + + if (!concept.trim().isEmpty()) { + + ConceptEntry[] found = null; + + if (indexService.isIndexerRunning()) { + return new ResponseEntity("Indexer is running. Please try again later.", + HttpStatus.SERVICE_UNAVAILABLE); + } + + try { + found = conceptManager.getConceptListEntriesForWordPOS(concept, pos, + Constants.WORDNET_DICTIONARY, -1, numberOfRecords); + } catch (IndexerRunningException ie) { + return new ResponseEntity("Indexer is running. Please try again later.", + HttpStatus.SERVICE_UNAVAILABLE); + } + + foundConcepts = new CopyOnWriteArrayList<>(wrapperCreator.createWrappers(found)); + } + + return new ResponseEntity(foundConcepts, HttpStatus.OK); + } + } diff --git a/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/web/ConceptListAddController.java b/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/web/ConceptListAddController.java similarity index 92% rename from Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/web/ConceptListAddController.java rename to Conceptpower+Spring/src/main/java/edu/asu/conceptpower/web/ConceptListAddController.java index 6522097bd..5258510c6 100644 --- a/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/web/ConceptListAddController.java +++ b/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/web/ConceptListAddController.java @@ -1,4 +1,4 @@ -package edu.asu.conceptpower.servlet.web; +package edu.asu.conceptpower.web; import javax.servlet.http.HttpServletRequest; @@ -12,8 +12,8 @@ import org.springframework.web.bind.annotation.ModelAttribute; import org.springframework.web.bind.annotation.RequestMapping; -import edu.asu.conceptpower.servlet.core.IConceptListManager; -import edu.asu.conceptpower.servlet.validation.ConceptListAddValidator; +import edu.asu.conceptpower.app.core.IConceptListManager; +import edu.asu.conceptpower.app.validation.ConceptListAddValidator; @Controller public class ConceptListAddController { diff --git a/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/web/ConceptListAddForm.java b/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/web/ConceptListAddForm.java similarity index 92% rename from Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/web/ConceptListAddForm.java rename to Conceptpower+Spring/src/main/java/edu/asu/conceptpower/web/ConceptListAddForm.java index 97774969d..b38f93d6d 100644 --- a/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/web/ConceptListAddForm.java +++ b/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/web/ConceptListAddForm.java @@ -1,4 +1,4 @@ -package edu.asu.conceptpower.servlet.web; +package edu.asu.conceptpower.web; public class ConceptListAddForm { diff --git a/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/web/ConceptListController.java b/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/web/ConceptListController.java similarity index 81% rename from Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/web/ConceptListController.java rename to Conceptpower+Spring/src/main/java/edu/asu/conceptpower/web/ConceptListController.java index 027a264f8..3676d648b 100644 --- a/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/web/ConceptListController.java +++ b/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/web/ConceptListController.java @@ -1,4 +1,4 @@ -package edu.asu.conceptpower.servlet.web; +package edu.asu.conceptpower.web; import java.util.HashMap; import java.util.List; @@ -17,16 +17,17 @@ import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.ResponseBody; +import edu.asu.conceptpower.app.core.IConceptListManager; +import edu.asu.conceptpower.app.core.IConceptManager; +import edu.asu.conceptpower.app.db.TypeDatabaseClient; +import edu.asu.conceptpower.app.db4o.IConceptDBManager; +import edu.asu.conceptpower.app.exceptions.LuceneException; +import edu.asu.conceptpower.app.util.URIHelper; +import edu.asu.conceptpower.app.wrapper.ConceptEntryWrapper; +import edu.asu.conceptpower.app.wrapper.IConceptWrapperCreator; import edu.asu.conceptpower.core.ConceptEntry; import edu.asu.conceptpower.core.ConceptList; import edu.asu.conceptpower.core.ConceptType; -import edu.asu.conceptpower.root.TypeDatabaseClient; -import edu.asu.conceptpower.root.URIHelper; -import edu.asu.conceptpower.servlet.core.IConceptListManager; -import edu.asu.conceptpower.servlet.core.IConceptManager; -import edu.asu.conceptpower.servlet.exceptions.LuceneException; -import edu.asu.conceptpower.servlet.wrapper.ConceptEntryWrapper; -import edu.asu.conceptpower.servlet.wrapper.IConceptWrapperCreator; @Controller public class ConceptListController { @@ -59,7 +60,6 @@ public String prepareShowConceptList(ModelMap model) { List conceptLists = conceptListManager.getAllConceptLists(); model.addAttribute("result", conceptLists); - return "/auth/conceptlist"; } @@ -73,17 +73,31 @@ public String prepareShowConceptList(ModelMap model) { * page */ @RequestMapping(value = "auth/{listid}/concepts", method = RequestMethod.GET) - public String getConceptsOfConceptList(@PathVariable("listid") String list, - ModelMap model) throws LuceneException { + public String getConceptsOfConceptList(@PathVariable("listid") String list, ModelMap model, + @RequestParam(defaultValue = "1") String page, + @RequestParam(defaultValue = IConceptDBManager.DESCENDING + "") String sortDir) throws LuceneException { - List founds = conceptManager.getConceptListEntries(list); + int pageInt = new Integer(page); + int sortDirInt = new Integer(sortDir); + int pageCount = conceptManager.getPageCount(list); + + List founds = conceptManager.getConceptListEntries(list, pageInt, -1, "id", sortDirInt); List foundConcepts = wrapperCreator .createWrappers(founds != null ? founds .toArray(new ConceptEntry[founds.size()]) : new ConceptEntry[0]); + if (pageInt < 1) { + pageInt = 1; + } + if (pageInt > pageCount) { + pageInt = pageCount; + } + model.addAttribute("page", pageInt); model.addAttribute("result", foundConcepts); + model.addAttribute("count", pageCount); + model.addAttribute("listid", list); return "/auth/conceptlist/concepts"; } diff --git a/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/web/ConceptListDeleteController.java b/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/web/ConceptListDeleteController.java similarity index 88% rename from Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/web/ConceptListDeleteController.java rename to Conceptpower+Spring/src/main/java/edu/asu/conceptpower/web/ConceptListDeleteController.java index 0118f0170..70f97a287 100644 --- a/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/web/ConceptListDeleteController.java +++ b/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/web/ConceptListDeleteController.java @@ -1,4 +1,4 @@ -package edu.asu.conceptpower.servlet.web; +package edu.asu.conceptpower.web; import java.util.List; @@ -9,12 +9,13 @@ import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; +import edu.asu.conceptpower.app.core.IConceptListManager; +import edu.asu.conceptpower.app.core.IConceptManager; +import edu.asu.conceptpower.app.db4o.IConceptDBManager; +import edu.asu.conceptpower.app.exceptions.LuceneException; +import edu.asu.conceptpower.app.users.IUserManager; import edu.asu.conceptpower.core.ConceptEntry; import edu.asu.conceptpower.core.ConceptList; -import edu.asu.conceptpower.servlet.core.IConceptListManager; -import edu.asu.conceptpower.servlet.core.IConceptManager; -import edu.asu.conceptpower.servlet.exceptions.LuceneException; -import edu.asu.conceptpower.servlet.users.IUserManager; @Controller public class ConceptListDeleteController { @@ -46,7 +47,7 @@ public String prepareDeleteConceptList(@PathVariable("name") String name, ModelM // condition to check enable whether to delete the conceptlist boolean enableDelete = true; List conceptEntries = null; - conceptEntries = conceptManager.getConceptListEntries(name); + conceptEntries = conceptManager.getConceptListEntries(name, 1, -1, "id", IConceptDBManager.DESCENDING); if (conceptEntries.size() > 0) enableDelete = false; diff --git a/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/web/ConceptListEditController.java b/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/web/ConceptListEditController.java similarity index 86% rename from Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/web/ConceptListEditController.java rename to Conceptpower+Spring/src/main/java/edu/asu/conceptpower/web/ConceptListEditController.java index 88714cd6c..e90773648 100644 --- a/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/web/ConceptListEditController.java +++ b/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/web/ConceptListEditController.java @@ -1,5 +1,6 @@ -package edu.asu.conceptpower.servlet.web; +package edu.asu.conceptpower.web; +import java.security.Principal; import java.util.Iterator; import java.util.List; @@ -18,14 +19,14 @@ import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; +import edu.asu.conceptpower.app.core.IConceptListManager; +import edu.asu.conceptpower.app.core.IConceptManager; +import edu.asu.conceptpower.app.core.IIndexService; +import edu.asu.conceptpower.app.exceptions.IndexerRunningException; +import edu.asu.conceptpower.app.exceptions.LuceneException; +import edu.asu.conceptpower.app.validation.ConceptListAddValidator; import edu.asu.conceptpower.core.ConceptEntry; import edu.asu.conceptpower.core.ConceptList; -import edu.asu.conceptpower.servlet.core.IConceptListManager; -import edu.asu.conceptpower.servlet.core.IConceptManager; -import edu.asu.conceptpower.servlet.core.IIndexService; -import edu.asu.conceptpower.servlet.exceptions.IndexerRunningException; -import edu.asu.conceptpower.servlet.exceptions.LuceneException; -import edu.asu.conceptpower.servlet.validation.ConceptListAddValidator; /** * This class provides all the methods required for editing a concept list @@ -93,7 +94,7 @@ public String prepareEditList(@PathVariable("listname") String listName, ModelMa @RequestMapping(value = "auth/conceptlist/storeeditlist", method = RequestMethod.POST) public String editList(HttpServletRequest req, @Validated @ModelAttribute("conceptListAddForm") ConceptListAddForm conceptListAddForm, - BindingResult result, ModelMap model) + BindingResult result, ModelMap model, Principal principal) throws LuceneException, IllegalAccessException, IndexerRunningException { if (result.hasErrors()) { return "/auth/conceptlist/editlist"; @@ -114,13 +115,14 @@ public String editList(HttpServletRequest req, // modify the name for all the existing concepts under this concept // list - List entries = conceptManager.getConceptListEntries(conceptListAddForm.getOldListName()); + List entries = conceptManager + .getConceptEntriedByConceptListName(conceptListAddForm.getOldListName()); Iterator entriesIterator = entries.iterator(); while (entriesIterator.hasNext()) { ConceptEntry conceptEntry = (ConceptEntry) entriesIterator.next(); conceptEntry.setConceptList(list.getConceptListName()); - conceptManager.storeModifiedConcept(conceptEntry); + conceptManager.storeModifiedConcept(conceptEntry, principal.getName()); model.addAttribute(indexerStatus, indexerRunning); } return "redirect:/auth/conceptlist"; diff --git a/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/web/ConceptMergeController.java b/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/web/ConceptMergeController.java new file mode 100644 index 000000000..1ff88ed20 --- /dev/null +++ b/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/web/ConceptMergeController.java @@ -0,0 +1,110 @@ +package edu.asu.conceptpower.web; + +import java.security.Principal; +import java.util.ArrayList; +import java.util.List; +import java.util.Set; +import java.util.stream.Collectors; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Controller; +import org.springframework.validation.BindingResult; +import org.springframework.validation.annotation.Validated; +import org.springframework.web.bind.WebDataBinder; +import org.springframework.web.bind.annotation.InitBinder; +import org.springframework.web.bind.annotation.ModelAttribute; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.servlet.ModelAndView; + +import edu.asu.conceptpower.app.bean.ConceptsMergeBean; +import edu.asu.conceptpower.app.core.IConceptListManager; +import edu.asu.conceptpower.app.core.IConceptManager; +import edu.asu.conceptpower.app.core.IConceptTypeManger; +import edu.asu.conceptpower.app.core.IConceptTypesService; +import edu.asu.conceptpower.app.core.IConceptTypesService.IdType; +import edu.asu.conceptpower.app.core.POS; +import edu.asu.conceptpower.app.exceptions.DictionaryDoesNotExistException; +import edu.asu.conceptpower.app.exceptions.DictionaryModifyException; +import edu.asu.conceptpower.app.exceptions.IndexerRunningException; +import edu.asu.conceptpower.app.exceptions.LuceneException; +import edu.asu.conceptpower.app.service.IConceptMergeService; +import edu.asu.conceptpower.core.ConceptEntry; +import edu.asu.conceptpower.core.ConceptList; + +@Controller +public class ConceptMergeController { + + @Autowired + private IConceptManager conceptManager; + + @Autowired + private IConceptMergeService conceptMergeService; + + @Autowired + private IConceptTypeManger conceptTypesManager; + + @Autowired + private IConceptListManager conceptListManager; + + @Autowired + private ConceptsMergeBeanValidator validator; + + @Autowired + private IConceptTypesService conceptTypesService; + + @InitBinder + private void initBinder(WebDataBinder binder) { + binder.setValidator(validator); + } + + @RequestMapping(value = "auth/concepts/merge", method = RequestMethod.GET) + public ModelAndView prepareMergeConcept(@ModelAttribute("conceptsMergeBean") ConceptsMergeBean conceptsMergeBean, + BindingResult result) { + List conceptEntries = new ArrayList<>(); + for (String id : conceptsMergeBean.getMergeIds()) { + conceptEntries.add(conceptManager.getConceptEntry(id)); + } + conceptsMergeBean = conceptMergeService.prepareMergeConcepts(conceptEntries, conceptsMergeBean); + + Set localConceptIds = conceptsMergeBean.getMergeIds().stream() + .filter(conceptId -> IdType.LOCAL_CONCEPT_ID == conceptTypesService + .getConceptTypeByConceptId(conceptId)) + .collect(Collectors.toSet()); + + ModelAndView mav = new ModelAndView(); + mav.addObject("localConceptIds", localConceptIds); + mav.addObject("types", conceptTypesManager.getAllTypes()); + mav.addObject("conceptEntries", conceptEntries); + mav.addObject("conceptListValues", conceptListManager.getAllConceptLists().stream() + .map(ConceptList::getConceptListName).collect(Collectors.toSet())); + mav.addObject("posValues", POS.posValues); + mav.setViewName("/auth/conceptMerge"); + return mav; + } + + @RequestMapping(value = "auth/concepts/merge", method = RequestMethod.POST) + public ModelAndView mergeConcept( + @ModelAttribute("conceptsMergeBean") @Validated ConceptsMergeBean conceptsMergeBean, BindingResult result, + Principal principal) throws IllegalAccessException, LuceneException, IndexerRunningException, + DictionaryDoesNotExistException, DictionaryModifyException { + ModelAndView mav = new ModelAndView(); + if (result.hasErrors()) { + // Adding all the default value. + Set localConceptIds = conceptsMergeBean.getMergeIds().stream().filter( + conceptId -> IdType.LOCAL_CONCEPT_ID == conceptTypesService.getConceptTypeByConceptId(conceptId)) + .collect(Collectors.toSet()); + mav.addObject("localConceptIds", localConceptIds); + mav.addObject("types", conceptTypesManager.getAllTypes()); + mav.addObject("conceptListValues", conceptListManager.getAllConceptLists().stream() + .map(ConceptList::getConceptListName).collect(Collectors.toSet())); + mav.addObject("posValues", POS.posValues); + mav.setViewName("/auth/conceptMerge"); + return mav; + } + conceptMergeService.mergeConcepts(conceptsMergeBean, principal.getName()); + mav.setViewName("redirect:/"); + return mav; + } + +} diff --git a/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/web/ConceptSearchBean.java b/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/web/ConceptSearchBean.java similarity index 89% rename from Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/web/ConceptSearchBean.java rename to Conceptpower+Spring/src/main/java/edu/asu/conceptpower/web/ConceptSearchBean.java index 4e7b0d11b..78f0397d0 100644 --- a/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/web/ConceptSearchBean.java +++ b/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/web/ConceptSearchBean.java @@ -1,4 +1,4 @@ -package edu.asu.conceptpower.servlet.web; +package edu.asu.conceptpower.web; import java.util.LinkedHashMap; import java.util.List; @@ -6,8 +6,8 @@ import org.springframework.stereotype.Component; -import edu.asu.conceptpower.servlet.core.POS; -import edu.asu.conceptpower.servlet.wrapper.ConceptEntryWrapper; +import edu.asu.conceptpower.app.core.POS; +import edu.asu.conceptpower.app.wrapper.ConceptEntryWrapper; @Component public class ConceptSearchBean { diff --git a/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/web/ConceptSearchController.java b/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/web/ConceptSearchController.java similarity index 84% rename from Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/web/ConceptSearchController.java rename to Conceptpower+Spring/src/main/java/edu/asu/conceptpower/web/ConceptSearchController.java index de626831a..e0ce128ae 100644 --- a/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/web/ConceptSearchController.java +++ b/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/web/ConceptSearchController.java @@ -1,4 +1,4 @@ -package edu.asu.conceptpower.servlet.web; +package edu.asu.conceptpower.web; import java.util.List; @@ -17,14 +17,14 @@ import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; +import edu.asu.conceptpower.app.core.IConceptManager; +import edu.asu.conceptpower.app.core.IIndexService; +import edu.asu.conceptpower.app.exceptions.IndexerRunningException; +import edu.asu.conceptpower.app.exceptions.LuceneException; +import edu.asu.conceptpower.app.validation.ConceptSearchValidator; +import edu.asu.conceptpower.app.wrapper.ConceptEntryWrapper; +import edu.asu.conceptpower.app.wrapper.IConceptWrapperCreator; import edu.asu.conceptpower.core.ConceptEntry; -import edu.asu.conceptpower.servlet.core.IConceptManager; -import edu.asu.conceptpower.servlet.core.IIndexService; -import edu.asu.conceptpower.servlet.exceptions.IndexerRunningException; -import edu.asu.conceptpower.servlet.exceptions.LuceneException; -import edu.asu.conceptpower.servlet.validation.ConceptSearchValidator; -import edu.asu.conceptpower.servlet.wrapper.ConceptEntryWrapper; -import edu.asu.conceptpower.servlet.wrapper.IConceptWrapperCreator; /** * This class provides concept search methods @@ -86,7 +86,7 @@ public String search(HttpServletRequest req, ModelMap model, } try { - found = conceptManager.getConceptListEntriesForWord(conceptSearchBean.getWord(), + found = conceptManager.getConceptListEntriesForWordPOS(conceptSearchBean.getWord(), conceptSearchBean.getPos().toString().toLowerCase().trim(), null); } catch (IndexerRunningException e) { model.addAttribute(indexerStatus, e.getMessage()); diff --git a/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/web/ConceptSearchJsonController.java b/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/web/ConceptSearchJsonController.java similarity index 90% rename from Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/web/ConceptSearchJsonController.java rename to Conceptpower+Spring/src/main/java/edu/asu/conceptpower/web/ConceptSearchJsonController.java index fc19d76ef..c99e70559 100644 --- a/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/web/ConceptSearchJsonController.java +++ b/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/web/ConceptSearchJsonController.java @@ -1,4 +1,4 @@ -package edu.asu.conceptpower.servlet.web; +package edu.asu.conceptpower.web; import java.util.ArrayList; import java.util.List; @@ -14,9 +14,9 @@ import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.ResponseBody; -import edu.asu.conceptpower.servlet.profile.ISearchResult; -import edu.asu.conceptpower.servlet.service.impl.AuthorityFileSearch; -import edu.asu.conceptpower.servlet.web.backing.SearchResultBackBean; +import edu.asu.conceptpower.app.profile.ISearchResult; +import edu.asu.conceptpower.app.service.impl.AuthorityFileSearch; +import edu.asu.conceptpower.web.backing.SearchResultBackBean; /** * This controller answer requests to other authority files diff --git a/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/web/ConceptTypeAddController.java b/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/web/ConceptTypeAddController.java similarity index 94% rename from Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/web/ConceptTypeAddController.java rename to Conceptpower+Spring/src/main/java/edu/asu/conceptpower/web/ConceptTypeAddController.java index 7583638a5..ac7fba8f8 100644 --- a/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/web/ConceptTypeAddController.java +++ b/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/web/ConceptTypeAddController.java @@ -1,4 +1,4 @@ -package edu.asu.conceptpower.servlet.web; +package edu.asu.conceptpower.web; import java.security.Principal; import java.util.LinkedHashMap; @@ -17,9 +17,9 @@ import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; +import edu.asu.conceptpower.app.core.IConceptTypeManger; +import edu.asu.conceptpower.app.validation.ConceptTypeAddValidator; import edu.asu.conceptpower.core.ConceptType; -import edu.asu.conceptpower.servlet.core.IConceptTypeManger; -import edu.asu.conceptpower.servlet.validation.ConceptTypeAddValidator; /** * This class provides required methods for concept type creation diff --git a/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/web/ConceptTypeAddForm.java b/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/web/ConceptTypeAddForm.java similarity index 97% rename from Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/web/ConceptTypeAddForm.java rename to Conceptpower+Spring/src/main/java/edu/asu/conceptpower/web/ConceptTypeAddForm.java index 4278fd229..2ede67520 100644 --- a/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/web/ConceptTypeAddForm.java +++ b/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/web/ConceptTypeAddForm.java @@ -1,4 +1,4 @@ -package edu.asu.conceptpower.servlet.web; +package edu.asu.conceptpower.web; import java.util.Map; diff --git a/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/web/ConceptTypeEditController.java b/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/web/ConceptTypeEditController.java similarity index 95% rename from Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/web/ConceptTypeEditController.java rename to Conceptpower+Spring/src/main/java/edu/asu/conceptpower/web/ConceptTypeEditController.java index 05fd6b982..92a5f47c1 100644 --- a/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/web/ConceptTypeEditController.java +++ b/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/web/ConceptTypeEditController.java @@ -1,4 +1,4 @@ -package edu.asu.conceptpower.servlet.web; +package edu.asu.conceptpower.web; import java.security.Principal; import java.util.Date; @@ -19,10 +19,10 @@ import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; +import edu.asu.conceptpower.app.core.IConceptTypeManger; +import edu.asu.conceptpower.app.users.IUserManager; +import edu.asu.conceptpower.app.validation.ConceptTypeAddValidator; import edu.asu.conceptpower.core.ConceptType; -import edu.asu.conceptpower.servlet.core.IConceptTypeManger; -import edu.asu.conceptpower.servlet.users.IUserManager; -import edu.asu.conceptpower.servlet.validation.ConceptTypeAddValidator; /** * This class provides all the methods for editing a type diff --git a/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/web/ConceptTypesController.java b/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/web/ConceptTypesController.java new file mode 100644 index 000000000..fc1fa1af6 --- /dev/null +++ b/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/web/ConceptTypesController.java @@ -0,0 +1,74 @@ +package edu.asu.conceptpower.web; + +import java.util.List; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Controller; +import org.springframework.ui.ModelMap; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; + +import edu.asu.conceptpower.app.core.IConceptTypeManger; +import edu.asu.conceptpower.app.db4o.IConceptDBManager; +import edu.asu.conceptpower.core.ConceptType; + +/** + * This class provides methods for viewing concepts of a particular type + * + * @author Chetan + * + */ +@Controller +public class ConceptTypesController { + + @Autowired + private IConceptTypeManger conceptTypesManager; + + /** + * This method provides information about all the types for concept type + * view page + * + * @param model + * A generic model holder for Servlet + * @return String value to redirect user to concept type list page + * @throws SecurityException + * @throws NoSuchFieldException + */ + @RequestMapping(value = "auth/concepttype") + public String prepareShowConceptTypes(ModelMap model, @RequestParam(defaultValue = "1") String page, + @RequestParam(defaultValue = IConceptDBManager.ASCENDING + "") String sortDir, + @RequestParam(defaultValue = "typeName") String sortColumn) throws NoSuchFieldException, SecurityException { + + ConceptType[] types = conceptTypesManager.getAllTypes(); + + int pageInt = new Integer(page); + int sortDirInt = new Integer(sortDir); + + List conceptTypes = conceptTypesManager.getConceptTypes(pageInt, -1, sortColumn, sortDirInt); + + // to show super type name instead of type id in type list view + for (ConceptType type : types) { + if (type.getSupertypeId() != null && !type.getSupertypeId().equals("")) { + ConceptType supertype = conceptTypesManager.getType(type.getSupertypeId()); + if (supertype != null) + type.setSupertypeId(supertype.getTypeName()); + } + } + + if (pageInt < 1) { + pageInt = 1; + } + + int pageCount = conceptTypesManager.getPageCount(); + if (pageInt > pageCount) { + pageInt = pageCount; + } + + model.addAttribute("page", pageInt); + model.addAttribute("result", conceptTypes); + model.addAttribute("count", pageCount); + model.addAttribute("sortDir", sortDir); + model.addAttribute("sortColumn", sortColumn); + return "/auth/concepttype"; + } +} diff --git a/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/web/ConceptWrapperAddController.java b/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/web/ConceptWrapperAddController.java similarity index 89% rename from Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/web/ConceptWrapperAddController.java rename to Conceptpower+Spring/src/main/java/edu/asu/conceptpower/web/ConceptWrapperAddController.java index cb5d9db3e..f2ceab755 100644 --- a/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/web/ConceptWrapperAddController.java +++ b/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/web/ConceptWrapperAddController.java @@ -1,4 +1,4 @@ -package edu.asu.conceptpower.servlet.web; +package edu.asu.conceptpower.web; import java.security.Principal; import java.util.Arrays; @@ -9,6 +9,8 @@ import javax.servlet.http.HttpServletRequest; import org.apache.commons.lang.StringEscapeUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.http.HttpStatus; @@ -20,20 +22,20 @@ import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RequestParam; +import edu.asu.conceptpower.app.core.IConceptListManager; +import edu.asu.conceptpower.app.core.IConceptManager; +import edu.asu.conceptpower.app.core.IConceptTypeManger; +import edu.asu.conceptpower.app.core.IIndexService; +import edu.asu.conceptpower.app.exceptions.DictionaryDoesNotExistException; +import edu.asu.conceptpower.app.exceptions.DictionaryModifyException; +import edu.asu.conceptpower.app.exceptions.IndexerRunningException; +import edu.asu.conceptpower.app.exceptions.LuceneException; +import edu.asu.conceptpower.app.wordnet.Constants; +import edu.asu.conceptpower.app.wrapper.ConceptEntryWrapper; +import edu.asu.conceptpower.app.wrapper.IConceptWrapperCreator; import edu.asu.conceptpower.core.ConceptEntry; import edu.asu.conceptpower.core.ConceptList; import edu.asu.conceptpower.core.ConceptType; -import edu.asu.conceptpower.servlet.core.IConceptListManager; -import edu.asu.conceptpower.servlet.core.IConceptManager; -import edu.asu.conceptpower.servlet.core.IConceptTypeManger; -import edu.asu.conceptpower.servlet.core.IIndexService; -import edu.asu.conceptpower.servlet.exceptions.DictionaryDoesNotExistException; -import edu.asu.conceptpower.servlet.exceptions.DictionaryModifyException; -import edu.asu.conceptpower.servlet.exceptions.IndexerRunningException; -import edu.asu.conceptpower.servlet.exceptions.LuceneException; -import edu.asu.conceptpower.servlet.wordnet.Constants; -import edu.asu.conceptpower.servlet.wrapper.ConceptEntryWrapper; -import edu.asu.conceptpower.servlet.wrapper.IConceptWrapperCreator; /** * This class provides methods required for creating concept wrappers @@ -62,6 +64,8 @@ public class ConceptWrapperAddController { @Value("#{messages['INDEXER_RUNNING']}") private String indexerRunning; + private static final Logger logger = LoggerFactory.getLogger(ConceptWrapperAddController.class); + /** * This method provides required information for concept wrapper creation * @@ -135,7 +139,7 @@ public String addConcept(HttpServletRequest req, Principal principal, Model mode // Need to include command Object return "forward:/auth/conceptlist/addconceptwrapper"; } - conceptManager.addConceptListEntry(conceptEntry); + conceptManager.addConceptListEntry(conceptEntry, principal.getName()); } return "redirect:/auth/" + req.getParameter("lists") + "/concepts"; @@ -168,7 +172,8 @@ public String search(HttpServletRequest req, ModelMap model) throws LuceneExcept } try { - found = conceptManager.getConceptListEntriesForWord(concept, pos, Constants.WORDNET_DICTIONARY); + found = conceptManager.getConceptListEntriesForWordPOS(concept, pos, + Constants.WORDNET_DICTIONARY); } catch (IndexerRunningException ie) { model.addAttribute(indexerRunning, ie.getMessage()); return "/login"; @@ -209,8 +214,10 @@ public ResponseEntity getSynonyms(@RequestParam("synonymname") String sy try { entries = conceptManager.getConceptListEntriesForWord(synonymname.trim()); } catch (LuceneException ex) { - return new ResponseEntity(ex.getMessage(), HttpStatus.BAD_REQUEST); + logger.error("Lucene exception", ex); + return new ResponseEntity(ex.getMessage(), HttpStatus.INTERNAL_SERVER_ERROR); } catch (IndexerRunningException ex) { + logger.info("Indexer running exception", ex); return new ResponseEntity(ex.getMessage(), HttpStatus.OK); } return new ResponseEntity(buildJSON(Arrays.asList(entries)), HttpStatus.OK); diff --git a/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/web/ConceptsMergeBeanValidator.java b/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/web/ConceptsMergeBeanValidator.java new file mode 100644 index 000000000..78ca3ff3b --- /dev/null +++ b/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/web/ConceptsMergeBeanValidator.java @@ -0,0 +1,34 @@ +package edu.asu.conceptpower.web; + +import org.springframework.stereotype.Component; +import org.springframework.validation.Errors; +import org.springframework.validation.ValidationUtils; +import org.springframework.validation.Validator; + +import edu.asu.conceptpower.app.bean.ConceptsMergeBean; + +@Component +public class ConceptsMergeBeanValidator implements Validator { + + @Override + public boolean supports(Class clazz) { + return ConceptsMergeBean.class.isAssignableFrom(clazz); + } + + @Override + public void validate(Object target, Errors errors) { + ValidationUtils.rejectIfEmptyOrWhitespace(errors, "word", "word", "Word cannot be empty."); + ValidationUtils.rejectIfEmptyOrWhitespace(errors, "selectedPosValue", "selectedPosValue", + "POS cannot be empty."); + ValidationUtils.rejectIfEmptyOrWhitespace(errors, "selectedListName", "selectedListName", + "Concept List cannot be empty."); + ValidationUtils.rejectIfEmptyOrWhitespace(errors, "selectedTypeId", "selectedTypeId", + "Concept Type cannot be empty."); + + ConceptsMergeBean conceptMergeBean = (ConceptsMergeBean) target; + if (conceptMergeBean.getMergeIds() == null || conceptMergeBean.getMergeIds().size() < 2) { + errors.reject("mergeIds", "Merged Id should contain atleast two ids."); + } + } + +} diff --git a/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/web/DownloadFilesUtility.java b/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/web/DownloadFilesUtility.java index 630dd9369..4938341e4 100644 --- a/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/web/DownloadFilesUtility.java +++ b/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/web/DownloadFilesUtility.java @@ -136,5 +136,4 @@ public String getToLocation() { public void setToLocation(String toLocation) { this.toLocation = toLocation; } - -} \ No newline at end of file +} diff --git a/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/web/ForgottenPasswordController.java b/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/web/ForgottenPasswordController.java similarity index 93% rename from Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/web/ForgottenPasswordController.java rename to Conceptpower+Spring/src/main/java/edu/asu/conceptpower/web/ForgottenPasswordController.java index c03f9a0fc..6954ef38f 100644 --- a/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/web/ForgottenPasswordController.java +++ b/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/web/ForgottenPasswordController.java @@ -1,4 +1,4 @@ -package edu.asu.conceptpower.servlet.web; +package edu.asu.conceptpower.web; import javax.servlet.http.HttpServletRequest; import javax.validation.Valid; @@ -13,12 +13,12 @@ import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; -import edu.asu.conceptpower.servlet.service.IEmailService; -import edu.asu.conceptpower.servlet.users.IUserManager; -import edu.asu.conceptpower.servlet.users.Token; -import edu.asu.conceptpower.servlet.web.backing.EmailBackBean; -import edu.asu.conceptpower.servlet.web.backing.UserBacking; +import edu.asu.conceptpower.app.service.IEmailService; +import edu.asu.conceptpower.app.users.IUserManager; +import edu.asu.conceptpower.app.users.Token; import edu.asu.conceptpower.users.User; +import edu.asu.conceptpower.web.backing.EmailBackBean; +import edu.asu.conceptpower.web.backing.UserBacking; /** * diff --git a/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/web/HomeController.java b/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/web/HomeController.java similarity index 95% rename from Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/web/HomeController.java rename to Conceptpower+Spring/src/main/java/edu/asu/conceptpower/web/HomeController.java index 2ace7d8c5..999e3fd61 100644 --- a/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/web/HomeController.java +++ b/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/web/HomeController.java @@ -1,4 +1,4 @@ -package edu.asu.conceptpower.servlet.web; +package edu.asu.conceptpower.web; import java.util.Locale; diff --git a/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/web/LoginController.java b/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/web/LoginController.java similarity index 97% rename from Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/web/LoginController.java rename to Conceptpower+Spring/src/main/java/edu/asu/conceptpower/web/LoginController.java index 6f6b8a120..c754b6aac 100644 --- a/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/web/LoginController.java +++ b/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/web/LoginController.java @@ -1,4 +1,4 @@ -package edu.asu.conceptpower.servlet.web; +package edu.asu.conceptpower.web; import org.springframework.stereotype.Controller; import org.springframework.ui.ModelMap; diff --git a/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/web/LuceneIndexController.java b/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/web/LuceneIndexController.java similarity index 66% rename from Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/web/LuceneIndexController.java rename to Conceptpower+Spring/src/main/java/edu/asu/conceptpower/web/LuceneIndexController.java index 25abbffb0..216f7dc89 100644 --- a/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/web/LuceneIndexController.java +++ b/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/web/LuceneIndexController.java @@ -1,4 +1,4 @@ -package edu.asu.conceptpower.servlet.web; +package edu.asu.conceptpower.web; import java.security.Principal; @@ -6,16 +6,18 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; import org.springframework.stereotype.Controller; import org.springframework.ui.ModelMap; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.ResponseBody; +import edu.asu.conceptpower.app.core.IIndexService; +import edu.asu.conceptpower.app.exceptions.IndexerRunningException; +import edu.asu.conceptpower.app.exceptions.LuceneException; import edu.asu.conceptpower.core.IndexingEvent; -import edu.asu.conceptpower.servlet.core.IIndexService; -import edu.asu.conceptpower.servlet.exceptions.IndexerRunningException; -import edu.asu.conceptpower.servlet.exceptions.LuceneException; /** * This class provides methods for deleting and viewing lucene indexes @@ -56,24 +58,37 @@ public String onLoadLucene(ModelMap model) { * @throws IndexerRunningException */ @RequestMapping(value = "auth/indexConcepts", method = RequestMethod.POST, produces = "application/json") - public @ResponseBody IndexingEvent indexConcepts(HttpServletRequest req, Principal principal, ModelMap model) + public @ResponseBody ResponseEntity indexConcepts(HttpServletRequest req, Principal principal, + ModelMap model) throws IndexerRunningException { - IndexingEvent bean = null; + IndexingEvent bean = new IndexingEvent(); try { if (manager.isIndexerRunning()) { - bean = manager.getTotalNumberOfWordsIndexed(); bean.setMessage(indexerRunning); - return bean; + return new ResponseEntity(bean, HttpStatus.SERVICE_UNAVAILABLE); } - manager.deleteIndexes(); - manager.indexConcepts(); - bean = manager.getTotalNumberOfWordsIndexed(); - bean.setMessage("Indexed successfully"); - return bean; + + manager.deleteIndexes(principal.getName()); + manager.indexConcepts(principal.getName()); + bean.setMessage("Indexer Running"); + return new ResponseEntity(bean, HttpStatus.OK); } catch (LuceneException | IllegalArgumentException | IllegalAccessException ex) { bean.setMessage(ex.getMessage()); - return bean; + return new ResponseEntity(bean, HttpStatus.INTERNAL_SERVER_ERROR); + } + } + + @RequestMapping(value = "auth/getIndexerStatus", method = RequestMethod.POST, produces = "application/json") + public @ResponseBody ResponseEntity getIndexerStatus() throws IndexerRunningException { + + IndexingEvent bean = new IndexingEvent(); + if (!manager.isIndexerRunning()) { + bean = manager.getTotalNumberOfWordsIndexed(); + bean.setMessage("Indexed successfully"); + return new ResponseEntity(bean, HttpStatus.OK); } + bean.setMessage("Indexer Running"); + return new ResponseEntity(bean, HttpStatus.ACCEPTED); } /** @@ -95,7 +110,7 @@ public String onLoadLucene(ModelMap model) { bean.setMessage(indexerRunning); return bean; } - manager.deleteIndexes(); + manager.deleteIndexes(principal.getName()); bean = manager.getTotalNumberOfWordsIndexed(); bean.setMessage("Concepts deleted from index successfully"); return bean; @@ -104,4 +119,4 @@ public String onLoadLucene(ModelMap model) { return bean; } } -} +} \ No newline at end of file diff --git a/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/web/PasswordEditController.java b/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/web/PasswordEditController.java similarity index 94% rename from Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/web/PasswordEditController.java rename to Conceptpower+Spring/src/main/java/edu/asu/conceptpower/web/PasswordEditController.java index e3055041a..3b9017848 100644 --- a/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/web/PasswordEditController.java +++ b/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/web/PasswordEditController.java @@ -1,4 +1,4 @@ -package edu.asu.conceptpower.servlet.web; +package edu.asu.conceptpower.web; import java.security.Principal; import javax.servlet.http.HttpServletRequest; @@ -11,9 +11,9 @@ import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; -import edu.asu.conceptpower.servlet.users.IUserManager; -import edu.asu.conceptpower.servlet.web.backing.UserBacking; +import edu.asu.conceptpower.app.users.IUserManager; import edu.asu.conceptpower.users.User; +import edu.asu.conceptpower.web.backing.UserBacking; @Controller public class PasswordEditController { diff --git a/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/web/UserDeleteController.java b/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/web/UserDeleteController.java similarity index 93% rename from Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/web/UserDeleteController.java rename to Conceptpower+Spring/src/main/java/edu/asu/conceptpower/web/UserDeleteController.java index 957300ae3..01a124ce5 100644 --- a/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/web/UserDeleteController.java +++ b/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/web/UserDeleteController.java @@ -1,4 +1,4 @@ -package edu.asu.conceptpower.servlet.web; +package edu.asu.conceptpower.web; import java.security.Principal; import org.springframework.beans.factory.annotation.Autowired; @@ -8,9 +8,9 @@ import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; -import edu.asu.conceptpower.servlet.users.IUserManager; -import edu.asu.conceptpower.servlet.web.backing.UserBacking; +import edu.asu.conceptpower.app.users.IUserManager; import edu.asu.conceptpower.users.User; +import edu.asu.conceptpower.web.backing.UserBacking; @Controller public class UserDeleteController { diff --git a/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/web/UserEditController.java b/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/web/UserEditController.java similarity index 94% rename from Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/web/UserEditController.java rename to Conceptpower+Spring/src/main/java/edu/asu/conceptpower/web/UserEditController.java index c677eb320..377b650de 100644 --- a/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/web/UserEditController.java +++ b/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/web/UserEditController.java @@ -1,4 +1,4 @@ -package edu.asu.conceptpower.servlet.web; +package edu.asu.conceptpower.web; import java.security.Principal; import org.springframework.beans.factory.annotation.Autowired; @@ -13,10 +13,10 @@ import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; -import edu.asu.conceptpower.servlet.users.IUserManager; -import edu.asu.conceptpower.servlet.validation.EmailValidator; -import edu.asu.conceptpower.servlet.web.backing.UserBacking; +import edu.asu.conceptpower.app.users.IUserManager; +import edu.asu.conceptpower.app.validation.EmailValidator; import edu.asu.conceptpower.users.User; +import edu.asu.conceptpower.web.backing.UserBacking; /** * This class provides required methods for editing a user diff --git a/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/web/UserEncryptPasswordController.java b/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/web/UserEncryptPasswordController.java similarity index 94% rename from Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/web/UserEncryptPasswordController.java rename to Conceptpower+Spring/src/main/java/edu/asu/conceptpower/web/UserEncryptPasswordController.java index f13379f2f..cc971f8b2 100644 --- a/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/web/UserEncryptPasswordController.java +++ b/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/web/UserEncryptPasswordController.java @@ -1,4 +1,4 @@ -package edu.asu.conceptpower.servlet.web; +package edu.asu.conceptpower.web; import java.security.Principal; @@ -10,7 +10,7 @@ import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RequestParam; -import edu.asu.conceptpower.servlet.users.IUserManager; +import edu.asu.conceptpower.app.users.IUserManager; import edu.asu.conceptpower.users.User; @Controller diff --git a/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/web/UserListController.java b/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/web/UserListController.java similarity index 89% rename from Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/web/UserListController.java rename to Conceptpower+Spring/src/main/java/edu/asu/conceptpower/web/UserListController.java index 80e1bbf95..686362e32 100644 --- a/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/web/UserListController.java +++ b/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/web/UserListController.java @@ -1,11 +1,11 @@ -package edu.asu.conceptpower.servlet.web; +package edu.asu.conceptpower.web; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.ui.ModelMap; import org.springframework.web.bind.annotation.RequestMapping; -import edu.asu.conceptpower.servlet.users.IUserManager; +import edu.asu.conceptpower.app.users.IUserManager; import edu.asu.conceptpower.users.User; /** diff --git a/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/web/backing/ConceptAddBean.java b/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/web/backing/ConceptAddBean.java new file mode 100644 index 000000000..d7b898a2d --- /dev/null +++ b/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/web/backing/ConceptAddBean.java @@ -0,0 +1,147 @@ +package edu.asu.conceptpower.web.backing; + +import java.util.HashMap; +import java.util.Map; + +import org.springframework.stereotype.Component; + +@Component("conceptAddBean") +public class ConceptAddBean { + + private String name; + private String pos; + private Map lists = new HashMap(); + private String selectedList; + private String description; + private Map types = new HashMap(); + private String selectedTypes; + private String equals; + private String similar; + private String synonymsids; + private Map serviceNameIdMap = new HashMap(); + private String selectedServiceNameIdMap; + private String term; + private String synonymDescription; + private String synonymId; + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getPos() { + return pos; + } + + public void setPos(String pos) { + this.pos = pos; + } + + public Map getLists() { + return lists; + } + + public void setLists(Map lists) { + this.lists = lists; + } + + public String getSelectedList() { + return selectedList; + } + + public void setSelectedList(String selectedList) { + this.selectedList = selectedList; + } + + public String getDescription() { + return description; + } + + public void setDescription(String description) { + this.description = description; + } + + public String getSelectedTypes() { + return selectedTypes; + } + + public void setSelectedTypes(String selectedTypes) { + this.selectedTypes = selectedTypes; + } + + public String getEquals() { + return equals; + } + + public void setEquals(String equals) { + this.equals = equals; + } + + public String getSimilar() { + return similar; + } + + public void setSimilar(String similar) { + this.similar = similar; + } + + public String getSynonymsids() { + return synonymsids; + } + + public void setSynonymsids(String synonymsids) { + this.synonymsids = synonymsids; + } + + public Map getTypes() { + return types; + } + + public void setTypes(Map types) { + this.types = types; + } + + public Map getServiceNameIdMap() { + return serviceNameIdMap; + } + + public void setServiceNameIdMap(Map serviceNameIdMap) { + this.serviceNameIdMap = serviceNameIdMap; + } + + public String getSelectedServiceNameIdMap() { + return selectedServiceNameIdMap; + } + + public void setSelectedServiceNameIdMap(String selectedServiceNameIdMap) { + this.selectedServiceNameIdMap = selectedServiceNameIdMap; + } + + public String getTerm() { + return term; + } + + public void setTerm(String term) { + this.term = term; + } + + public String getSynonymDescription() { + return synonymDescription; + } + + public void setSynonymDescription(String synonymDescription) { + this.synonymDescription = synonymDescription; + } + + public String getSynonymId() { + return synonymId; + } + + public void setSynonymId(String synonymId) { + this.synonymId = synonymId; + } + +} diff --git a/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/web/backing/EmailBackBean.java b/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/web/backing/EmailBackBean.java similarity index 89% rename from Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/web/backing/EmailBackBean.java rename to Conceptpower+Spring/src/main/java/edu/asu/conceptpower/web/backing/EmailBackBean.java index 75f92eab5..106f75bff 100644 --- a/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/web/backing/EmailBackBean.java +++ b/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/web/backing/EmailBackBean.java @@ -1,4 +1,4 @@ -package edu.asu.conceptpower.servlet.web.backing; +package edu.asu.conceptpower.web.backing; import org.hibernate.validator.constraints.NotEmpty; diff --git a/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/web/backing/SearchResultBackBean.java b/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/web/backing/SearchResultBackBean.java similarity index 96% rename from Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/web/backing/SearchResultBackBean.java rename to Conceptpower+Spring/src/main/java/edu/asu/conceptpower/web/backing/SearchResultBackBean.java index 916eb195b..9d0f76ba6 100644 --- a/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/web/backing/SearchResultBackBean.java +++ b/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/web/backing/SearchResultBackBean.java @@ -1,4 +1,4 @@ -package edu.asu.conceptpower.servlet.web.backing; +package edu.asu.conceptpower.web.backing; import java.util.HashMap; import java.util.Map; diff --git a/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/web/backing/SearchResultBackBeanForm.java b/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/web/backing/SearchResultBackBeanForm.java similarity index 91% rename from Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/web/backing/SearchResultBackBeanForm.java rename to Conceptpower+Spring/src/main/java/edu/asu/conceptpower/web/backing/SearchResultBackBeanForm.java index 64e24d025..caa2723e7 100644 --- a/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/web/backing/SearchResultBackBeanForm.java +++ b/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/web/backing/SearchResultBackBeanForm.java @@ -1,4 +1,4 @@ -package edu.asu.conceptpower.servlet.web.backing; +package edu.asu.conceptpower.web.backing; import java.util.List; diff --git a/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/web/backing/UserBacking.java b/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/web/backing/UserBacking.java similarity index 93% rename from Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/web/backing/UserBacking.java rename to Conceptpower+Spring/src/main/java/edu/asu/conceptpower/web/backing/UserBacking.java index c098617b7..0eb7626ab 100644 --- a/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/web/backing/UserBacking.java +++ b/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/web/backing/UserBacking.java @@ -1,6 +1,6 @@ -package edu.asu.conceptpower.servlet.web.backing; +package edu.asu.conceptpower.web.backing; -import edu.asu.conceptpower.servlet.validation.ValuesMatch; +import edu.asu.conceptpower.app.validation.ValuesMatch; @ValuesMatch(first = "password", second = "retypedPassword") public class UserBacking { diff --git a/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/web/profile/ChangePasswordController.java b/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/web/profile/ChangePasswordController.java similarity index 91% rename from Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/web/profile/ChangePasswordController.java rename to Conceptpower+Spring/src/main/java/edu/asu/conceptpower/web/profile/ChangePasswordController.java index 1934b9b7d..65287cf6c 100644 --- a/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/web/profile/ChangePasswordController.java +++ b/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/web/profile/ChangePasswordController.java @@ -1,4 +1,4 @@ -package edu.asu.conceptpower.servlet.web.profile; +package edu.asu.conceptpower.web.profile; import java.security.Principal; @@ -13,9 +13,9 @@ import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; -import edu.asu.conceptpower.servlet.users.IUserManager; -import edu.asu.conceptpower.servlet.web.profile.backing.PasswordBean; +import edu.asu.conceptpower.app.users.IUserManager; import edu.asu.conceptpower.users.User; +import edu.asu.conceptpower.web.profile.backing.PasswordBean; @Controller public class ChangePasswordController { diff --git a/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/web/profile/ProfileController.java b/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/web/profile/ProfileController.java similarity index 87% rename from Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/web/profile/ProfileController.java rename to Conceptpower+Spring/src/main/java/edu/asu/conceptpower/web/profile/ProfileController.java index 4e2523119..d56da0ad5 100644 --- a/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/web/profile/ProfileController.java +++ b/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/web/profile/ProfileController.java @@ -1,4 +1,4 @@ -package edu.asu.conceptpower.servlet.web.profile; +package edu.asu.conceptpower.web.profile; import java.security.Principal; @@ -7,7 +7,7 @@ import org.springframework.ui.Model; import org.springframework.web.bind.annotation.RequestMapping; -import edu.asu.conceptpower.servlet.users.IUserManager; +import edu.asu.conceptpower.app.users.IUserManager; import edu.asu.conceptpower.users.User; @Controller diff --git a/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/web/profile/backing/PasswordBean.java b/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/web/profile/backing/PasswordBean.java similarity index 87% rename from Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/web/profile/backing/PasswordBean.java rename to Conceptpower+Spring/src/main/java/edu/asu/conceptpower/web/profile/backing/PasswordBean.java index 6eed3b490..09d1a6271 100644 --- a/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/web/profile/backing/PasswordBean.java +++ b/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/web/profile/backing/PasswordBean.java @@ -1,8 +1,8 @@ -package edu.asu.conceptpower.servlet.web.profile.backing; +package edu.asu.conceptpower.web.profile.backing; import org.hibernate.validator.constraints.NotEmpty; -import edu.asu.conceptpower.servlet.validation.ValuesMatch; +import edu.asu.conceptpower.app.validation.ValuesMatch; @ValuesMatch(first = "password", second = "passwordRepeat") public class PasswordBean { diff --git a/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/web/util/ExceptionHandler.java b/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/web/util/ExceptionHandler.java new file mode 100644 index 000000000..4dc40a094 --- /dev/null +++ b/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/web/util/ExceptionHandler.java @@ -0,0 +1,28 @@ +package edu.asu.conceptpower.web.util; + +import java.nio.file.AccessDeniedException; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.security.authentication.BadCredentialsException; +import org.springframework.web.bind.annotation.ControllerAdvice; + +/** + * This class handle exceptions thrown in the controllers. So far, there + * is only one exception page shown if something goes wrong. + * + * @author Julia Damerow + * + */ +@ControllerAdvice +public class ExceptionHandler { + + private static final Logger logger = LoggerFactory.getLogger(ExceptionHandler.class); + + @org.springframework.web.bind.annotation.ExceptionHandler(value = { Exception.class, IllegalArgumentException.class, + IllegalAccessException.class, BadCredentialsException.class, AccessDeniedException.class }) + public String handle(Exception e) { + logger.error("ExceptionHandler caught exception.", e); + return "exception"; + } +} diff --git a/Conceptpower+Spring/src/main/resources/config.properties b/Conceptpower+Spring/src/main/resources/config.properties index f32318e6d..b4a0a29ba 100644 --- a/Conceptpower+Spring/src/main/resources/config.properties +++ b/Conceptpower+Spring/src/main/resources/config.properties @@ -1,3 +1,4 @@ password.recovery.expiration.hours=24 lucenePath=${lucene.path} -numberOfLuceneResults=10 \ No newline at end of file +numberOfLuceneResults=100 +default_page_size=20 \ No newline at end of file diff --git a/Conceptpower+Spring/src/main/resources/locale/errormessages.properties b/Conceptpower+Spring/src/main/resources/locale/errormessages.properties index 8139d62e1..d94f8ce10 100644 --- a/Conceptpower+Spring/src/main/resources/locale/errormessages.properties +++ b/Conceptpower+Spring/src/main/resources/locale/errormessages.properties @@ -3,4 +3,3 @@ error_message_403 = Not authorized to access this page. error_message_404 = Resource not found error_message_405 = Database is down!! People are working on it error_message_406 = Unknown error occurred please contact the administrator - diff --git a/Conceptpower+Spring/src/main/resources/pos.properties b/Conceptpower+Spring/src/main/resources/pos.properties new file mode 100644 index 000000000..2fc440bcb --- /dev/null +++ b/Conceptpower+Spring/src/main/resources/pos.properties @@ -0,0 +1,5 @@ +noun=Noun +verb=Verb +adverb=Adverb +adjective=Adjective +other=Other \ No newline at end of file diff --git a/Conceptpower+Spring/src/main/resources/validatormessages_en_US.properties b/Conceptpower+Spring/src/main/resources/validatormessages_en_US.properties index 296beeed5..54281d3e3 100644 --- a/Conceptpower+Spring/src/main/resources/validatormessages_en_US.properties +++ b/Conceptpower+Spring/src/main/resources/validatormessages_en_US.properties @@ -14,27 +14,30 @@ match.passwords = Passwords do not match. concept_name.required = Concept name is mandatory. concept_description.required = Concept Description is mandatory. concept_unique.required = Concept name should be unique. -concept_name.wordnet = Concept name should not be WordNet. +concept_list_name.wordnet = Concept list name cannot be WordNet. #Concept Type Creation required.type_name = Concept Type name is mandatory. required.type_description = Concept Type description is mandatory. required.unique.type_name = Concept Type should be unique. #User Registration Validator Messages -required.username = Username cannot be empty -required.name = Name of the User cannot be empty -required.password = Password cannot be empty -password.short = Password should be at least 4 characters -required.email = Email cannot be empty -proper.email = Please give a proper email id -username.exists = Username already exists. Please Select a Different Username -proper.username = Username cannot have any special characters or Capital Letters -proper.name = Name cannot have any special characters. Only Spaces allowed +required.username = Username cannot be empty. +required.name = Name of the User cannot be empty. +required.password = Password cannot be empty. +password.short = Password should be at least 4 characters. +required.email = Email cannot be empty. +proper.email = Please give a proper email id. +username.exists = Username already exists. Please select a different username. +proper.username = Username cannot have any special characters or capital letters. +proper.name = Name cannot have any special characters. Only spaces are allowed. #Concept List Creation -concept_name.required = Concept name is mandatory -concept_description.required = Concept Description is mandatory -concept_unique.required = Concept name should be unique -concept_name.wordnet = Concept name should not be WordNet +concept_name.required = Concept name is mandatory. +concept_description.required = Concept description is mandatory. +concept_unique.required = Concept name should be unique. +list.required = Concept list is mandatory. +types.required = Concept type is mandatory. #HomeScreen Validators name.required = Word is mandatory field. -pos.required = POS is mandatory. -no.searchResults = No search results found. \ No newline at end of file +pos.required = POS (part of speech) is mandatory. +no.searchResults = No search results found. +error_message_101 = There are difference in pos within the merging concepts. +error_message_102 = The concepts you are trying to merge have different concept types. \ No newline at end of file diff --git a/Conceptpower+Spring/src/main/webapp/WEB-INF/spring/appServlet/rest-context.xml b/Conceptpower+Spring/src/main/webapp/WEB-INF/spring/appServlet/rest-context.xml new file mode 100644 index 000000000..e28bbd46d --- /dev/null +++ b/Conceptpower+Spring/src/main/webapp/WEB-INF/spring/appServlet/rest-context.xml @@ -0,0 +1,49 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Conceptpower+Spring/src/main/webapp/WEB-INF/spring/appServlet/servlet-context.xml b/Conceptpower+Spring/src/main/webapp/WEB-INF/spring/appServlet/servlet-context.xml index 77eeeb19d..11549d390 100644 --- a/Conceptpower+Spring/src/main/webapp/WEB-INF/spring/appServlet/servlet-context.xml +++ b/Conceptpower+Spring/src/main/webapp/WEB-INF/spring/appServlet/servlet-context.xml @@ -7,15 +7,21 @@ http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd - http://www.springframework.org/schema/security - http://www.springframework.org/schema/security/spring-security-3.2.xsd"> + http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.2.xsd + http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security-3.2.xsd"> - + + + + + + + @@ -37,44 +43,11 @@ + + + + - - - - - - - - - - - smtp - true - true - true - - - - - - - - - - - - - - - - - - - - - - - - - + diff --git a/Conceptpower+Spring/src/main/webapp/WEB-INF/spring/db4o-config.xml b/Conceptpower+Spring/src/main/webapp/WEB-INF/spring/db4o-config.xml index 413a5b6da..cfe76471d 100644 --- a/Conceptpower+Spring/src/main/webapp/WEB-INF/spring/db4o-config.xml +++ b/Conceptpower+Spring/src/main/webapp/WEB-INF/spring/db4o-config.xml @@ -5,23 +5,19 @@ - + - + - - - - - + - + diff --git a/Conceptpower+Spring/src/main/webapp/WEB-INF/spring/rest-service.xml b/Conceptpower+Spring/src/main/webapp/WEB-INF/spring/rest-service.xml index 350ee35ff..3afe09aba 100644 --- a/Conceptpower+Spring/src/main/webapp/WEB-INF/spring/rest-service.xml +++ b/Conceptpower+Spring/src/main/webapp/WEB-INF/spring/rest-service.xml @@ -73,14 +73,11 @@ - - - - edu.asu.conceptpower.servlet.profile.impl.ViafReply + edu.asu.conceptpower.app.profile.impl.ViafReply diff --git a/Conceptpower+Spring/src/main/webapp/WEB-INF/spring/root-context.xml b/Conceptpower+Spring/src/main/webapp/WEB-INF/spring/root-context.xml index e488a0f6e..d36fa7d14 100644 --- a/Conceptpower+Spring/src/main/webapp/WEB-INF/spring/root-context.xml +++ b/Conceptpower+Spring/src/main/webapp/WEB-INF/spring/root-context.xml @@ -3,24 +3,69 @@ xmlns:se="http://www.springframework.org/schema/security" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:context="http://www.springframework.org/schema/context" xmlns:util="http://www.springframework.org/schema/util" + xmlns:task="http://www.springframework.org/schema/task" + xmlns:aop="http://www.springframework.org/schema/aop" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd http://www.springframework.org/schema/security - http://www.springframework.org/schema/security/spring-security-3.2.xsd"> + http://www.springframework.org/schema/security/spring-security-3.2.xsd + http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.2.xsd + http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task-3.0.xsd"> - + + + + + - + - + + + + + + + + + + + + smtp + true + true + true + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Conceptpower+Spring/src/main/webapp/WEB-INF/spring/wordnet-config.xml b/Conceptpower+Spring/src/main/webapp/WEB-INF/spring/wordnet-config.xml index a667cf249..adbb4dab4 100644 --- a/Conceptpower+Spring/src/main/webapp/WEB-INF/spring/wordnet-config.xml +++ b/Conceptpower+Spring/src/main/webapp/WEB-INF/spring/wordnet-config.xml @@ -4,7 +4,7 @@ xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd"> - + diff --git a/Conceptpower+Spring/src/main/webapp/WEB-INF/spring/xml-config.xml b/Conceptpower+Spring/src/main/webapp/WEB-INF/spring/xml-config.xml index 745ca4b48..7996bcc66 100644 --- a/Conceptpower+Spring/src/main/webapp/WEB-INF/spring/xml-config.xml +++ b/Conceptpower+Spring/src/main/webapp/WEB-INF/spring/xml-config.xml @@ -5,7 +5,7 @@ - + diff --git a/Conceptpower+Spring/src/main/webapp/WEB-INF/tiles-defs.xml b/Conceptpower+Spring/src/main/webapp/WEB-INF/tiles-defs.xml index fa08da3b6..4751208f6 100644 --- a/Conceptpower+Spring/src/main/webapp/WEB-INF/tiles-defs.xml +++ b/Conceptpower+Spring/src/main/webapp/WEB-INF/tiles-defs.xml @@ -281,6 +281,14 @@ value="/WEB-INF/views/auth/lucene/luceneindex.jsp" /> + + + + + + + diff --git a/Conceptpower+Spring/src/main/webapp/WEB-INF/tiles/skeleton-nonav.jsp b/Conceptpower+Spring/src/main/webapp/WEB-INF/tiles/skeleton-nonav.jsp index 6737ced5c..dd88036de 100644 --- a/Conceptpower+Spring/src/main/webapp/WEB-INF/tiles/skeleton-nonav.jsp +++ b/Conceptpower+Spring/src/main/webapp/WEB-INF/tiles/skeleton-nonav.jsp @@ -104,7 +104,7 @@ -
+
+