Skip to content
This repository has been archived by the owner on Feb 20, 2024. It is now read-only.

Commit

Permalink
Replaced personList and creation of DIVs with personListString and cr…
Browse files Browse the repository at this point in the history
…eation of DIVs in Java to speed up DOM creation. (#151)

Check during creation of personList required, as some user data seems to be valid but not set leading to NullPointerExceptions. This could be avoided with a data cleanup;
  • Loading branch information
konradlang committed Oct 21, 2022
1 parent 0dda697 commit 61edd20
Show file tree
Hide file tree
Showing 4 changed files with 93 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,12 @@ public class OwnerQueriesDetailBean implements Serializable {


private int unreadQueryCount = 0;
@Deprecated
private List<Person> personList;
/**
* String to hold contact persons in DIVs
*/
private String personStringDIVsForRequest = "";

private final HashMap<String, List<CollectionLifeCycleStatus>> sortedCollections = new HashMap<>();

Expand Down Expand Up @@ -325,7 +330,10 @@ public String initialize() {
}
}

setPersonListForRequest(config, selectedQuery.getId());
// setPersonListForRequest(config, selectedQuery.getId());
// Set the PersonDIVsString - setPersonListForRequest is deprecated once this works
setPersonStringDIVsForRequest(config, selectedQuery.getId());


/*
* Initialize Lifecycle Status
Expand All @@ -345,6 +353,7 @@ public String initialize() {
return null;
}

@Deprecated
private void setPersonListForRequest(Config config, Integer queryId) {
personList = DbUtil.getPersonsContactsForRequest(config, queryId);
}
Expand Down Expand Up @@ -1088,10 +1097,41 @@ public void setUnreadPrivateNegotiationCount(int unreadPrivateNegotiationCount)
this.unreadPrivateNegotiationCount = unreadPrivateNegotiationCount;
}

/**
* Set the contact persons in a String with DIVs to speed up the DOM creation
*
* @param config
* @param queryId
*/
private void setPersonStringDIVsForRequest( Config config, Integer queryId) {
// ensure the personStringDIVsForRequest is empty
personStringDIVsForRequest = new String("");

// get the personList from the database
personList = DbUtil.getPersonsContactsForRequest(config, queryId);

logger.debug ( "personStringDIVsForRequest: " + personStringDIVsForRequest);
for( de.samply.bbmri.negotiator.jooq.tables.pojos.Person person : personList) {
if( person.getAuthName() != null) {
personStringDIVsForRequest = personStringDIVsForRequest.concat("<div class=\"col-xs-3\"><i class=\"glyphicon glyphicon-user\"/></i>");
personStringDIVsForRequest = personStringDIVsForRequest.concat(person.getAuthName());
personStringDIVsForRequest = personStringDIVsForRequest.concat("</div>");
}
}

}
/**
* Returns the previously set person list as DIVs to speed up DOM creation
* @return
*/
public String getPersonStringDIVsForRequest() {
return personStringDIVsForRequest;
}
@Deprecated
public List<Person> getPersonList() {
return personList;
}

@Deprecated
public void setPersonList(List<Person> personList) {
this.personList = personList;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,8 +187,13 @@ public int getNumQueries() {
private int unreadCommentCount = 0;
private int privateNegotiationCount;
private int unreadPrivateNegotiationCount = 0;
@Deprecated
private List<Person> personList;

/**
* String to hold contact persons in DIVs
*/
private String personStringDIVsForRequest = "";
private int unreadQueryCount = 0;
/**
* Lifecycle Collection Data (Form, Structure)
Expand Down Expand Up @@ -304,8 +309,9 @@ public String loadSelectedQueryDetails() {
logger.debug("loadSelectedQueryDetails-21: " + LocalDateTime.now());
}
logger.debug("loadSelectedQueryDetails-21.1-setPersonListForRequest: " + LocalDateTime.now());
// This will be set once the button is hit ...
//setPersonListForRequest(config, selectedQuery.getId());
// setPersonListForRequest(config, selectedQuery.getId());
// Set the PersonDIVsString - setPersonListForRequest is deprecated once this works
setPersonStringDIVsForRequest(config, selectedQuery.getId());
logger.debug("loadSelectedQueryDetails-22: " + LocalDateTime.now());
/*
* Initialize Lifecycle Status
Expand Down Expand Up @@ -333,6 +339,37 @@ public String loadSelectedQueryDetails() {
return null;
}

/**
* Set the contact persons in a String with DIVs to speed up the DOM creation
*
* @param config
* @param queryId
*/
private void setPersonStringDIVsForRequest( Config config, Integer queryId) {
// ensure the personStringDIVsForRequest is empty
personStringDIVsForRequest = new String("");

// get the personList from the database
personList = DbUtil.getPersonsContactsForRequest(config, queryId);

for( de.samply.bbmri.negotiator.jooq.tables.pojos.Person person : personList) {
if( person.getAuthName() != null) {
personStringDIVsForRequest = personStringDIVsForRequest.concat("<div class=\"col-xs-3\"><i class=\"glyphicon glyphicon-user\"/></i>");
personStringDIVsForRequest = personStringDIVsForRequest.concat(person.getAuthName());
personStringDIVsForRequest = personStringDIVsForRequest.concat("</div>");
}
}
}

/**
* Returns the previously set person list as DIVs to speed up DOM creation
* @return
*/
private String getPersonStringDIVsForRequest() {
return personStringDIVsForRequest;
}

@Deprecated
private void setPersonListForRequest(Config config, Integer queryId) {
personList = DbUtil.getPersonsContactsForRequest(config, queryId);
}
Expand Down
6 changes: 6 additions & 0 deletions src/main/webapp/owner/detail.xhtml
Original file line number Diff line number Diff line change
Expand Up @@ -413,10 +413,16 @@
<div id="demo" class="collapse">
<div class="container">
<div class="row">
<!-- Create DIV in code and only show the string - should speed up significantly:
https://howchoo.com/code/learn-the-slow-and-fast-way-to-append-elements-to-the-dom
-->
<h:outputText escape="false" value="#{ownerQueriesDetailBean.getPersonStringDIVsForRequest()}" />
<!--
<ui:repeat value="#{ownerQueriesDetailBean.personList}"
var="person">
<div class="col-xs-3"><i class="glyphicon glyphicon-user"/>#{person.authName}</div>
</ui:repeat>
-->
</div></div>
</div>
</div>
Expand Down
6 changes: 6 additions & 0 deletions src/main/webapp/researcher/detail.xhtml
Original file line number Diff line number Diff line change
Expand Up @@ -532,10 +532,16 @@
<div id="demo" class="collapse">
<div class="container">
<div class="row">
<!-- Create DIV in code and only show the string - should speed up significantly:
https://howchoo.com/code/learn-the-slow-and-fast-way-to-append-elements-to-the-dom
-->
#{researcherQueriesDetailBean.getPersonStringDIVsForRequest()}
<!--
<ui:repeat value="#{researcherQueriesDetailBean.getPersonList()}"
var="person">
<div class="col-xs-3"><i class="glyphicon glyphicon-user"/>#{person.authName}</div>
</ui:repeat>
-->
</div></div>
</div>
</div>
Expand Down

0 comments on commit 61edd20

Please sign in to comment.