From f2ff8f1dee830840a0458fee3176e339101055b9 Mon Sep 17 00:00:00 2001 From: nicholaswilson100 Date: Fri, 5 Feb 2016 10:16:50 +0000 Subject: [PATCH] SAK-30322: Rename Sakai Resource Picker to "Search Resources"Changing SAK-30322: Various bug fixes SAK-30322: Various bug fixes 2 SAK-30322: Various bug fixes 3 SAK-30322: Export button and citation export links SAK-30322: Fixed test SAK-30322: Export, print, Last updated links SAK-30322: Fix indentation SAK-30322: Fix indentation SAK-30322: Fix indentation --- .../citation/api/CitationCollectionOrder.java | 22 +++ .../citation/impl/BaseCitationService.java | 63 ++++++- .../citation/impl/BasicCitationService.java | 9 + .../impl/CitationListAccessServlet.java | 72 ++++++-- .../citation/impl/DbCitationService.java | 29 ++- .../impl/NestedCitationValidator.java | 17 +- .../impl/NestedCitationValidatorTest.java | 174 ++++++++++++++++++ .../citation/tool/CitationHelperAction.java | 6 +- .../tool/src/webapp/css/citations.css | 50 ++++- .../src/webapp/js/edit_nested_citations.js | 4 +- .../src/webapp/js/view_nested_citations.js | 30 +-- .../webapp/vm/citation/_nestableCitation.vm | 4 +- .../src/webapp/vm/citation/new_resource.vm | 10 + .../util/src/bundle/citations.properties | 7 +- .../src/bundle/citations_en_GB.properties | 1 + 15 files changed, 446 insertions(+), 52 deletions(-) create mode 100644 citations/citations-impl/impl/src/test/org/sakaiproject/citation/impl/NestedCitationValidatorTest.java diff --git a/citations/citations-api/api/src/java/org/sakaiproject/citation/api/CitationCollectionOrder.java b/citations/citations-api/api/src/java/org/sakaiproject/citation/api/CitationCollectionOrder.java index fd03789d20be..4b10f7ae5614 100644 --- a/citations/citations-api/api/src/java/org/sakaiproject/citation/api/CitationCollectionOrder.java +++ b/citations/citations-api/api/src/java/org/sakaiproject/citation/api/CitationCollectionOrder.java @@ -131,4 +131,26 @@ public int getCountCitations() { } return citationNo; } + + public CitationCollectionOrder copy(String collectionId) { + + CitationCollectionOrder citationCollectionOrder = new CitationCollectionOrder(); + + citationCollectionOrder.setCollectionId(collectionId); + + citationCollectionOrder.setChildren(this.getChildren()); + citationCollectionOrder.setCitationid(this.getCitationid()); + citationCollectionOrder.setLocation(this.getLocation()); + citationCollectionOrder.setSectiontype(this.getSectiontype()); + citationCollectionOrder.setValue(this.getValue()); + + return citationCollectionOrder; + } + + public CitationCollectionOrder copy(String collectionId, String citationId) { + + CitationCollectionOrder citationCollectionOrder = copy(collectionId); + citationCollectionOrder.setCitationid(citationId); + return citationCollectionOrder; + } } diff --git a/citations/citations-impl/impl/src/java/org/sakaiproject/citation/impl/BaseCitationService.java b/citations/citations-impl/impl/src/java/org/sakaiproject/citation/impl/BaseCitationService.java index 5fda7767700d..0ea3903349c3 100644 --- a/citations/citations-impl/impl/src/java/org/sakaiproject/citation/impl/BaseCitationService.java +++ b/citations/citations-impl/impl/src/java/org/sakaiproject/citation/impl/BaseCitationService.java @@ -2624,6 +2624,8 @@ public TitleComparator(boolean ascending) protected Map m_citations = new LinkedHashMap(); + protected List m_nestedCitationCollectionOrders = new ArrayList(); + protected Comparator m_comparator = DEFAULT_COMPARATOR; protected String m_sortOrder; @@ -2870,6 +2872,14 @@ public List getCitations() return citations; } + public List getNestedCitationCollectionOrders() { + return m_nestedCitationCollectionOrders; + } + + public void setNestedCitationCollectionOrders(List m_nestedCitationCollectionOrders) { + this.m_nestedCitationCollectionOrders = m_nestedCitationCollectionOrders; + } + public CitationCollection getCitations(Comparator c) { checkForUpdates(); @@ -3073,6 +3083,15 @@ public void saveCitation(Citation citation) save(citation); } + /* + * (non-Javadoc) + * + * @see org.sakaiproject.citation.api.CitationCollection#saveCitationCollectionOrder(org.sakaiproject.citation.api.CitationCollectionOrder) + */ + public void saveCitationCollectionOrder(CitationCollectionOrder citationCollectionOrder) + { + save(citationCollectionOrder); + } /** * * @param comparator @@ -3208,6 +3227,35 @@ protected void set(BasicCitationCollection other, boolean isTemporary) M_log.warn("copy(" + oldCitation.getId() + ") ==> " + newCitation.getId(), e); } } + + Iterator iterator = other.getNestedCitationCollectionOrders().iterator(); + while(iterator.hasNext()) { + CitationCollectionOrder citationCollectionOrder = (CitationCollectionOrder) iterator.next(); + if (citationCollectionOrder.isCitation()){ + try { + // copy the citation + CitationCollection collection = getCollection(citationCollectionOrder.getCollectionId()); + BasicCitation oldCitation = (BasicCitation) collection.getCitation(citationCollectionOrder.getCitationid()); + BasicCitation newCitation = new BasicCitation(); + newCitation.copy(oldCitation); + newCitation.m_temporary = isTemporary; + this.saveCitation(newCitation); + + // copy the citation's citationCollectionOrder + CitationCollectionOrder newCitationCollectionOrder = citationCollectionOrder.copy(this.getId(), newCitation.getId()); + this.saveCitationCollectionOrder(newCitationCollectionOrder); + + } catch (IdUnusedException e) { + M_log.warn("copying citationcollectionorder(" + citationCollectionOrder.getCitationid() + ") ==> " + citationCollectionOrder.getValue(), e); + } + } + else { + // copy the citationCollectionOrder + CitationCollectionOrder newCitationCollectionOrder = citationCollectionOrder.copy(this.getId()); + this.saveCitationCollectionOrder(newCitationCollectionOrder); + } + } + this.m_mostRecentUpdate = TimeService.newTime().getTime(); } @@ -3844,6 +3892,8 @@ protected interface Storage public void saveCitation(Citation edit); + public void saveCitationCollectionOrder(CitationCollectionOrder citationCollectionOrder); + public void saveCollection(CitationCollection collection); public void saveSection(CitationCollectionOrder citationCollectionOrder); @@ -5451,6 +5501,17 @@ public void save(Citation citation) this.m_storage.saveCitation(citation); } + + /* + * (non-Javadoc) + * + * @see org.sakaiproject.citation.api.CitationService#save(org.sakaiproject.citation.api.CitationCollectionOrder) + */ + public void save(CitationCollectionOrder citationCollectionOrder) + { + this.m_storage.saveCitationCollectionOrder(citationCollectionOrder); + } + public void setIdManager(IdManager idManager) { m_idManager = idManager; @@ -5650,7 +5711,7 @@ private void copyCitationCollection(Reference reference) { ContentResourceEdit edit = contentService.editResource(reference.getId()); String collectionId = new String(edit.getContent()); - CitationCollection oldCollection = getCollection(collectionId); + CitationCollection oldCollection = getUnnestedCitationCollection(collectionId); BasicCitationCollection newCollection = new BasicCitationCollection(); newCollection.copy((BasicCitationCollection) oldCollection); save(newCollection); diff --git a/citations/citations-impl/impl/src/java/org/sakaiproject/citation/impl/BasicCitationService.java b/citations/citations-impl/impl/src/java/org/sakaiproject/citation/impl/BasicCitationService.java index f1cdbc8e903e..ee629891156a 100644 --- a/citations/citations-impl/impl/src/java/org/sakaiproject/citation/impl/BasicCitationService.java +++ b/citations/citations-impl/impl/src/java/org/sakaiproject/citation/impl/BasicCitationService.java @@ -256,6 +256,15 @@ public void saveCitation(Citation edit) this.m_citations.put(edit.getId(), edit); } + + /* (non-Javadoc) + * @see org.sakaiproject.citation.impl.BaseCitationService.Storage#saveCitationCollectionOrder(org.sakaiproject.citation.api.CitationCollectionOrder) + */ + public void saveCitationCollectionOrder(CitationCollectionOrder citationCollectionOrder) + { + this.m_citationCollections.put(citationCollectionOrder.getLocation(), citationCollectionOrder); + } + /* (non-Javadoc) * @see org.sakaiproject.citation.impl.BaseCitationService.Storage#saveCollection(java.util.Collection) */ diff --git a/citations/citations-impl/impl/src/java/org/sakaiproject/citation/impl/CitationListAccessServlet.java b/citations/citations-impl/impl/src/java/org/sakaiproject/citation/impl/CitationListAccessServlet.java index 431a88d682fe..73a007069e23 100644 --- a/citations/citations-impl/impl/src/java/org/sakaiproject/citation/impl/CitationListAccessServlet.java +++ b/citations/citations-impl/impl/src/java/org/sakaiproject/citation/impl/CitationListAccessServlet.java @@ -24,6 +24,7 @@ import java.io.IOException; import java.io.OutputStream; import java.io.PrintWriter; +import java.text.SimpleDateFormat; import java.util.*; import javax.servlet.http.HttpServletRequest; @@ -41,19 +42,14 @@ import org.sakaiproject.component.cover.ServerConfigurationService; import org.sakaiproject.content.api.ContentResource; import org.sakaiproject.content.cover.ContentHostingService; -import org.sakaiproject.entity.api.EntityAccessOverloadException; -import org.sakaiproject.entity.api.EntityCopyrightException; -import org.sakaiproject.entity.api.EntityNotDefinedException; -import org.sakaiproject.entity.api.EntityPermissionException; -import org.sakaiproject.entity.api.HttpAccess; -import org.sakaiproject.entity.api.Reference; -import org.sakaiproject.entity.api.ResourceProperties; +import org.sakaiproject.entity.api.*; import org.sakaiproject.event.api.Event; import org.sakaiproject.event.cover.EventTrackingService; import org.sakaiproject.exception.IdUnusedException; import org.sakaiproject.exception.PermissionException; import org.sakaiproject.exception.ServerOverloadException; import org.sakaiproject.exception.TypeException; +import org.sakaiproject.tool.api.SessionManager; import org.sakaiproject.util.ResourceLoader; import org.sakaiproject.util.Validator; @@ -131,6 +127,8 @@ protected void handleExportRequest(HttpServletRequest req, HttpServletResponse r Reference ref, String format, String subtype) throws EntityNotDefinedException, EntityAccessOverloadException, EntityPermissionException { + SessionManager sessionManager = ComponentManager.get(SessionManager.class); + org.sakaiproject.content.api.ContentHostingService contentHostingService = ComponentManager.get(org.sakaiproject.content.api.ContentHostingService.class); if(! ContentHostingService.allowGetResource(req.getParameter("resourceId"))) { String url = (req.getRequestURL()).toString(); @@ -149,7 +147,25 @@ protected void handleExportRequest(HttpServletRequest req, HttpServletResponse r if(org.sakaiproject.citation.api.CitationService.RIS_FORMAT.equals(format)) { - String citationCollectionId = req.getParameter("citationCollectionId"); + String citationCollectionId = null; + ContentResource resource = null; + try { + resource = contentHostingService.getResource(req.getParameter("resourceId")); + citationCollectionId = new String(resource.getContent()); + } + catch (PermissionException e) { + throw new EntityPermissionException(sessionManager.getCurrentSessionUserId(), "handleExportRequest", ref.getReference()); + } + catch (IdUnusedException e) { + throw new EntityNotDefinedException(ref.getReference()); + } + catch (TypeException e) { + throw new IllegalStateException("Resource Mismatch: " + ref.getReference(), e); + } + catch (ServerOverloadException e){ + throw new EntityAccessOverloadException(ref.getReference()); + } + List citationIds = new java.util.ArrayList(); CitationCollection collection = null; try @@ -316,9 +332,26 @@ protected void handleViewRequest(HttpServletRequest req, HttpServletResponse res List citations = collection.getCitations(); String contentCollectionId = resource.getContainingCollection().getId(); - out.println("
\n\t
"); - out.println("\t
" + "

" + Validator.escapeHtml(title) + "

"); - out.println("\t
"); + + String exportParams = "?resourceDisplayName=" + resource.getProperties().getProperty(ResourceProperties.PROP_DISPLAY_NAME) + "&resourceId=" + resource.getId(); + String exportUrlAll = fullCollection.getUrl(org.sakaiproject.citation.api.CitationService.REF_TYPE_EXPORT_RIS_ALL) + exportParams; + String displayDate = null; + try { + displayDate = new SimpleDateFormat("dd/MM/yyyy", rb.getLocale()).format(properties.getDateProperty(ResourceProperties.PROP_MODIFIED_DATE)); + } catch (EntityPropertyNotDefinedException e) { + m_log.warn("CitationListAccessServlet.handleViewRequest() : Property name requested is not defined - for contentCollectionId" + contentCollectionId); + } catch (EntityPropertyTypeException e) { + m_log.warn("CitationListAccessServlet.handleViewRequest() : Named property found does not match the type of access requested - for contentCollectionId" + contentCollectionId); + } + + out.println("
\n\t
"); + out.println("\t
" + + "

" + + Validator.escapeHtml(title) + "

" + + "
" + + "Export" + "Print" + + "
Last updated: " + displayDate + "
" + "
" + "" + "
"); out.println("
"); if( introduction != null && !introduction.trim().equals("") ) { @@ -418,9 +451,9 @@ private void displayCitations(PrintWriter out, List citations, Citatio + "\" class=\"googleBookCover\">
"); out.println("\t\t\t\t
" + Validator.escapeHtml( citation.getCreator() ) + "
"); - out.println("\t\t\t\t
" + Validator.escapeHtml( citation.getSource() ) + "
"); + out.println("\t\t\t\t
" + Validator.escapeHtml( citation.getSource() ) + "
"); - out.println("\t\t\t
"); + out.println("\t\t\t
"); Schema schema = citation.getSchema(); if(schema == null) { @@ -478,7 +511,7 @@ private void displayCitations(PrintWriter out, List citations, Citatio } } } - out.println("\t\t\t
"); + out.println("\t\t\t
"); // rhs links out.println("\t\t\t
"); @@ -527,6 +560,9 @@ private void displayCitations(PrintWriter out, List citations, Citatio out.println("\t\t
"); out.println("\t\t\t"); + out.println("\t\t
"); + + out.println("\t\t"); fields = schema.getFields(); fieldIt = fields.iterator(); @@ -609,7 +645,7 @@ private void displayNestedSections(String title, String citationCollectionId, or CitationCollectionOrder nestedCollection = citationService.getNestedCollection(citationCollectionId); int nestedSectionsSize = nestedCollection.getChildren().size(); - out.println("
    "); + out.println("
      "); // h1 sections if (nestedSectionsSize > 0) { @@ -626,7 +662,7 @@ private void displayNestedSections(String title, String citationCollectionId, or (nestedSection.getChildren().size() > 0 ? "Citation View" : "") + "" + "
      " + - nestedSection.getValue() + (citationNo!=0 ? " (" + citationNo + " citations)" : "") + "
      "); + (nestedSection.getValue()!=null ? nestedSection.getValue() : "") + (citationNo!=0 ? " (" + citationNo + " citations)" : "") + ""); // h2 sections if (nestedSection.getChildren().size() > 0) { @@ -642,7 +678,7 @@ private void displayNestedSections(String title, String citationCollectionId, or out.println("
    1. " + "
      " + - h2Section.getValue() + "
      "); + (h2Section.getValue()!=null ? h2Section.getValue() : "") + ""); // h3 sections if (h2Section.getChildren().size() > 0) { @@ -658,7 +694,7 @@ private void displayNestedSections(String title, String citationCollectionId, or h3Section.getSectiontype() + "'>" + "
      " + - "
      " + h3Section.getValue() + "
      "); + "
      " + (h3Section.getValue()!=null ? h3Section.getValue() : "") + "
      "); // nested citations if (h3Section.getChildren().size() > 0) { diff --git a/citations/citations-impl/impl/src/java/org/sakaiproject/citation/impl/DbCitationService.java b/citations/citations-impl/impl/src/java/org/sakaiproject/citation/impl/DbCitationService.java index 70d1ad9c59bb..58807c5c0753 100644 --- a/citations/citations-impl/impl/src/java/org/sakaiproject/citation/impl/DbCitationService.java +++ b/citations/citations-impl/impl/src/java/org/sakaiproject/citation/impl/DbCitationService.java @@ -202,6 +202,11 @@ public void saveCitation(Citation edit) this.commitCitation(edit); } + public void saveCitationCollectionOrder(CitationCollectionOrder citationCollectionOrder) + { + this.commitCitationCollectionOrder(citationCollectionOrder); + } + public void saveCollection(CitationCollection collection) { this.commitCollection(collection); @@ -349,6 +354,23 @@ else if(value instanceof String) } } + /* (non-Javadoc) + * @see org.sakaiproject.citation.impl.BaseCitationService.Storage#commitCitationCollectionOrder(org.sakaiproject.citation.api.CitationCollectionOrder) + */ + protected void commitCitationCollectionOrder(CitationCollectionOrder citationCollectionOrder) + { + String orderStatement = "insert into " + m_collectionOrderTableName + " (COLLECTION_ID, CITATION_ID, LOCATION, SECTION_TYPE, VALUE) VALUES(?,?,?,?,?)"; + + Object[] orderFields = new Object[5]; + orderFields [0] = citationCollectionOrder.getCollectionId(); + orderFields [1] = citationCollectionOrder.getCitationid(); + orderFields [2] = citationCollectionOrder.getLocation(); + orderFields [3] = citationCollectionOrder.getSectiontype(); + orderFields [4] = citationCollectionOrder.getValue(); + + m_sqlService.dbWrite(orderStatement, orderFields); + } + /* (non-Javadoc) * @see org.sakaiproject.citation.impl.BaseCitationService.Storage#commitCitationCollectionOrder(org.sakaiproject.citation.api.CitationCollectionOrder) */ @@ -1218,6 +1240,9 @@ private void getCitationCollectionOrders(String collectionId, BasicCitationColle citation.setPosition(Integer.parseInt((String) orderTriple.getValue())); edit.add(citation); } + + List citationCollectionOrders = getNestedCollectionAsList(collectionId); + edit.setNestedCitationCollectionOrders(citationCollectionOrders); } private BasicCitationCollection getBasicCitationCollection(String collectionId) { @@ -1754,14 +1779,14 @@ public Object readSqlResultRecord(ResultSet result) collectionId = result.getString(1); citationId = result.getString(2); location = result.getInt(3); - sectionType = CitationCollectionOrder.SectionType.valueOf(result.getString(4)); + sectionType = result.getString(4)==null ? null : CitationCollectionOrder.SectionType.valueOf(result.getString(4)); value = result.getString(5); citationCollectionOrder = new CitationCollectionOrder(collectionId, citationId, location, sectionType, value); } catch (SQLException e) { - M_log.warn("TripleReader: problem reading CitationCollectionOrder from result: collectionId(" + collectionId + ") location(" + location + M_log.warn("CitationCollectionOrderReader: problem reading CitationCollectionOrder from result: collectionId(" + collectionId + ") location(" + location + ") sectionType(" + sectionType + ") value(" + value + ")"); return null; } diff --git a/citations/citations-impl/impl/src/java/org/sakaiproject/citation/impl/NestedCitationValidator.java b/citations/citations-impl/impl/src/java/org/sakaiproject/citation/impl/NestedCitationValidator.java index f56302ec0b5b..63aa83e4c60c 100644 --- a/citations/citations-impl/impl/src/java/org/sakaiproject/citation/impl/NestedCitationValidator.java +++ b/citations/citations-impl/impl/src/java/org/sakaiproject/citation/impl/NestedCitationValidator.java @@ -20,8 +20,6 @@ enum NESTED_CITATION_LIST { public CitationCollectionOrder.SectionType[] getAllowableTypes() { return new CitationCollectionOrder.SectionType[]{ CitationCollectionOrder.SectionType.HEADING1, - CitationCollectionOrder.SectionType.DESCRIPTION, - CitationCollectionOrder.SectionType.CITATION, null // 'Null' here refers to the unnested list }; } @@ -62,29 +60,36 @@ public CitationCollectionOrder.SectionType[] getAllowableTypes() { public boolean isValid(List citationCollectionOrders) { for (CitationCollectionOrder h1Section : citationCollectionOrders) { - if (!Arrays.asList(NESTED_CITATION_LIST.TOP_LEVEL.getAllowableTypes()).contains( + if (hasNullCitationIdAndSectionType(h1Section) || !Arrays.asList(NESTED_CITATION_LIST.TOP_LEVEL.getAllowableTypes()).contains( h1Section.getSectiontype())){ return false; } for (CitationCollectionOrder h2Section : h1Section.getChildren()) { - if (!Arrays.asList(NESTED_CITATION_LIST.HEADING1.getAllowableTypes()).contains( + if (hasNullCitationIdAndSectionType(h2Section) || !Arrays.asList(NESTED_CITATION_LIST.HEADING1.getAllowableTypes()).contains( h2Section.getSectiontype())){ return false; } for (CitationCollectionOrder h3Section : h2Section.getChildren()) { - if (!Arrays.asList(NESTED_CITATION_LIST.HEADING2.getAllowableTypes()).contains( + if (hasNullCitationIdAndSectionType(h3Section) || !Arrays.asList(NESTED_CITATION_LIST.HEADING2.getAllowableTypes()).contains( h3Section.getSectiontype())){ return false; } for (CitationCollectionOrder citation : h3Section.getChildren()) { - if (!Arrays.asList(NESTED_CITATION_LIST.HEADING3.getAllowableTypes()).contains( + if (hasNullCitationIdAndSectionType(citation) || !Arrays.asList(NESTED_CITATION_LIST.HEADING3.getAllowableTypes()).contains( citation.getSectiontype())){ return false; } + if (citation.getChildren()!=null && !citation.getChildren().isEmpty()){ + return false; + } } } } } return true; } + + private boolean hasNullCitationIdAndSectionType(CitationCollectionOrder citationCollectionOrder) { + return citationCollectionOrder.getCitationid()==null && citationCollectionOrder.getSectiontype()==null; + } } diff --git a/citations/citations-impl/impl/src/test/org/sakaiproject/citation/impl/NestedCitationValidatorTest.java b/citations/citations-impl/impl/src/test/org/sakaiproject/citation/impl/NestedCitationValidatorTest.java new file mode 100644 index 000000000000..004b23120be1 --- /dev/null +++ b/citations/citations-impl/impl/src/test/org/sakaiproject/citation/impl/NestedCitationValidatorTest.java @@ -0,0 +1,174 @@ +package org.sakaiproject.citation.impl; + +import org.sakaiproject.citation.api.*; + +import java.util.ArrayList; +import java.util.List; + +public class NestedCitationValidatorTest extends BaseCitationServiceSupport { + + private CitationValidator citationValidator = new NestedCitationValidator(); + + public void testValidList_H1() { + + List citationCollectionOrders = new ArrayList(); + CitationCollectionOrder h1CitationCollectionOrder = getH1(); + citationCollectionOrders.add(h1CitationCollectionOrder); + + boolean isValid = citationValidator.isValid(citationCollectionOrders); + assertTrue(isValid); + } + + public void testValidList_H1_Citation() { + + List citationCollectionOrders = new ArrayList(); + + // h1 with h2, h3, citation + CitationCollectionOrder citation = getCitation(); + CitationCollectionOrder h1 = getH1(); + h1.addChild(citation); + citationCollectionOrders.add(h1); + + boolean isValid = citationValidator.isValid(citationCollectionOrders); + assertTrue(isValid); + } + + public void testValidComplexList() { + + List citationCollectionOrders = new ArrayList(); + + // h1 with h2, h3, citation + CitationCollectionOrder citation = getCitation(); + CitationCollectionOrder h3 = getH3(); + h3.addChild(citation); + CitationCollectionOrder h2 = getH2(); + h2.addChild(h3); + CitationCollectionOrder h1 = getH1(); + h1.addChild(h2); + citationCollectionOrders.add(h1); + + // h1 with description and h2 in it ; h2 has h3 and citation in it + CitationCollectionOrder citation1 = getCitation(); + CitationCollectionOrder h3_1 = getH3(); + h3_1.addChild(citation1); + CitationCollectionOrder h2_1 = getH2(); + h2_1.addChild(h3_1); + CitationCollectionOrder h1Description = getDescription(); + CitationCollectionOrder h1_1 = getH1(); + h1_1.addChild(h2_1); + h1_1.addChild(h1Description); + citationCollectionOrders.add(h1_1); + + // h1 with h2, h3, citation + CitationCollectionOrder citation2 = getCitation(); + CitationCollectionOrder h1_2 = getH1(); + h1_2.addChild(citation2); + citationCollectionOrders.add(h1_2); + + + boolean isValid = citationValidator.isValid(citationCollectionOrders); + assertTrue(isValid); + } + + public void testInvalidList_Citation() { + + List citationCollectionOrders = new ArrayList(); + + // h1 with invalid null h2 + CitationCollectionOrder nullH2 = getNullCitationIdAndNullSectionType(); + citationCollectionOrders.add(nullH2); + CitationCollectionOrder h1 = getH1(); + h1.addChild(nullH2); + citationCollectionOrders.add(h1); + + boolean isValid = citationValidator.isValid(citationCollectionOrders); + assertFalse(isValid); + } + + public void testInvalidList_NullCitationIdAndNullSectionType() { + + List citationCollectionOrders = new ArrayList(); + + CitationCollectionOrder citation = getNullCitationIdAndNullSectionType(); + citationCollectionOrders.add(citation); + + boolean isValid = citationValidator.isValid(citationCollectionOrders); + assertFalse(isValid); + } + + public void testInvalidList_H1_H3() { + + List citationCollectionOrders = new ArrayList(); + + // h1 with h2, h3, citation + CitationCollectionOrder h3 = getH3(); + CitationCollectionOrder h1 = getH1(); + h1.addChild(h3); + + citationCollectionOrders.add(h1); + + boolean isValid = citationValidator.isValid(citationCollectionOrders); + assertFalse(isValid); + } + + public void testInvalidList_H1_H2_H3_Citation_H3() { + + List citationCollectionOrders = new ArrayList(); + + // h1 with h2, h3, citation + CitationCollectionOrder h3 = getH3(); + CitationCollectionOrder citation = getCitation(); + citation.addChild(h3); + CitationCollectionOrder h3_1 = getH3(); + h3_1.addChild(citation); + CitationCollectionOrder h2 = getH2(); + h2.addChild(h3_1); + CitationCollectionOrder h1 = getH1(); + h1.addChild(h2); + citationCollectionOrders.add(h1); + + boolean isValid = citationValidator.isValid(citationCollectionOrders); + assertFalse(isValid); + } + + private CitationCollectionOrder getH1() { + CitationCollectionOrder h1CitationCollectionOrder = new CitationCollectionOrder(); + h1CitationCollectionOrder.setSectiontype(CitationCollectionOrder.SectionType.HEADING1); + return h1CitationCollectionOrder; + } + + private CitationCollectionOrder getH2() { + CitationCollectionOrder h2CitationCollectionOrder = new CitationCollectionOrder(); + h2CitationCollectionOrder.setSectiontype(CitationCollectionOrder.SectionType.HEADING2); + return h2CitationCollectionOrder; + } + + private CitationCollectionOrder getH3() { + CitationCollectionOrder h3CitationCollectionOrder = new CitationCollectionOrder(); + h3CitationCollectionOrder.setSectiontype(CitationCollectionOrder.SectionType.HEADING3); + return h3CitationCollectionOrder; + } + + private CitationCollectionOrder getCitation() { + CitationCollectionOrder citation = new CitationCollectionOrder(); + citation.setSectiontype(CitationCollectionOrder.SectionType.CITATION); + return citation; + } + + private CitationCollectionOrder getNullCitationIdAndNullSectionType() { + CitationCollectionOrder citation = new CitationCollectionOrder(); + citation.setCollectionId("xxx"); + citation.setLocation(1); + return citation; + } + + private CitationCollectionOrder getDescription() { + CitationCollectionOrder description = new CitationCollectionOrder(); + description.setSectiontype(CitationCollectionOrder.SectionType.DESCRIPTION); + return description; + } + + private CitationCollectionOrder getUnnestedList() { + return new CitationCollectionOrder(); + } +} diff --git a/citations/citations-tool/tool/src/java/org/sakaiproject/citation/tool/CitationHelperAction.java b/citations/citations-tool/tool/src/java/org/sakaiproject/citation/tool/CitationHelperAction.java index bcca2f79d347..de4a7784ca46 100644 --- a/citations/citations-tool/tool/src/java/org/sakaiproject/citation/tool/CitationHelperAction.java +++ b/citations/citations-tool/tool/src/java/org/sakaiproject/citation/tool/CitationHelperAction.java @@ -2405,7 +2405,6 @@ public String buildNewResourcePanelContext(VelocityPortlet portlet, Context cont } catch (ServerOverloadException e) { logger.warn("ServerOverloadException geting props in buildNewResourcePanelContext() " + e); } - context.put(CITATION_ACTION, UPDATE_RESOURCE); } if(contentProperties == null) { @@ -2512,8 +2511,9 @@ public String buildNewResourcePanelContext(VelocityPortlet portlet, Context cont context.put( "collectionSize", new Integer( citationCollection.size() ) ); // export URLs - String exportUrlSel = citationCollection.getUrl(CitationService.REF_TYPE_EXPORT_RIS_SEL); - String exportUrlAll = citationCollection.getUrl(CitationService.REF_TYPE_EXPORT_RIS_ALL); + String exportParams = "?resourceDisplayName=" + resource.getProperties().getProperty(ResourceProperties.PROP_DISPLAY_NAME) + "&resourceId=" + resourceId; + String exportUrlSel = citationCollection.getUrl(CitationService.REF_TYPE_EXPORT_RIS_SEL) + exportParams; + String exportUrlAll = citationCollection.getUrl(CitationService.REF_TYPE_EXPORT_RIS_ALL) + exportParams; context.put("exportUrlSel", exportUrlSel); context.put("exportUrlAll", exportUrlAll); diff --git a/citations/citations-tool/tool/src/webapp/css/citations.css b/citations/citations-tool/tool/src/webapp/css/citations.css index 054e7790d732..ed8118c98765 100644 --- a/citations/citations-tool/tool/src/webapp/css/citations.css +++ b/citations/citations-tool/tool/src/webapp/css/citations.css @@ -50,6 +50,15 @@ padding:.3em 0; border-bottom:2px solid #ccc } +.floatLeft{ + float:left; +} +.floatRight{ + float:right; +} +.fullWidth{ + width:100%; +} .detailsDiv{ float:left; width:100%; @@ -64,7 +73,7 @@ margin: 1em; } table.lines tr:hover { - background-color: #FFF; + background-color: #e7e7e7; } table.lines tr:nth-child(odd), .citationDetails table.lines tr{ background: #eeeeee; @@ -112,10 +121,21 @@ ol.vertical { background-color: #E0DED9; padding: 10px; } +ol.viewCitations li { + color: #000; + display: block; + margin: 5px; +} ol.vertical li { color: #0088cc; display: block; - margin: 5px; +} +.availability { + margin-right: 15px; +} +.listWidth { + margin: auto; + max-width: 1024px; } ol.vertical li div.editor ol li, ol.vertical li div.editor ul li{ display:list-item; @@ -180,6 +200,25 @@ ol.serialization li div.sectionEditor.h1Editor:hover { .h1TopBar { width:100%; float:left; } +.banner { + float:left; + margin-top: 15px; + margin-left:15px; +} +.bannerLinks { + float:right; + margin-right:15px; + margin-top: 10px; +} +a.export { + padding-right:10px; +} +a.print { + padding-right:10px; +} +.lastUpdated { + float:right; +} .accordionArrow { cursor: pointer; float:left; @@ -220,6 +259,11 @@ ol.vertical li div.editor ol li, ol.vertical li div.editor ul li{ display:list-item; color: #000; } +ol.viewCitations li { + color: #000; + display: block; + margin: 5px; +} .h2NestedLevel, .h3NestedLevel, .h4NestedLevel { padding:5px; display: block; @@ -295,4 +339,4 @@ ol.nav ol.dropdown-menu li.placeholder::before { left: 10px; margin-top: -5px; top: 0; -} \ No newline at end of file +} diff --git a/citations/citations-tool/tool/src/webapp/js/edit_nested_citations.js b/citations/citations-tool/tool/src/webapp/js/edit_nested_citations.js index 90f8f775f166..5f2e8880f066 100644 --- a/citations/citations-tool/tool/src/webapp/js/edit_nested_citations.js +++ b/citations/citations-tool/tool/src/webapp/js/edit_nested_citations.js @@ -412,7 +412,7 @@ } var params = $('#newCitationListForm').serializeArray(); params.push({name:'addSectionHTML', value:$('#' + this.id.replace(TOGGLE, SECTION_INLINE_EDITOR)).get(0).innerHTML}); - params.push({name:'sectionType', value:$('#' + this.id.replace(TOGGLE, SECTION_INLINE_EDITOR)).parent().attr('data-sectiontype')}); + params.push({name:'sectionType', value:$(this).parent().parent().attr('data-sectiontype')}); params.push({name:'locationId', value:this.id.replace(TOGGLE, "")}); ajaxPost(actionUrl, params, true); @@ -571,7 +571,7 @@ $('.h1NestedLevel li[data-sectiontype="HEADING1"] > div > div[id^=sectionInlineEditor]').click(function() { $(this).parent().parent().find('ol').slideToggle(); - var image = $('#' + this.id.replace('sectionInlineEditor', 'toggleImg')).get(0); + var image = $('#' + this.id.replace('linkClick', 'toggleImg')).get(0); if( image.src.indexOf("/library/image/sakai/white-arrow-right.gif")!=-1 ) { image.src = "/library/image/sakai/white-arrow-down.gif"; diff --git a/citations/citations-tool/tool/src/webapp/js/view_nested_citations.js b/citations/citations-tool/tool/src/webapp/js/view_nested_citations.js index d1ff8de40b69..530a4a98b629 100644 --- a/citations/citations-tool/tool/src/webapp/js/view_nested_citations.js +++ b/citations/citations-tool/tool/src/webapp/js/view_nested_citations.js @@ -2,22 +2,24 @@ function addAccordionFunctionality() { - // h1 level collapse - $('.h1NestedLevel ol').each(function () { - $(this).hide(); - }); + // collapse h1 level if not on print view + if(window.location.href.indexOf("printView") == -1) { + $('.h1NestedLevel ol').each(function () { + $(this).hide(); + }); - // expand all on click - $('.h1NestedLevel li[data-sectiontype="HEADING1"] > div[id^=linkClick]').click(function() { - $(this).parent().find('ol').slideToggle(); - var image = $('#' + this.id.replace('linkClick', 'toggleImg')).get(0); + // expand all on click + $('.h1NestedLevel li[data-sectiontype="HEADING1"] > div[id^=linkClick]').click(function() { + $(this).parent().find('ol').slideToggle(); + var image = $('#' + this.id.replace('linkClick', 'toggleImg')).get(0); - if( image.src.indexOf("/library/image/sakai/white-arrow-right.gif")!=-1 ) { - image.src = "/library/image/sakai/white-arrow-down.gif"; - } else { - image.src = "/library/image/sakai/white-arrow-right.gif"; - } - }); + if( image.src.indexOf("/library/image/sakai/white-arrow-right.gif")!=-1 ) { + image.src = "/library/image/sakai/white-arrow-down.gif"; + } else { + image.src = "/library/image/sakai/white-arrow-right.gif"; + } + }); + } } $(document).ready(function(){ diff --git a/citations/citations-tool/tool/src/webapp/vm/citation/_nestableCitation.vm b/citations/citations-tool/tool/src/webapp/vm/citation/_nestableCitation.vm index ff78e8d0b904..0366987860cb 100644 --- a/citations/citations-tool/tool/src/webapp/vm/citation/_nestableCitation.vm +++ b/citations/citations-tool/tool/src/webapp/vm/citation/_nestableCitation.vm @@ -34,5 +34,7 @@ $tlang.getString("action.edit") | $tlang.getString("action.remove") + | + $tlang.getString("export.citation") - + \ No newline at end of file diff --git a/citations/citations-tool/tool/src/webapp/vm/citation/new_resource.vm b/citations/citations-tool/tool/src/webapp/vm/citation/new_resource.vm index f19b64e566b1..5d644164413f 100644 --- a/citations/citations-tool/tool/src/webapp/vm/citation/new_resource.vm +++ b/citations/citations-tool/tool/src/webapp/vm/citation/new_resource.vm @@ -161,6 +161,16 @@ span.searchTargetLink { margin-right:50px; }
    2. + + #if( $!exportUrlAll ) +
    3. + + $tlang.getString("resource.export") + + +
    4. + #end