From 728e5eae55ddb33fd8b3d201cd8092262ad64ef4 Mon Sep 17 00:00:00 2001 From: Julia Damerow Date: Mon, 8 Aug 2016 16:31:21 -0700 Subject: [PATCH 01/10] [CCP-159] concepts index uses correct field for indexing ids concepts are deleted from lucene before updating them; descriptions are shown in search view; --- .../asu/conceptpower/root/DatabaseClient.java | 10 ++++ .../conceptpower/root/DatabaseManager.java | 4 ++ .../servlet/core/impl/ConceptManager.java | 12 ++++- .../servlet/db/objectdb/ConceptDBManager.java | 4 ++ .../servlet/db4o/IConceptDBManager.java | 4 ++ .../servlet/lucene/impl/LuceneUtility.java | 46 +++++++++++-------- .../servlet/web/ConceptAddController.java | 7 --- .../servlet/web/ConceptEditController.java | 1 + .../servlet/web/ConceptListController.java | 2 +- .../web/ConceptWrapperAddController.java | 2 +- .../src/main/resources/log4j.xml | 2 +- .../src/main/webapp/WEB-INF/views/home.jsp | 4 +- 12 files changed, 65 insertions(+), 33 deletions(-) diff --git a/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/root/DatabaseClient.java b/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/root/DatabaseClient.java index cc7d4c472..5ba0a1d92 100644 --- a/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/root/DatabaseClient.java +++ b/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/root/DatabaseClient.java @@ -19,6 +19,7 @@ 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; @Component public class DatabaseClient implements IConceptDBManager { @@ -82,6 +83,15 @@ public ConceptEntry getEntry(String id) { return null; } + + @Override + public List getConceptByWordnetId(String wordnetId) { + ConceptEntry entry = new ConceptEntry(); + entry.setWordnetId(wordnetId + ","); + + ObjectSet entries = dictionaryClient.queryByExample(entry); + return entries; + } /* (non-Javadoc) * @see edu.asu.conceptpower.db4o.IConceptDBManager#queryByExample(java.lang.Object) 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 index 0dbcaf1b2..13506539b 100644 --- a/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/root/DatabaseManager.java +++ b/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/root/DatabaseManager.java @@ -7,6 +7,8 @@ import com.db4o.cs.Db4oClientServer; import com.db4o.cs.config.ServerConfiguration; +import edu.asu.conceptpower.core.ConceptEntry; + public class DatabaseManager implements Serializable { /** @@ -21,7 +23,9 @@ public void init() { ServerConfiguration configuration = Db4oClientServer .newServerConfiguration(); configuration.file().blockSize(80); + configuration.common().objectClass(ConceptEntry.class).objectField("wordnetId").indexed(true); server = Db4oClientServer.openServer(configuration, databasePath, 0); + } public ObjectContainer getClient() { 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/servlet/core/impl/ConceptManager.java index 808d6524f..ca94ccad1 100644 --- a/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/core/impl/ConceptManager.java +++ b/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/core/impl/ConceptManager.java @@ -82,7 +82,7 @@ public ConceptEntry getConceptEntry(String id) { */ @Override public ConceptEntry getWordnetConceptEntry(String wordnetId) throws LuceneException { - ConceptEntry entry = getConceptEntry(wordnetId); + ConceptEntry entry = wordnetManager.getConcept(wordnetId); return entry; } @@ -384,6 +384,13 @@ public String addConceptListEntry(ConceptEntry entry) 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; @@ -401,8 +408,9 @@ public String addConceptListEntry(ConceptEntry entry) public void storeModifiedConcept(ConceptEntry entry) throws LuceneException, IllegalAccessException, IndexerRunningException { String modified = entry.getModified() != null ? entry.getModified() : ""; if (!modified.trim().isEmpty()) - modified += ", "; + modified += ", "; entry.setModified(modified + entry.getModifiedUser() + "@" + (new Date()).toString()); + indexService.deleteById(entry.getId()); indexService.insertConcept(entry); client.update(entry, DBNames.DICTIONARY_DB); 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/servlet/db/objectdb/ConceptDBManager.java index ceffe1c6c..32ed0e6f2 100644 --- a/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/db/objectdb/ConceptDBManager.java +++ b/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/db/objectdb/ConceptDBManager.java @@ -92,6 +92,10 @@ public void update(ConceptList list, String listname, String databasename) { // TODO Auto-generated method stub } + + public List getConceptByWordnetId(String wordnetId) { + return null; + } } diff --git a/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/db4o/IConceptDBManager.java b/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/db4o/IConceptDBManager.java index ebeff7ebc..27b1f7c4e 100644 --- a/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/db4o/IConceptDBManager.java +++ b/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/db4o/IConceptDBManager.java @@ -2,6 +2,8 @@ import java.util.List; +import com.db4o.ObjectSet; + import edu.asu.conceptpower.core.ConceptEntry; import edu.asu.conceptpower.core.ConceptList; @@ -41,4 +43,6 @@ public abstract ConceptEntry[] getEntriesByFieldContains(String field, public abstract void update(ConceptList list, String listname, String databasename); + List getConceptByWordnetId(String wordnetId); + } \ No newline at end of file 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/servlet/lucene/impl/LuceneUtility.java index 99ce70cde..c40c5211f 100644 --- a/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/lucene/impl/LuceneUtility.java +++ b/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/lucene/impl/LuceneUtility.java @@ -17,11 +17,12 @@ import org.apache.lucene.analysis.standard.StandardAnalyzer; import org.apache.lucene.document.Document; import org.apache.lucene.document.Field; -import org.apache.lucene.document.StoredField; +import org.apache.lucene.document.StringField; import org.apache.lucene.document.TextField; import org.apache.lucene.index.DirectoryReader; import org.apache.lucene.index.IndexWriter; import org.apache.lucene.index.IndexWriterConfig; +import org.apache.lucene.index.Term; import org.apache.lucene.queryparser.classic.ParseException; import org.apache.lucene.queryparser.classic.QueryParser; import org.apache.lucene.search.IndexSearcher; @@ -30,6 +31,8 @@ import org.apache.lucene.search.TopDocs; 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; @@ -38,7 +41,7 @@ import edu.asu.conceptpower.core.ConceptEntry; import edu.asu.conceptpower.core.IndexingEvent; -import edu.asu.conceptpower.root.DatabaseClient; +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; @@ -66,6 +69,8 @@ @Component @PropertySource("classpath:config.properties") public class LuceneUtility implements ILuceneUtility { + + private final Logger logger = LoggerFactory.getLogger(getClass()); @Autowired private StandardAnalyzer whiteSpaceAnalyzer; @@ -74,7 +79,7 @@ public class LuceneUtility implements ILuceneUtility { private WordNetConfiguration configuration; @Autowired - private DatabaseClient databaseClient; + private IConceptDBManager databaseClient; @Autowired @Qualifier("luceneDAO") @@ -118,14 +123,11 @@ public void init() throws LuceneException { */ public void deleteById(String id) throws LuceneException { try { - Query q = new QueryParser("id", whiteSpaceAnalyzer).parse("id:" + id); - writer.deleteDocuments(q); + writer.deleteDocuments(new Term(LuceneFieldNames.ID, id)); writer.commit(); reloadReader(); } catch (IOException ex) { throw new LuceneException("Issues in deletion. Please retry", ex); - } catch (ParseException e) { - throw new LuceneException("Issues in framing queries", e); } luceneDAO.storeValues(-1, LuceneAction.DELETE); } @@ -151,8 +153,8 @@ public void insertConcept(ConceptEntry entry) throws LuceneException, IllegalAcc doc.add(new TextField(searchFieldAnnotation.lucenefieldName(), String.valueOf(contentOfField), Field.Store.YES)); } else { - doc.add(new StoredField(searchFieldAnnotation.lucenefieldName(), - String.valueOf(contentOfField))); + doc.add(new StringField(searchFieldAnnotation.lucenefieldName(), + String.valueOf(contentOfField), Field.Store.YES)); } } } @@ -222,12 +224,18 @@ protected int[] createDocuments(Iterator iterator, IDictionary dict, List wordIdds = indexWord.getWordIDs(); for (IWordID wordId : wordIdds) { - Document doc = createIndividualDocument(dict, wordId); - try { - numberOfIndexedWords++; - writer.addDocument(doc); - } catch (IOException e) { - numberOfUnIndexedWords++; + 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 { + Document doc = createIndividualDocument(dict, wordId); + try { + numberOfIndexedWords++; + writer.addDocument(doc); + } catch (IOException e) { + numberOfUnIndexedWords++; + } } } } @@ -239,12 +247,12 @@ private Document createIndividualDocument(IDictionary dict, IWordID wordId) { Document doc = new Document(); String lemma = wordId.getLemma().replace("_", " "); doc.add(new TextField(LuceneFieldNames.WORD, lemma, Field.Store.YES)); - doc.add(new TextField(LuceneFieldNames.POS, wordId.getPOS().toString(), Field.Store.YES)); + doc.add(new StringField(LuceneFieldNames.POS, wordId.getPOS().toString(), Field.Store.YES)); IWord word = dict.getWord(wordId); doc.add(new TextField(LuceneFieldNames.DESCRIPTION, word.getSynset().getGloss(), Field.Store.YES)); - doc.add(new TextField(LuceneFieldNames.ID, word.getID().toString(), Field.Store.YES)); - doc.add(new TextField(LuceneFieldNames.WORDNETID, word.getID().toString(), Field.Store.YES)); + doc.add(new StringField(LuceneFieldNames.ID, word.getID().toString(), Field.Store.YES)); + doc.add(new StringField(LuceneFieldNames.WORDNETID, word.getID().toString(), Field.Store.YES)); ISynset synset = word.getSynset(); List synonyms = synset.getWords(); @@ -256,7 +264,7 @@ private Document createIndividualDocument(IDictionary dict, IWordID wordId) { doc.add(new TextField(LuceneFieldNames.SYNONYMID, sb.toString(), Field.Store.YES)); // Adding this new data to delete only wordnet concepts while // adding all wordnet concepts from jwi. - doc.add(new TextField(LuceneFieldNames.CONCEPT_LIST, Constants.WORDNET_DICTIONARY, Field.Store.YES)); + doc.add(new StringField(LuceneFieldNames.CONCEPT_LIST, Constants.WORDNET_DICTIONARY, Field.Store.YES)); return doc; } 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 index 5a6ff1d53..5a64d5240 100644 --- 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 @@ -41,7 +41,6 @@ import edu.asu.conceptpower.servlet.profile.impl.ServiceBackBean; import edu.asu.conceptpower.servlet.profile.impl.ServiceRegistry; import edu.asu.conceptpower.servlet.web.backing.SearchResultBackBeanForm; -import edu.asu.conceptpower.servlet.wrapper.IConceptWrapperCreator; /** * This class provides all the methods required for new concept creation @@ -61,12 +60,6 @@ public class ConceptAddController { @Autowired private IConceptListManager conceptListManager; - @Autowired - private ConceptListController conceptListController; - - @Autowired - private IConceptWrapperCreator wrapperCreator; - @Autowired private IConceptTypeManger conceptTypesManager; diff --git a/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/web/ConceptEditController.java b/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/web/ConceptEditController.java index a47843a18..c91e1f1cd 100644 --- a/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/web/ConceptEditController.java +++ b/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/web/ConceptEditController.java @@ -154,6 +154,7 @@ public ModelAndView confirmEdit(@PathVariable("id") String id, HttpServletReques conceptEntry.setSimilarTo(conceptEditBean.getSimilar()); conceptEntry.setTypeId(conceptEditBean.getSelectedTypeId()); conceptEntry.setSynonymIds(conceptEditBean.getSynonymsids()); + conceptEntry.setModifiedUser(principal.getName()); String userId = usersManager.findUser(principal.getName()).getUsername(); conceptEntry.setModified(userId); diff --git a/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/web/ConceptListController.java b/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/web/ConceptListController.java index 4f32b6d27..027a264f8 100644 --- a/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/web/ConceptListController.java +++ b/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/web/ConceptListController.java @@ -122,7 +122,7 @@ public String getConceptsOfConceptList(@PathVariable("listid") String list, : typeDatabaseClient.getType( wrapper.getEntry().getTypeId()); - details.put("description", wrapper.getEntry().getDescription()); + details.put("description", wrapper.getDescription()); details.put( "type", diff --git a/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/web/ConceptWrapperAddController.java b/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/web/ConceptWrapperAddController.java index 0c3fc092a..cb5d9db3e 100644 --- a/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/web/ConceptWrapperAddController.java +++ b/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/web/ConceptWrapperAddController.java @@ -118,7 +118,7 @@ public String addConcept(HttpServletRequest req, Principal principal, Model mode String[] wrappers = req.getParameter("wrapperids").split(Constants.CONCEPT_SEPARATOR); if (wrappers.length > 0) { ConceptEntry conceptEntry = new ConceptEntry(); - conceptEntry.setWord(conceptManager.getConceptEntry(wrappers[0]).getWord()); + conceptEntry.setWord(conceptManager.getConceptEntry(wrappers[0]).getWord().replace("_", " ")); conceptEntry.setPos(conceptManager.getConceptEntry(wrappers[0]).getPos()); conceptEntry.setSynonymIds(req.getParameter("synonymsids")); conceptEntry.setWordnetId(req.getParameter("wrapperids")); diff --git a/Conceptpower+Spring/src/main/resources/log4j.xml b/Conceptpower+Spring/src/main/resources/log4j.xml index e77a6f828..926605935 100644 --- a/Conceptpower+Spring/src/main/resources/log4j.xml +++ b/Conceptpower+Spring/src/main/resources/log4j.xml @@ -12,7 +12,7 @@ - + diff --git a/Conceptpower+Spring/src/main/webapp/WEB-INF/views/home.jsp b/Conceptpower+Spring/src/main/webapp/WEB-INF/views/home.jsp index a56aec9af..1121b3a40 100644 --- a/Conceptpower+Spring/src/main/webapp/WEB-INF/views/home.jsp +++ b/Conceptpower+Spring/src/main/webapp/WEB-INF/views/home.jsp @@ -89,7 +89,7 @@ $(document).ready(function() { $("#detailsequalto").text(details.equalto); $("#detailssimilarto").text(details.similarto); $("#detailscreator").text(details.creator); - $("#detailsdescription").text(details.description); + $("#detailsdescription").html(details.description); } }); }); @@ -227,7 +227,7 @@ function showFormProcessing() { + value="${concept.description}"> From 7126474dce0c59a7e07351293ad22304dd6b9c9b Mon Sep 17 00:00:00 2001 From: Julia Damerow Date: Mon, 8 Aug 2016 16:35:00 -0700 Subject: [PATCH 02/10] [CCP-159] formatting --- .../src/main/java/edu/asu/conceptpower/root/DatabaseClient.java | 2 +- .../main/java/edu/asu/conceptpower/root/DatabaseManager.java | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/root/DatabaseClient.java b/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/root/DatabaseClient.java index 5ba0a1d92..a348b5028 100644 --- a/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/root/DatabaseClient.java +++ b/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/root/DatabaseClient.java @@ -45,7 +45,7 @@ public void init() { * @see edu.asu.conceptpower.db4o.IConceptDBManager#getEntry(java.lang.String) */ @Override - public ConceptEntry getEntry(String id) { + public ConceptEntry getEntry(String id) { ConceptEntry exampleEntry = new ConceptEntry(); // check if there is a wrapper for wordnet entry 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 index 13506539b..7257dc229 100644 --- a/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/root/DatabaseManager.java +++ b/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/root/DatabaseManager.java @@ -24,6 +24,7 @@ public void init() { .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); } From 267e11cab8b8ece1f2783d8c9b13b9cebb74d46b Mon Sep 17 00:00:00 2001 From: Julia Damerow Date: Mon, 8 Aug 2016 16:37:22 -0700 Subject: [PATCH 03/10] [CCP-159] gitignore --- Conceptpower+Spring/.gitignore | 1 + 1 file changed, 1 insertion(+) create mode 100644 Conceptpower+Spring/.gitignore diff --git a/Conceptpower+Spring/.gitignore b/Conceptpower+Spring/.gitignore new file mode 100644 index 000000000..614e1b2b9 --- /dev/null +++ b/Conceptpower+Spring/.gitignore @@ -0,0 +1 @@ +/buildNumber.properties From 8736eb6a71ff0dcdd374d7a82e0b0d00c7daa097 Mon Sep 17 00:00:00 2001 From: Julia Damerow Date: Mon, 8 Aug 2016 16:39:02 -0700 Subject: [PATCH 04/10] [CCP-159] formatting --- .../asu/conceptpower/root/DatabaseClient.java | 709 +++++++++--------- 1 file changed, 370 insertions(+), 339 deletions(-) diff --git a/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/root/DatabaseClient.java b/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/root/DatabaseClient.java index a348b5028..1359657a9 100644 --- a/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/root/DatabaseClient.java +++ b/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/root/DatabaseClient.java @@ -24,345 +24,376 @@ @Component public class DatabaseClient implements IConceptDBManager { - ObjectContainer wordnetCacheClient; - ObjectContainer dictionaryClient; - - @Autowired - @Qualifier("wordnetCacheDatabaseManager") - private DatabaseManager wordnetCache; - - @Autowired - @Qualifier("conceptDatabaseManager") - private DatabaseManager dictionary; - - @PostConstruct - public void init() { - this.wordnetCacheClient = wordnetCache.getClient(); - this.dictionaryClient = dictionary.getClient(); - } - - /* (non-Javadoc) - * @see edu.asu.conceptpower.db4o.IConceptDBManager#getEntry(java.lang.String) - */ - @Override + ObjectContainer wordnetCacheClient; + ObjectContainer dictionaryClient; + + @Autowired + @Qualifier("wordnetCacheDatabaseManager") + private DatabaseManager wordnetCache; + + @Autowired + @Qualifier("conceptDatabaseManager") + private DatabaseManager dictionary; + + @PostConstruct + public void init() { + this.wordnetCacheClient = wordnetCache.getClient(); + this.dictionaryClient = dictionary.getClient(); + } + + /* + * (non-Javadoc) + * + * @see + * edu.asu.conceptpower.db4o.IConceptDBManager#getEntry(java.lang.String) + */ + @Override public ConceptEntry getEntry(String id) { - ConceptEntry exampleEntry = new ConceptEntry(); - - // check if there is a wrapper for wordnet entry - exampleEntry.setId(null); - exampleEntry.setWordnetId(id); - - ConceptEntry[] dictionaryResults = getEntriesByFieldContains( - "wordnetid", id); - // ObjectSet results = dictionaryClient - // .queryByExample(exampleEntry); - - // there should only be exactly one object with this id - if (dictionaryResults.length == 1) - return dictionaryResults[0]; - - 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); - // there should only be exactly one object with this id - if (results.size() == 1) - return results.get(0); - - return null; - } - - @Override + ConceptEntry exampleEntry = new ConceptEntry(); + + // check if there is a wrapper for wordnet entry + exampleEntry.setId(null); + exampleEntry.setWordnetId(id); + + ConceptEntry[] dictionaryResults = getEntriesByFieldContains("wordnetid", id); + // ObjectSet results = dictionaryClient + // .queryByExample(exampleEntry); + + // there should only be exactly one object with this id + if (dictionaryResults.length == 1) + return dictionaryResults[0]; + + 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); + // there should only be exactly one object with this id + if (results.size() == 1) + return results.get(0); + + return null; + } + + @Override public List getConceptByWordnetId(String wordnetId) { - ConceptEntry entry = new ConceptEntry(); - entry.setWordnetId(wordnetId + ","); - - ObjectSet entries = dictionaryClient.queryByExample(entry); - return entries; - } - - /* (non-Javadoc) - * @see edu.asu.conceptpower.db4o.IConceptDBManager#queryByExample(java.lang.Object) - */ - @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; - - } - - /* (non-Javadoc) - * @see edu.asu.conceptpower.db4o.IConceptDBManager#getEntriesByFieldContains(java.lang.String, java.lang.String) - */ - @Override - public ConceptEntry[] getEntriesByFieldContains(String field, - String containsString) { - if (containsString == null || field == null) - return new ConceptEntry[0]; - final String fField = field; - final String fSearchFor = containsString; - - ObjectSet results = dictionaryClient - .query(new Predicate() { - public boolean match(ConceptEntry con) { - - // go through all fields of class to find field that - // should be searched - Field[] fields = con.getClass().getDeclaredFields(); - for (Field field : fields) { - SearchField searchFieldAnnotation = field - .getAnnotation(SearchField.class); - if (searchFieldAnnotation != null) { - // if we found the field that should be search - // through - if (searchFieldAnnotation.fieldName().equals( - fField)) { - String fieldContent = null; - // check content - try { - field.setAccessible(true); - Object contentOfField = field.get(con); - if (contentOfField instanceof String) - fieldContent = contentOfField - .toString(); - } catch (IllegalArgumentException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - continue; - } catch (IllegalAccessException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - continue; - } - - if (fieldContent != null) { - if (fieldContent - .trim() - .toLowerCase() - .contains( - fSearchFor.trim() - .toLowerCase())) - return true; - } - return false; - } - } - } - - return false; - } - }); - - return results.toArray(new ConceptEntry[results.size()]); - } - - /* (non-Javadoc) - * @see edu.asu.conceptpower.db4o.IConceptDBManager#getEntriesForWord(java.lang.String, java.lang.String) - */ - @Override - public ConceptEntry[] getEntriesForWord(String word, String pos) { - ConceptEntry[] allConcepts = getEntriesForWord(word); - - List entries = new ArrayList(); - for (ConceptEntry entry : allConcepts) { - if (entry.getPos().toLowerCase().equals(pos.toLowerCase()) - && !entry.isDeleted()) - entries.add(entry); - } - - return entries.toArray(new ConceptEntry[entries.size()]); - } - - /* (non-Javadoc) - * @see edu.asu.conceptpower.db4o.IConceptDBManager#getSynonymsPointingToId(java.lang.String) - */ - @Override - public ConceptEntry[] getSynonymsPointingToId(String id) { - List entries = new ArrayList(); - final String wordId = id; - - ObjectSet results = dictionaryClient - .query(new Predicate() { - public boolean match(ConceptEntry con) { - return con.getSynonymIds().contains(wordId) - && !con.isDeleted(); - } - }); - - if (results.size() > 0) { - entries.addAll(results); - } - - return entries.toArray(new ConceptEntry[entries.size()]); - } - - /* (non-Javadoc) - * @see edu.asu.conceptpower.db4o.IConceptDBManager#getEntriesForWord(java.lang.String) - */ - @Override - public ConceptEntry[] getEntriesForWord(String word) { - - List entries = new ArrayList(); - - // check user build dictionary - final String fWord = word; - ObjectSet results = dictionaryClient - .query(new Predicate() { - public boolean match(ConceptEntry con) { - return con.getWord().replace("_", " ").toLowerCase() - .contains(fWord.toLowerCase()) - && !con.isDeleted(); - } - }); - - if (results.size() > 0) { - entries.addAll(results); - } - - return entries.toArray(new ConceptEntry[entries.size()]); - } - - /* (non-Javadoc) - * @see edu.asu.conceptpower.db4o.IConceptDBManager#getConceptList(java.lang.String) - */ - @Override - @SuppressWarnings("serial") - public ConceptList getConceptList(String name) { - final String fName = name; - List dicts = dictionaryClient - .query(new Predicate() { - public boolean match(ConceptList dict) { - return dict.getConceptListName().equals(fName); - } - }); - - if (dicts.size() == 1) - return dicts.get(0); - return null; - } - - /* (non-Javadoc) - * @see edu.asu.conceptpower.db4o.IConceptDBManager#getAllElementsOfType(java.lang.Class) - */ - @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; - } - - /* (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); - - List results = wordnetCacheClient.queryByExample(entry); - List dictResults = dictionaryClient.queryByExample(entry); - - List allResults = new ArrayList(); - allResults.addAll(results); - allResults.addAll(dictResults); - return allResults; - } - - /* (non-Javadoc) - * @see edu.asu.conceptpower.db4o.IConceptDBManager#store(java.lang.Object, java.lang.String) - */ - @Override - public void store(Object element, String databasename) { - // FIXME no caching? - // if (databasename.equals(DBNames.WORDNET_CACHE)) { - // wordnetCacheClient.store(element); - // wordnetCacheClient.commit(); - // return; - // } - if (databasename.equals(DBNames.DICTIONARY_DB)) { - dictionaryClient.store(element); - dictionaryClient.commit(); - } - } - - /* (non-Javadoc) - * @see edu.asu.conceptpower.db4o.IConceptDBManager#update(edu.asu.conceptpower.core.ConceptEntry, java.lang.String) - */ - @Override - public void update(ConceptEntry entry, String databasename) { - if (databasename.equals(DBNames.DICTIONARY_DB)) { - ConceptEntry toBeUpdated = getEntry(entry.getId()); - toBeUpdated.setBroadens(entry.getBroadens()); - toBeUpdated.setConceptList(entry.getConceptList()); - toBeUpdated.setDescription(entry.getDescription()); - toBeUpdated.setEqualTo(entry.getEqualTo()); - toBeUpdated.setModified(entry.getModified()); - toBeUpdated.setNarrows(entry.getNarrows()); - toBeUpdated.setPos(entry.getPos()); - toBeUpdated.setSimilarTo(entry.getSimilarTo()); - toBeUpdated.setSynonymIds(entry.getSynonymIds()); - toBeUpdated.setSynsetIds(entry.getSynsetIds()); - toBeUpdated.setTypeId(entry.getTypeId()); - toBeUpdated.setWord(entry.getWord()); - toBeUpdated.setWordnetId(entry.getWordnetId()); - toBeUpdated.setDeleted(entry.isDeleted()); - dictionaryClient.store(toBeUpdated); - dictionaryClient.commit(); - } - } - - /* (non-Javadoc) - * @see edu.asu.conceptpower.db4o.IConceptDBManager#deleteConceptList(java.lang.String) - */ - @Override - public void deleteConceptList(String name) { - ConceptList list = new ConceptList(); - list.setConceptListName(name); - - ObjectSet results = dictionaryClient.queryByExample(list); - for (ConceptList res : results) { - dictionaryClient.delete(res); - dictionaryClient.commit(); - } - } - - /* (non-Javadoc) - * @see edu.asu.conceptpower.db4o.IConceptDBManager#update(edu.asu.conceptpower.core.ConceptList, java.lang.String, java.lang.String) - */ - @Override - public void update(ConceptList list, String listname, String databasename) { - if (databasename.equals(DBNames.DICTIONARY_DB)) { - ConceptList toBeUpdated = getConceptList(listname); - toBeUpdated.setConceptListName(list.getConceptListName()); - toBeUpdated.setDescription(list.getDescription()); - dictionaryClient.store(list); - dictionaryClient.commit(); - } - } + ConceptEntry entry = new ConceptEntry(); + entry.setWordnetId(wordnetId + ","); + + ObjectSet entries = dictionaryClient.queryByExample(entry); + return entries; + } + + /* + * (non-Javadoc) + * + * @see + * edu.asu.conceptpower.db4o.IConceptDBManager#queryByExample(java.lang. + * Object) + */ + @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; + + } + + /* + * (non-Javadoc) + * + * @see + * edu.asu.conceptpower.db4o.IConceptDBManager#getEntriesByFieldContains( + * java.lang.String, java.lang.String) + */ + @Override + public ConceptEntry[] getEntriesByFieldContains(String field, String containsString) { + if (containsString == null || field == null) + return new ConceptEntry[0]; + final String fField = field; + final String fSearchFor = containsString; + + ObjectSet results = dictionaryClient.query(new Predicate() { + public boolean match(ConceptEntry con) { + + // go through all fields of class to find field that + // should be searched + Field[] fields = con.getClass().getDeclaredFields(); + for (Field field : fields) { + SearchField searchFieldAnnotation = field.getAnnotation(SearchField.class); + if (searchFieldAnnotation != null) { + // if we found the field that should be search + // through + if (searchFieldAnnotation.fieldName().equals(fField)) { + String fieldContent = null; + // check content + try { + field.setAccessible(true); + Object contentOfField = field.get(con); + if (contentOfField instanceof String) + fieldContent = contentOfField.toString(); + } catch (IllegalArgumentException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + continue; + } catch (IllegalAccessException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + continue; + } + + if (fieldContent != null) { + if (fieldContent.trim().toLowerCase().contains(fSearchFor.trim().toLowerCase())) + return true; + } + return false; + } + } + } + + return false; + } + }); + + return results.toArray(new ConceptEntry[results.size()]); + } + + /* + * (non-Javadoc) + * + * @see + * edu.asu.conceptpower.db4o.IConceptDBManager#getEntriesForWord(java.lang. + * String, java.lang.String) + */ + @Override + public ConceptEntry[] getEntriesForWord(String word, String pos) { + ConceptEntry[] allConcepts = getEntriesForWord(word); + + List entries = new ArrayList(); + for (ConceptEntry entry : allConcepts) { + if (entry.getPos().toLowerCase().equals(pos.toLowerCase()) && !entry.isDeleted()) + entries.add(entry); + } + + return entries.toArray(new ConceptEntry[entries.size()]); + } + + /* + * (non-Javadoc) + * + * @see + * edu.asu.conceptpower.db4o.IConceptDBManager#getSynonymsPointingToId(java. + * lang.String) + */ + @Override + public ConceptEntry[] getSynonymsPointingToId(String id) { + List entries = new ArrayList(); + final String wordId = id; + + ObjectSet results = dictionaryClient.query(new Predicate() { + public boolean match(ConceptEntry con) { + return con.getSynonymIds().contains(wordId) && !con.isDeleted(); + } + }); + + if (results.size() > 0) { + entries.addAll(results); + } + + return entries.toArray(new ConceptEntry[entries.size()]); + } + + /* + * (non-Javadoc) + * + * @see + * edu.asu.conceptpower.db4o.IConceptDBManager#getEntriesForWord(java.lang. + * String) + */ + @Override + public ConceptEntry[] getEntriesForWord(String word) { + + List entries = new ArrayList(); + + // check user build dictionary + final String fWord = word; + ObjectSet results = dictionaryClient.query(new Predicate() { + public boolean match(ConceptEntry con) { + return con.getWord().replace("_", " ").toLowerCase().contains(fWord.toLowerCase()) && !con.isDeleted(); + } + }); + + if (results.size() > 0) { + entries.addAll(results); + } + + return entries.toArray(new ConceptEntry[entries.size()]); + } + + /* + * (non-Javadoc) + * + * @see + * edu.asu.conceptpower.db4o.IConceptDBManager#getConceptList(java.lang. + * String) + */ + @Override + @SuppressWarnings("serial") + public ConceptList getConceptList(String name) { + final String fName = name; + List dicts = dictionaryClient.query(new Predicate() { + public boolean match(ConceptList dict) { + return dict.getConceptListName().equals(fName); + } + }); + + if (dicts.size() == 1) + return dicts.get(0); + return null; + } + + /* + * (non-Javadoc) + * + * @see + * edu.asu.conceptpower.db4o.IConceptDBManager#getAllElementsOfType(java. + * lang.Class) + */ + @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; + } + + /* + * (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); + + List results = wordnetCacheClient.queryByExample(entry); + List dictResults = dictionaryClient.queryByExample(entry); + + List allResults = new ArrayList(); + allResults.addAll(results); + allResults.addAll(dictResults); + return allResults; + } + + /* + * (non-Javadoc) + * + * @see edu.asu.conceptpower.db4o.IConceptDBManager#store(java.lang.Object, + * java.lang.String) + */ + @Override + public void store(Object element, String databasename) { + // FIXME no caching? + // if (databasename.equals(DBNames.WORDNET_CACHE)) { + // wordnetCacheClient.store(element); + // wordnetCacheClient.commit(); + // return; + // } + if (databasename.equals(DBNames.DICTIONARY_DB)) { + dictionaryClient.store(element); + dictionaryClient.commit(); + } + } + + /* + * (non-Javadoc) + * + * @see + * edu.asu.conceptpower.db4o.IConceptDBManager#update(edu.asu.conceptpower. + * core.ConceptEntry, java.lang.String) + */ + @Override + public void update(ConceptEntry entry, String databasename) { + if (databasename.equals(DBNames.DICTIONARY_DB)) { + ConceptEntry toBeUpdated = getEntry(entry.getId()); + toBeUpdated.setBroadens(entry.getBroadens()); + toBeUpdated.setConceptList(entry.getConceptList()); + toBeUpdated.setDescription(entry.getDescription()); + toBeUpdated.setEqualTo(entry.getEqualTo()); + toBeUpdated.setModified(entry.getModified()); + toBeUpdated.setNarrows(entry.getNarrows()); + toBeUpdated.setPos(entry.getPos()); + toBeUpdated.setSimilarTo(entry.getSimilarTo()); + toBeUpdated.setSynonymIds(entry.getSynonymIds()); + toBeUpdated.setSynsetIds(entry.getSynsetIds()); + toBeUpdated.setTypeId(entry.getTypeId()); + toBeUpdated.setWord(entry.getWord()); + toBeUpdated.setWordnetId(entry.getWordnetId()); + toBeUpdated.setDeleted(entry.isDeleted()); + dictionaryClient.store(toBeUpdated); + dictionaryClient.commit(); + } + } + + /* + * (non-Javadoc) + * + * @see + * edu.asu.conceptpower.db4o.IConceptDBManager#deleteConceptList(java.lang. + * String) + */ + @Override + public void deleteConceptList(String name) { + ConceptList list = new ConceptList(); + list.setConceptListName(name); + + ObjectSet results = dictionaryClient.queryByExample(list); + for (ConceptList res : results) { + dictionaryClient.delete(res); + dictionaryClient.commit(); + } + } + + /* + * (non-Javadoc) + * + * @see + * edu.asu.conceptpower.db4o.IConceptDBManager#update(edu.asu.conceptpower. + * core.ConceptList, java.lang.String, java.lang.String) + */ + @Override + public void update(ConceptList list, String listname, String databasename) { + if (databasename.equals(DBNames.DICTIONARY_DB)) { + ConceptList toBeUpdated = getConceptList(listname); + toBeUpdated.setConceptListName(list.getConceptListName()); + toBeUpdated.setDescription(list.getDescription()); + dictionaryClient.store(list); + dictionaryClient.commit(); + } + } } From 755aabfd24a3a4bb7c8c568ade716ef89ca559d1 Mon Sep 17 00:00:00 2001 From: Julia Damerow Date: Tue, 16 Aug 2016 15:24:24 -0700 Subject: [PATCH 05/10] [CCP-160] added page for user to change password --- .../validation/ValuesMatchValidator.java | 6 +-- .../web/profile/ChangePasswordController.java | 53 +++++++++++++++++++ .../web/profile/ProfileController.java | 29 ++++++++++ .../web/profile/backing/PasswordBean.java | 35 ++++++++++++ .../src/main/webapp/WEB-INF/tiles-defs.xml | 19 ++++++- .../webapp/WEB-INF/tiles/skeleton-nonav.jsp | 4 +- .../main/webapp/WEB-INF/tiles/skeleton.jsp | 4 +- .../WEB-INF/views/auth/profile/password.jsp | 38 +++++++++++++ .../WEB-INF/views/auth/profile/profile.jsp | 21 ++++++++ .../main/webapp/resources/assets/css/main.css | 4 ++ 10 files changed, 205 insertions(+), 8 deletions(-) create mode 100644 Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/web/profile/ChangePasswordController.java create mode 100644 Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/web/profile/ProfileController.java create mode 100644 Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/web/profile/backing/PasswordBean.java create mode 100644 Conceptpower+Spring/src/main/webapp/WEB-INF/views/auth/profile/password.jsp create mode 100644 Conceptpower+Spring/src/main/webapp/WEB-INF/views/auth/profile/profile.jsp diff --git a/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/validation/ValuesMatchValidator.java b/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/validation/ValuesMatchValidator.java index 95697df3a..e0acb670e 100644 --- a/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/validation/ValuesMatchValidator.java +++ b/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/validation/ValuesMatchValidator.java @@ -51,7 +51,7 @@ public boolean isValid(Object arg0, ConstraintValidatorContext context) { if (firstObj.equals("") || firstObj == null) { context.disableDefaultConstraintViolation(); - context.buildConstraintViolationWithTemplate("This field cannot be empty").addNode(firstFieldName) + context.buildConstraintViolationWithTemplate("This field cannot be empty.").addNode(firstFieldName) .addConstraintViolation(); return false; } @@ -65,7 +65,7 @@ public boolean isValid(Object arg0, ConstraintValidatorContext context) { if (secondObj.equals("") || secondObj == null) { context.disableDefaultConstraintViolation(); - context.buildConstraintViolationWithTemplate("This field cannot be empty").addNode(secondFieldName) + context.buildConstraintViolationWithTemplate("This field cannot be empty.").addNode(secondFieldName) .addConstraintViolation(); return false; } @@ -74,7 +74,7 @@ public boolean isValid(Object arg0, ConstraintValidatorContext context) { if (!matches) { context.disableDefaultConstraintViolation(); - context.buildConstraintViolationWithTemplate("Passwords do not match").addNode(secondFieldName) + context.buildConstraintViolationWithTemplate("Passwords do not match.").addNode(secondFieldName) .addConstraintViolation(); } 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/servlet/web/profile/ChangePasswordController.java new file mode 100644 index 000000000..87409ffc7 --- /dev/null +++ b/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/web/profile/ChangePasswordController.java @@ -0,0 +1,53 @@ +package edu.asu.conceptpower.servlet.web.profile; + +import java.security.Principal; + +import javax.validation.Valid; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.security.crypto.bcrypt.BCrypt; +import org.springframework.stereotype.Controller; +import org.springframework.ui.Model; +import org.springframework.validation.BindingResult; +import org.springframework.web.bind.annotation.ModelAttribute; +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.users.User; + +@Controller +public class ChangePasswordController { + + @Autowired + private IUserManager userManager; + + @RequestMapping(value = "/auth/profile/password/change", method = RequestMethod.GET) + public String showChangePassword(Model model, Principal principal) { + model.addAttribute("passwordBean", new PasswordBean()); + + return "auth/profile/password"; + } + + @RequestMapping(value = "/auth/profile/password/change", method = RequestMethod.POST) + public String changePassword(@Valid @ModelAttribute PasswordBean passwordBean, BindingResult results, Model model, Principal principal) { + if (results.hasErrors()) { + passwordBean.setOldPassword(""); + return "auth/profile/password"; + } + + String oldPasswordEncrypt = BCrypt.hashpw(passwordBean.getOldPassword(), BCrypt.gensalt()); + User user = userManager.getUser(principal.getName(), oldPasswordEncrypt); + if (user != null) { + user.setPw(passwordBean.getPassword()); + userManager.storeModifiedPassword(user); + return "redirect:/auth/profile"; + } + + model.addAttribute("show_error_alert", true); + model.addAttribute("error_alert_msg", "Your password could not be changed. The old password you've entered was incorrect."); + model.addAttribute("passwordBean", new PasswordBean()); + return "auth/profile/password"; + } +} 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/servlet/web/profile/ProfileController.java new file mode 100644 index 000000000..4e2523119 --- /dev/null +++ b/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/web/profile/ProfileController.java @@ -0,0 +1,29 @@ +package edu.asu.conceptpower.servlet.web.profile; + +import java.security.Principal; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Controller; +import org.springframework.ui.Model; +import org.springframework.web.bind.annotation.RequestMapping; + +import edu.asu.conceptpower.servlet.users.IUserManager; +import edu.asu.conceptpower.users.User; + +@Controller +public class ProfileController { + + @Autowired + private IUserManager userManager; + + @RequestMapping(value = "/auth/profile") + public String showProfile(Model model, Principal principal) { + User user = userManager.findUser(principal.getName()); + if (user == null) { + return "auth/user/notfound"; + } + + model.addAttribute("currentUser", user); + return "auth/profile"; + } +} 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/servlet/web/profile/backing/PasswordBean.java new file mode 100644 index 000000000..6eed3b490 --- /dev/null +++ b/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/web/profile/backing/PasswordBean.java @@ -0,0 +1,35 @@ +package edu.asu.conceptpower.servlet.web.profile.backing; + +import org.hibernate.validator.constraints.NotEmpty; + +import edu.asu.conceptpower.servlet.validation.ValuesMatch; + +@ValuesMatch(first = "password", second = "passwordRepeat") +public class PasswordBean { + + @NotEmpty(message="Please enter your current password.") + private String oldPassword; + private String password; + private String passwordRepeat; + + public String getPassword() { + return password; + } + public void setPassword(String password) { + this.password = password; + } + public String getPasswordRepeat() { + return passwordRepeat; + } + public void setPasswordRepeat(String passwordRepeat) { + this.passwordRepeat = passwordRepeat; + } + public String getOldPassword() { + return oldPassword; + } + public void setOldPassword(String oldPassword) { + this.oldPassword = oldPassword; + } + + +} 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 5d7ce8b21..fa08da3b6 100644 --- a/Conceptpower+Spring/src/main/webapp/WEB-INF/tiles-defs.xml +++ b/Conceptpower+Spring/src/main/webapp/WEB-INF/tiles-defs.xml @@ -275,13 +275,30 @@ - + + + + + + + + + + + + + + + + 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 b96d4a7c2..6737ced5c 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 @@ -117,8 +117,8 @@

- - + "> +

diff --git a/Conceptpower+Spring/src/main/webapp/WEB-INF/tiles/skeleton.jsp b/Conceptpower+Spring/src/main/webapp/WEB-INF/tiles/skeleton.jsp index 5b6e4b1e0..4b1f71b26 100644 --- a/Conceptpower+Spring/src/main/webapp/WEB-INF/tiles/skeleton.jsp +++ b/Conceptpower+Spring/src/main/webapp/WEB-INF/tiles/skeleton.jsp @@ -123,8 +123,8 @@

- - + "> +

diff --git a/Conceptpower+Spring/src/main/webapp/WEB-INF/views/auth/profile/password.jsp b/Conceptpower+Spring/src/main/webapp/WEB-INF/views/auth/profile/password.jsp new file mode 100644 index 000000000..8e576c305 --- /dev/null +++ b/Conceptpower+Spring/src/main/webapp/WEB-INF/views/auth/profile/password.jsp @@ -0,0 +1,38 @@ +<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%> +<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form"%> + +

Change Password

+ +

Please enter your new password and repeat it.

+ + + +
+ +
+ + +
+
+
+ +
+ + +
+
+
+ +
+ + +
+
+ +
+ +
+
\ No newline at end of file diff --git a/Conceptpower+Spring/src/main/webapp/WEB-INF/views/auth/profile/profile.jsp b/Conceptpower+Spring/src/main/webapp/WEB-INF/views/auth/profile/profile.jsp new file mode 100644 index 000000000..e06b81206 --- /dev/null +++ b/Conceptpower+Spring/src/main/webapp/WEB-INF/views/auth/profile/profile.jsp @@ -0,0 +1,21 @@ +<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%> + + + +

+ ${currentUser.email} +

+

+ +Admin + + +Regular User + +

+ +

+">Change Password +

\ No newline at end of file diff --git a/Conceptpower+Spring/src/main/webapp/resources/assets/css/main.css b/Conceptpower+Spring/src/main/webapp/resources/assets/css/main.css index 6c0966b04..d4ba3f387 100644 --- a/Conceptpower+Spring/src/main/webapp/resources/assets/css/main.css +++ b/Conceptpower+Spring/src/main/webapp/resources/assets/css/main.css @@ -109,4 +109,8 @@ img.pull-left { margin-right: 10px; } .widget-simplenav { margin-left:-5px; } .widget-simplenav a{ margin:0 5px; } + +.error { + color: darkred; +} \ No newline at end of file From ec9f7412e3665f0bb883e4ff57370a3ffa93fe4a Mon Sep 17 00:00:00 2001 From: Julia Damerow Date: Wed, 17 Aug 2016 07:53:58 -0700 Subject: [PATCH 06/10] [CCP-160] check password correctly --- .../web/profile/ChangePasswordController.java | 21 ++++++++++--------- 1 file changed, 11 insertions(+), 10 deletions(-) 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/servlet/web/profile/ChangePasswordController.java index 87409ffc7..1934b9b7d 100644 --- a/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/web/profile/ChangePasswordController.java +++ b/Conceptpower+Spring/src/main/java/edu/asu/conceptpower/servlet/web/profile/ChangePasswordController.java @@ -19,34 +19,35 @@ @Controller public class ChangePasswordController { - + @Autowired private IUserManager userManager; @RequestMapping(value = "/auth/profile/password/change", method = RequestMethod.GET) public String showChangePassword(Model model, Principal principal) { model.addAttribute("passwordBean", new PasswordBean()); - + return "auth/profile/password"; } - + @RequestMapping(value = "/auth/profile/password/change", method = RequestMethod.POST) - public String changePassword(@Valid @ModelAttribute PasswordBean passwordBean, BindingResult results, Model model, Principal principal) { + public String changePassword(@Valid @ModelAttribute PasswordBean passwordBean, BindingResult results, Model model, + Principal principal) { if (results.hasErrors()) { passwordBean.setOldPassword(""); return "auth/profile/password"; } - - String oldPasswordEncrypt = BCrypt.hashpw(passwordBean.getOldPassword(), BCrypt.gensalt()); - User user = userManager.getUser(principal.getName(), oldPasswordEncrypt); - if (user != null) { + + User user = userManager.findUser(principal.getName()); + if (user != null && BCrypt.checkpw(passwordBean.getOldPassword(), user.getPw())) { user.setPw(passwordBean.getPassword()); userManager.storeModifiedPassword(user); return "redirect:/auth/profile"; } - + model.addAttribute("show_error_alert", true); - model.addAttribute("error_alert_msg", "Your password could not be changed. The old password you've entered was incorrect."); + model.addAttribute("error_alert_msg", + "Your password could not be changed. The old password you've entered was incorrect."); model.addAttribute("passwordBean", new PasswordBean()); return "auth/profile/password"; } From 8e576b17d2acce3c7253128cd084fa96e00eb5be Mon Sep 17 00:00:00 2001 From: Julia Damerow Date: Wed, 17 Aug 2016 09:57:34 -0700 Subject: [PATCH 07/10] [CCP-161] added link to forgot password page --- .../src/main/webapp/WEB-INF/views/forgot.jsp | 6 +++++- .../src/main/webapp/WEB-INF/views/nav/mainnav.jsp | 3 +++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/Conceptpower+Spring/src/main/webapp/WEB-INF/views/forgot.jsp b/Conceptpower+Spring/src/main/webapp/WEB-INF/views/forgot.jsp index aae4c40fd..addb44192 100644 --- a/Conceptpower+Spring/src/main/webapp/WEB-INF/views/forgot.jsp +++ b/Conceptpower+Spring/src/main/webapp/WEB-INF/views/forgot.jsp @@ -14,8 +14,12 @@ commandName="emailBackBean" action="${pageContext.servletContext.contextPath}/emailSent" method='post'> - Email address: +

+ Email address: +

+

+

diff --git a/Conceptpower+Spring/src/main/webapp/WEB-INF/views/nav/mainnav.jsp b/Conceptpower+Spring/src/main/webapp/WEB-INF/views/nav/mainnav.jsp index 676e7cf28..d02e8cc00 100644 --- a/Conceptpower+Spring/src/main/webapp/WEB-INF/views/nav/mainnav.jsp +++ b/Conceptpower+Spring/src/main/webapp/WEB-INF/views/nav/mainnav.jsp @@ -106,5 +106,8 @@ class="btn btn-action btn-sm" /> + \ No newline at end of file From acc3f8d3479da45ca287b87739aa935c14bc4e7c Mon Sep 17 00:00:00 2001 From: Julia Damerow Date: Wed, 17 Aug 2016 10:19:46 -0700 Subject: [PATCH 08/10] [CCP-161] fixed some layout issues --- .../src/main/webapp/WEB-INF/views/resetComplete.jsp | 4 ++-- .../src/main/webapp/WEB-INF/views/resetPassword.jsp | 2 +- .../src/main/webapp/WEB-INF/views/startReset.jsp | 4 ++++ 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/Conceptpower+Spring/src/main/webapp/WEB-INF/views/resetComplete.jsp b/Conceptpower+Spring/src/main/webapp/WEB-INF/views/resetComplete.jsp index 00a5f7e10..e81028c4c 100644 --- a/Conceptpower+Spring/src/main/webapp/WEB-INF/views/resetComplete.jsp +++ b/Conceptpower+Spring/src/main/webapp/WEB-INF/views/resetComplete.jsp @@ -19,11 +19,11 @@ - + - + diff --git a/Conceptpower+Spring/src/main/webapp/WEB-INF/views/resetPassword.jsp b/Conceptpower+Spring/src/main/webapp/WEB-INF/views/resetPassword.jsp index f5e707b82..d75d4c96c 100644 --- a/Conceptpower+Spring/src/main/webapp/WEB-INF/views/resetPassword.jsp +++ b/Conceptpower+Spring/src/main/webapp/WEB-INF/views/resetPassword.jsp @@ -32,7 +32,7 @@ + path="retypedPassword" class="form-control"/> diff --git a/Conceptpower+Spring/src/main/webapp/WEB-INF/views/startReset.jsp b/Conceptpower+Spring/src/main/webapp/WEB-INF/views/startReset.jsp index a0af1d5b2..7f4ee5339 100644 --- a/Conceptpower+Spring/src/main/webapp/WEB-INF/views/startReset.jsp +++ b/Conceptpower+Spring/src/main/webapp/WEB-INF/views/startReset.jsp @@ -14,9 +14,13 @@ commandName="emailBackBean" action="${pageContext.servletContext.contextPath}/reset" method='post'> +

Email address: +

+

+

From ebb7a6a16e774f0cdf4e0aa879728607c2d9b6f0 Mon Sep 17 00:00:00 2001 From: Julia Damerow Date: Wed, 17 Aug 2016 10:43:30 -0700 Subject: [PATCH 09/10] Make debug level configurable through maven. --- Conceptpower+Spring/pom.xml | 1 + Conceptpower+Spring/src/main/resources/log4j.xml | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/Conceptpower+Spring/pom.xml b/Conceptpower+Spring/pom.xml index b36d22e81..400bfc1a4 100644 --- a/Conceptpower+Spring/pom.xml +++ b/Conceptpower+Spring/pom.xml @@ -28,6 +28,7 @@ 3.2.8.RELEASE /Users/karthikeyanmohan/Software/Conceptpower/indexFiles + debug diff --git a/Conceptpower+Spring/src/main/resources/log4j.xml b/Conceptpower+Spring/src/main/resources/log4j.xml index 926605935..dffac3cd8 100644 --- a/Conceptpower+Spring/src/main/resources/log4j.xml +++ b/Conceptpower+Spring/src/main/resources/log4j.xml @@ -12,7 +12,7 @@ - + From 38a47c365d22641bdd37c92a18b8fe46634934f9 Mon Sep 17 00:00:00 2001 From: Julia Damerow Date: Wed, 17 Aug 2016 10:46:32 -0700 Subject: [PATCH 10/10] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 06153f56d..8eb568e9a 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ # Conceptpower -[![Build Status](http://diging-dev.asu.edu:8091/buildStatus/icon?job=Conceptpower_deploy_on_push_to_develop)](http://diging-dev.asu.edu:8091/job/Conceptpower_deploy_on_push_to_develop/) +[![Build Status](http://diging-dev.asu.edu/jenkins/buildStatus/icon?job=Conceptpower_deploy_on_push_to_develop)](http://diging-dev.asu.edu:8091/job/Conceptpower_deploy_on_push_to_develop/) Conceptpower is an authority file service, which is based on WordNet 3.0 (http://wordnet.princeton.edu) and can be extended as needed. It is being developed by the digital history and philosophy of science group in the Center for Biology and Society at Arizona State University. Conceptpower is a Java web application that can be deployed in a servlet container such as Apache Tomcat.
Username:
Password:
Re-type new password: