changeset 173:aa564b1b5e1f public_by_author

publicByAuthor feature ui for selecting texts ready. actual changing of public state not yet implemented.
author Robert Casties <casties@mpiwg-berlin.mpg.de>
date Wed, 06 Jun 2018 21:01:05 +0200
parents 3475b8bea550
children 4961820373d0
files src/main/java/de/mpiwg/itgroup/ismi/browse/AbstractEntityRepositoryBean.java src/main/java/de/mpiwg/itgroup/ismi/browse/FullEntityRepositoryBean.java src/main/java/de/mpiwg/itgroup/ismi/merge/PublicByAuthorBean.java src/main/java/de/mpiwg/itgroup/ismi/util/guiComponents/DataPaginator.java src/main/webapp/clean/components/publicFindAuthor.xhtml src/main/webapp/clean/components/publicShowSubjects.xhtml src/main/webapp/clean/publicByAuthor.xhtml
diffstat 7 files changed, 178 insertions(+), 43 deletions(-) [+]
line wrap: on
line diff
--- a/src/main/java/de/mpiwg/itgroup/ismi/browse/AbstractEntityRepositoryBean.java	Mon Jun 04 20:17:04 2018 +0200
+++ b/src/main/java/de/mpiwg/itgroup/ismi/browse/AbstractEntityRepositoryBean.java	Wed Jun 06 21:01:05 2018 +0200
@@ -46,6 +46,7 @@
 
 	protected String personName;
 	protected String personNameTranslit;
+	protected String personMamsNr;
 
 	protected String codexIdentifier;
 	
@@ -113,37 +114,37 @@
 	public String advancedFirst() {
 		this.advancedPaginator.first();
 		this.updateAdvancedEntities();
-		return GOTO_ENTITY_REPOSITORY;
+		return null; //GOTO_ENTITY_REPOSITORY;
 	}
 
 	public String advancedLast() {
 		this.advancedPaginator.last();
 		this.updateAdvancedEntities();
-		return GOTO_ENTITY_REPOSITORY;
+		return null; //GOTO_ENTITY_REPOSITORY;
 	}
 
 	public String advancedFastForward() {
 		this.advancedPaginator.fastForward();
 		this.updateAdvancedEntities();
-		return GOTO_ENTITY_REPOSITORY;
+		return null; //GOTO_ENTITY_REPOSITORY;
 	}
 
 	public String advancedFastRewind() {
 		this.advancedPaginator.fastRewind();
 		this.updateAdvancedEntities();
-		return GOTO_ENTITY_REPOSITORY;
+		return null; //GOTO_ENTITY_REPOSITORY;
 	}
 
 	public String advancedPrevious() {
 		this.advancedPaginator.previous();
 		this.updateAdvancedEntities();
-		return GOTO_ENTITY_REPOSITORY;
+		return null; //GOTO_ENTITY_REPOSITORY;
 	}
 
 	public String advancedNext() {
 		this.advancedPaginator.next();
 		this.updateAdvancedEntities();
-		return GOTO_ENTITY_REPOSITORY;
+		return null; //GOTO_ENTITY_REPOSITORY;
 	}
 	
 	public void reset(){
@@ -289,6 +290,9 @@
             if (StringUtils.isNotEmpty(this.personNameTranslit)) {
                 filterList.add(new AttributeFilter("name_translit", this.personNameTranslit, PERSON));
             }
+            if (StringUtils.isNotEmpty(this.personMamsNr)) {
+                filterList.add(new AttributeFilter("mams_number", this.personMamsNr, PERSON));
+            }
         }
         
         /*
@@ -431,7 +435,21 @@
 		this.personNameTranslit = personNameTranslit;
 	}
 
-	public String getObjectClass() {
+	/**
+     * @return the personMamsNr
+     */
+    public String getPersonMamsNr() {
+        return personMamsNr;
+    }
+
+    /**
+     * @param personMamsNr the personMamsNr to set
+     */
+    public void setPersonMamsNr(String personMamsNr) {
+        this.personMamsNr = personMamsNr;
+    }
+
+    public String getObjectClass() {
 		return objectClass;
 	}
 
--- a/src/main/java/de/mpiwg/itgroup/ismi/browse/FullEntityRepositoryBean.java	Mon Jun 04 20:17:04 2018 +0200
+++ b/src/main/java/de/mpiwg/itgroup/ismi/browse/FullEntityRepositoryBean.java	Wed Jun 06 21:01:05 2018 +0200
@@ -1,9 +1,13 @@
 package de.mpiwg.itgroup.ismi.browse;
 
 import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.List;
 
 import org.apache.commons.lang.StringUtils;
 import org.mpi.openmind.cache.WrapperService;
+import org.mpi.openmind.repository.bo.Attribute;
 import org.mpi.openmind.repository.bo.Entity;
 
 /**
@@ -16,8 +20,15 @@
 
     private static final long serialVersionUID = 8022526185079972610L;
 
-    /* (non-Javadoc)
-     * @see de.mpiwg.itgroup.ismi.browse.AbstractEntityRepositoryBean#updateAdvancedEntities()
+    protected String sortAttributeName;
+
+    protected boolean sortAttributeNumerically = false;
+
+    /*
+     * (non-Javadoc)
+     * 
+     * @see de.mpiwg.itgroup.ismi.browse.AbstractEntityRepositoryBean#
+     * updateAdvancedEntities()
      */
     @Override
     protected void updateAdvancedEntities() {
@@ -45,11 +56,121 @@
         WrapperService store = getWrapper();
         for (Entity ent : this.currentEntities) {
             if (ent.isLightweight()) {
-               store.getEntityContent(ent);
+                store.getEntityContent(ent);
             }
         }
     }
 
-    
-    
+    public String actionSortByAttributes() {
+        try {
+            this.sortByAttributes();
+        } catch (Exception e) {
+            printInternalError(e);
+            logger.error(e.getMessage(), e);
+        }
+        return GOTO_ENTITY_REPOSITORY;
+    }
+
+    public void sortByAttributes() throws Exception {
+        this.resultMode = MODE_ADVANCED;
+        this.setPage("");
+        this.entities = new ArrayList<Entity>();
+        this.currentEntities = new ArrayList<Entity>();
+
+        this.resultSummaryMsg = "";
+
+        /*
+         * run search and sort result (by attribute)
+         */
+        List<Entity> resultList = getWrapper().getEntitiesByDef(this.objectClass);
+        // sort List (by ownvalue)
+        Collections.sort(resultList,
+                getEntityAttributeComparator(this.sortAttributeName, this.sortAttributeNumerically));
+        this.entities = resultList;
+
+        if (resultList.size() > 0) {
+            this.resultSummaryMsg = resultList.size() + " items were found!";
+            this.advancedPaginator.setCurrentPage(0);
+            int entitiesCount = this.entities.size();
+            this.advancedPaginator.resetNumberOfPages(entitiesCount);
+            this.updateAdvancedEntities();
+        } else {
+            this.resultSummaryMsg = "No items were found!";
+        }
+    }
+
+    public Comparator<Entity> getEntityAttributeComparator(final String attName, final boolean numerically) {
+        return new Comparator<Entity>() {
+            @Override
+            public int compare(Entity e1, Entity e2) {
+                if (e1.isLightweight()) {
+                    e1 = getWrapper().getEntityContent(e1);
+                }
+                Attribute att1 = e1.getAttributeByName(attName);
+                if (e2.isLightweight()) {
+                    e2 = getWrapper().getEntityContent(e2);
+                }
+                Attribute att2 = e2.getAttributeByName(attName);
+                if (att1 == null && att2 != null) {
+                    return 1;
+                } else if (att1 != null && att2 == null) {
+                    return -1;
+                } else if (att1 == null && att2 == null) {
+                    return 0;
+                }
+                if (numerically) {
+                    Integer a1 = null;
+                    Integer a2 = null;
+                    try {
+                        a1 = Integer.parseInt(att1.getValue());
+                    } catch (Exception e) {
+                    }
+                    try {
+                        a2 = Integer.parseInt(att2.getValue());
+                    } catch (Exception e) {
+                    }
+                    if (a1 == null && a2 != null) {
+                        return 1;
+                    } else if (a1 != null && a2 == null) {
+                        return -1;
+                    } else if (a1 == null && a2 == null) {
+                        return 0;
+                    }
+                   return Integer.compare(a1, a2);
+                } else {
+                    return att1.getValue().compareTo(att2.getValue());
+                }
+            }
+        };
+    }
+
+    /**
+     * @return the sortAttributeName
+     */
+    public String getSortAttributeName() {
+        return sortAttributeName;
+    }
+
+    /**
+     * @param sortAttributeName
+     *            the sortAttributeName to set
+     */
+    public void setSortAttributeName(String sortAttributeName) {
+        this.sortAttributeName = sortAttributeName;
+    }
+
+    /**
+     * @return the sortAttributeNumerical
+     */
+    public boolean isSortAttributeNumerically() {
+        return sortAttributeNumerically;
+    }
+
+    /**
+     * @param sortAttributeNumerical
+     *            the sortAttributeNumerical to set
+     */
+    public void setSortAttributeNumerically(boolean sortAttributeNumerical) {
+        this.sortAttributeNumerically = sortAttributeNumerical;
+    }
 }
--- a/src/main/java/de/mpiwg/itgroup/ismi/merge/PublicByAuthorBean.java	Mon Jun 04 20:17:04 2018 +0200
+++ b/src/main/java/de/mpiwg/itgroup/ismi/merge/PublicByAuthorBean.java	Wed Jun 06 21:01:05 2018 +0200
@@ -33,7 +33,7 @@
     protected Map<String,List<String>> subjectParents;
 
 	
-	private EntityRepositoryBean browseBean;
+	private FullEntityRepositoryBean browseBean;
 	
 	
 	public PublicByAuthorBean(){
@@ -152,23 +152,21 @@
        selectedPersonId = entity.getId();
        setSelectedPersonById();
        // switch tab
-       getSessionBean().setSelectedPublicByAuthorTab("02");
+       getSessionBean().setSelectedPublicByAuthorTab("sub");
        return null;
 	}
 	
-    public String actionSearch(){
-		this.search();
-		return null;
+	public void actionAllAuthors() {
+	    browseBean.setObjectClass(PERSON);
+	    browseBean.setSortAttributeName("mams_number");
+	    browseBean.setSortAttributeNumerically(true);
+	    try {
+            browseBean.sortByAttributes();
+        } catch (Exception e) {
+            logger.error(e);
+        }
 	}
 	
-	public void search(){
-		long start = System.currentTimeMillis();
-		
-		long end = System.currentTimeMillis();
-		logger.info("execution time [ms] = " + (end - start));
-	}
-
-	
 	/**
 	 * @return the findAuthorName
 	 */
--- a/src/main/java/de/mpiwg/itgroup/ismi/util/guiComponents/DataPaginator.java	Mon Jun 04 20:17:04 2018 +0200
+++ b/src/main/java/de/mpiwg/itgroup/ismi/util/guiComponents/DataPaginator.java	Wed Jun 06 21:01:05 2018 +0200
@@ -4,7 +4,7 @@
 
 public class DataPaginator {
 	/* This should be parameters or properties stored somewhere */
-	private int itemsPerPage = 10;
+	private int itemsPerPage = 20;
 	private int rewindFastForwardBy = 10;
 	
 	private int currentPage;
--- a/src/main/webapp/clean/components/publicFindAuthor.xhtml	Mon Jun 04 20:17:04 2018 +0200
+++ b/src/main/webapp/clean/components/publicFindAuthor.xhtml	Wed Jun 06 21:01:05 2018 +0200
@@ -13,19 +13,20 @@
             
 
 
-		<h:panelGrid columns="2" styleClass="displayPanel"
+		<h:panelGrid columns="3" styleClass="displayPanel"
 			columnClasses="displayPanelColumn01,displayPanelColumn02">
 
+            <a4j:commandButton value="show all authors"
+                actionListener="#{Session.publicByAuthor.actionAllAuthors}"
+                render="selectPersonPanel" />
+            <h:outputText/>
+            <h:outputText/>
+
 			<h:panelGrid columns="1">
 				<h:outputLabel value="Person name" />
 				<h:outputLabel value="(name_translit)" />
 			</h:panelGrid>
 			<h:inputText value="#{Session.publicByAuthor.browseBean.personNameTranslit}" />
-
-            <a4j:commandButton value="show all"
-                actionListener="#{Session.publicByAuthor.listenerAllAuthorSearch}"
-                render="selectPersonPanel" />
-
 			<a4j:commandButton value="search"
 				actionListener="#{Session.publicByAuthor.browseBean.actionSearchByAttributes}"
 				render="selectPersonPanel" />
@@ -93,7 +94,7 @@
 				</h:panelGroup>
 			</h:column>
 
-			<rich:dataTable id="advancedDataTable" rows="10"
+			<rich:dataTable id="advancedDataTable" rows="30"
 				value="#{Session.publicByAuthor.browseBean.currentEntities}"
 				rendered="#{!empty Session.publicByAuthor.browseBean.currentEntities}"
 				var="entity" styleClass="rsPanel" columnClasses="rsPanelColumn">
--- a/src/main/webapp/clean/components/publicShowSubjects.xhtml	Mon Jun 04 20:17:04 2018 +0200
+++ b/src/main/webapp/clean/components/publicShowSubjects.xhtml	Wed Jun 06 21:01:05 2018 +0200
@@ -12,15 +12,13 @@
 
 		<!-- <h:outputStylesheet name="/css/ismi-db/repository.css" /> -->
 
-
+        <h2 style="color:black; text-align:left">Author: #{Session.publicByAuthor.selectedPerson.ownValue}"</h2>
 
 		<h:panelGrid columns="3" styleClass="displayPanel"
 			columnClasses="displayPanelColumn01,displayPanelColumn02">
 
 			<h:outputLabel value="Person ID" />
 			<h:inputText value="#{Session.publicByAuthor.selectedPersonId}" />
-			<h:outputText
-				value="#{Session.publicByAuthor.selectedPerson.ownValue}" />
 
 			<a4j:commandButton value="search"
 				actionListener="#{Session.publicByAuthor.listenerAuthorIdSearch}"
--- a/src/main/webapp/clean/publicByAuthor.xhtml	Mon Jun 04 20:17:04 2018 +0200
+++ b/src/main/webapp/clean/publicByAuthor.xhtml	Wed Jun 06 21:01:05 2018 +0200
@@ -21,14 +21,13 @@
 				styleClass="mainPanel">
 
 				<rich:tabPanel id="tabPanel"
-					activeItem="#{Session.selectedPublicByAuthorTab}"
-					itemChangeListener="#{Session.listenerPublicByAuthorTabChange}">
+					activeItem="#{Session.selectedPublicByAuthorTab}">
 				
-					<rich:tab header="Find Author" name="01">
-						<ui:include src="components/publicFindAuthor.xhtml" />
-					</rich:tab>
-					
-                    <rich:tab header="Select by Subject" name="02">
+                    <rich:tab header="Find Author" name="src">
+                        <ui:include src="components/publicFindAuthor.xhtml" />
+                    </rich:tab>
+                    
+                    <rich:tab header="Select by Subject" name="sub">
                         <ui:include src="components/publicShowSubjects.xhtml" />
                     </rich:tab>
 				</rich:tabPanel>