Skip to content

Commit

Permalink
Merge pull request #7 from nicolasmoreau/master
Browse files Browse the repository at this point in the history
Guided query interface
  • Loading branch information
nicolasmoreau committed Apr 15, 2015
2 parents 1a580b1 + 54cd729 commit c8b1343
Show file tree
Hide file tree
Showing 54 changed files with 1,348 additions and 232 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

public class RedirectPage {
public static final String QUERY="query";
public static final String QUERYTREE="queryTree";
public static final String PREVIEW="preview";
public static final String QUERY_LOG="queryLog";
public static final String SPECIES="species";
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package org.vamdc.portal.session.preview;

import java.util.List;

import org.vamdc.portal.entity.query.HttpHeadResponse;
import org.vamdc.portal.entity.security.User;
import org.vamdc.portal.session.queryBuilder.FormHolder;
import org.vamdc.portal.session.queryBuilder.QueryData;
import org.vamdc.portal.session.queryLog.QueryLog;

public interface PersistableQueryInterface {
public List<HttpHeadResponse> getNodesResponse();
public User getUser();
public QueryLog getQueryLog();
public QueryData getQueryData();
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ public class PreviewManager implements Serializable{
private long startTime;

public void initiate(){

if (nodeFutureResponses.size()>0)
return;

Expand Down Expand Up @@ -153,7 +154,10 @@ public void clear(){

public String refine(){
clear();
return RedirectPage.QUERY;
if(!queryData.isGuidedQuery())
return RedirectPage.QUERY;
else
return RedirectPage.QUERYTREE;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@
import org.jboss.seam.log.Log;
import org.vamdc.portal.RedirectPage;
import org.vamdc.portal.entity.query.HttpHeadResponse;
import org.vamdc.portal.entity.query.HttpHeadResponse.Response;
import org.vamdc.portal.entity.query.Query;
import org.vamdc.portal.entity.security.User;
import org.vamdc.portal.session.preview.PersistableQueryInterface;
import org.vamdc.portal.session.preview.PreviewManager;
import org.vamdc.portal.session.queryBuilder.forms.AtomsForm;
import org.vamdc.portal.session.queryBuilder.forms.BranchesForm;
Expand All @@ -40,7 +41,7 @@
*/
@Name("query")
@Scope(ScopeType.EVENT)
public class QueryController {
public class QueryController implements PersistableQueryInterface{

@Logger
Log log;
Expand All @@ -60,11 +61,8 @@ public class QueryController {

@End
public String saveQuery(){

if (queryData.isValid()){
persistQuery();


persistQuery();
conversation.endAndRedirect();
log.info("Save action");
return RedirectPage.QUERY_LOG;
Expand All @@ -75,11 +73,12 @@ public String saveQuery(){
}

private void persistQuery() {
Query query = constructQuery();
QueryPersister p = new QueryPersister(this);
Query query = p.constructQuery();//constructQuery();
queryLog.save(query,queryData.getEditQueryId());
}

private Query constructQuery(){
/*private Query constructQuery(){
Query result=null;
if (queryData.getEditQueryId()!=null)
result = queryLog.getQuery(queryData.getEditQueryId());
Expand All @@ -103,16 +102,17 @@ private List<HttpHeadResponse> selectRespondedNodes() {
responses.add(response);
}
return responses;
}
}*/



public String preview(){

if (queryData.isValid()){
return RedirectPage.PREVIEW;
}else
}else{
return RedirectPage.QUERY;
}
}

public String edit(String queryID){
Expand Down Expand Up @@ -168,5 +168,24 @@ public void addFormUtil(){
queryData.addForm(new UtilForm());
}

@Override
public List<HttpHeadResponse> getNodesResponse() {
return preview.getNodes();
}

@Override
public User getUser() {
return auth.getUser();
}

@Override
public QueryLog getQueryLog(){
return this.queryLog;
}

@Override
public QueryData getQueryData(){
return this.queryData;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import org.vamdc.tapservice.vss2.RestrictExpression;
import org.vamdc.tapservice.vss2.VSSParser;


@Name("queryData")
@Scope(ScopeType.CONVERSATION)
public class QueryData implements FormHolder,Serializable{
Expand All @@ -39,6 +40,7 @@ public class QueryData implements FormHolder,Serializable{
//All forms and lists are serialized explicitly
private transient Collection<Form> forms;
private transient List<Form> formsList;
private transient List<Form> unsortedFormsList;

//Species-related forms
private transient Collection<SpeciesForm> speciesForms;
Expand All @@ -54,6 +56,9 @@ public class QueryData implements FormHolder,Serializable{
private transient Collection<Restrictable> activeKeywords;
private transient Collection<String> activeNodes;

private Integer speciesFormPosition;
private Boolean guidedQuery = false;

@In(create=true) private transient RegistryFacade registryFacade;

public QueryData(){
Expand All @@ -63,6 +68,7 @@ public QueryData(){
private void initCollections(){
formCounts=Collections.synchronizedMap(new TreeMap<Integer,Integer>());
forms=Collections.synchronizedSet(new TreeSet<Form>(new Order()));
unsortedFormsList = Collections.synchronizedList(new ArrayList<Form>());
formsList = Collections.synchronizedList(new ArrayList<Form>());
speciesForms=Collections.synchronizedSet(new TreeSet<SpeciesForm>(new Order()));
request = EnumSet.noneOf(Requestable.class);
Expand Down Expand Up @@ -124,8 +130,7 @@ private Collection<Restrictable> getKeywordsFromForms(){
for (Form form:getForms()){
result.addAll(form.getKeywords());
}
return result;

return result;
}

private Collection<Restrictable> getKeywordsFromQuery(String query){
Expand All @@ -148,12 +153,11 @@ private Collection<Restrictable> getKeywordsFromQuery(String query){
}



public String getQueryString(){
if (isUserModified())
return customQueryString;
return QueryGenerator.buildQueryString(request,formsList);
}
}


private boolean isUserModified(){
Expand All @@ -172,6 +176,10 @@ public List<Form> getForms(){
return formsList;
}

public List<Form> getUnsortedForms(){
return this.unsortedFormsList;
}

public Collection<SpeciesForm> getSpeciesForms(){
return new ArrayList<SpeciesForm>(speciesForms);
}
Expand Down Expand Up @@ -205,13 +213,36 @@ private boolean quickAddForm(Form form){
form.setQueryData(this);
forms.add(form);
formCounts.put(form.getOrder(), getFormTypeCount(form)+1);

if(form.getOrder() == Order.GuidedSpeciesType)
this.speciesFormPosition = forms.size()-1;

if (form instanceof SpeciesForm)
speciesForms.add((SpeciesForm) form);
else
unsortedFormsList.add(form);

return true;
}
return false;
}

public List<Form> getOrderedGuidedForm(){
if(this.getSpeciesForms().size() > 0 && this.speciesFormPosition != null){
List<Form> result = new ArrayList<Form>();
for(Form f : this.unsortedFormsList){
result.add(f);
}
int i = this.speciesFormPosition;
for(Form f : this.speciesForms){
result.add(i+1, f);
i++;
}
return result;
}else
return this.unsortedFormsList;
}

public Integer getFormTypeCount(Form form){
Integer count;
if ((count=formCounts.get(form.getOrder()))!=null){
Expand All @@ -231,13 +262,15 @@ public void deleteForm(Form form){
}
formCounts.put(form.getOrder(), getFormTypeCount(form)-1);
forms.remove(form);
unsortedFormsList.remove(form);
if (form.getOrder()<Order.SPECIES_LIMIT)
speciesForms.remove(form);
speciesForms.remove(form);

rebuildLists();
}

public String getComments() { return comments; }
public void setComments(String comments) { this.comments = comments; }
public void setComments(String comments) {this.comments = comments; }

public String getEditQueryId() { return editedQueryId; }
public void setEditQueryId(String editQueryId) { this.editedQueryId = editQueryId; }
Expand Down Expand Up @@ -291,4 +324,13 @@ public void setCustomQueryString(String customQueryString) {
this.customQueryString = customQueryString;
}

public void setGuidedQuery(Boolean guidedQuery){
this.guidedQuery = guidedQuery;
}

public Boolean isGuidedQuery(){
return this.guidedQuery;
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public int compare(Form o1, Form o2) {
}

public static String getFormsQuery(Collection<Form> forms){

SortedSet<Form> sorted = new TreeSet<Form>(new NewOrder());
sorted.addAll(forms);

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package org.vamdc.portal.session.queryBuilder;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;


import org.vamdc.portal.entity.query.HttpHeadResponse;
import org.vamdc.portal.entity.query.Query;
import org.vamdc.portal.entity.query.HttpHeadResponse.Response;
import org.vamdc.portal.session.preview.PersistableQueryInterface;


public class QueryPersister {
private PersistableQueryInterface queryManager;

public QueryPersister(PersistableQueryInterface queryManager){
this.queryManager = queryManager;
}

public Query constructQuery(){
Query result=null;
if (queryManager.getQueryData().getEditQueryId() !=null)
result = queryManager.getQueryLog().getQuery(queryManager.getQueryData().getEditQueryId());
else
result = new Query();
result.setComments(queryManager.getQueryData().getComments());
result.setQueryString(queryManager.getQueryData().getQueryString());
result.setResponses(selectRespondedNodes());
result.setUser(queryManager.getUser());
result.setDate(new Date());
return result;
}

private List<HttpHeadResponse> selectRespondedNodes() {
ArrayList<HttpHeadResponse> responses = new ArrayList<HttpHeadResponse>();

for (HttpHeadResponse response:queryManager.getNodesResponse()){
if (response.getStatus()==Response.OK || response.getStatus()==Response.TRUNCATED)
responses.add(response);
}
return responses;
}


}

This file was deleted.

Loading

0 comments on commit c8b1343

Please sign in to comment.