BrightSide Workbench Full Report + Source Code
org.turro.elephant.direct.AbstractDirectQuery Class Referenceabstract
Inheritance diagram for org.turro.elephant.direct.AbstractDirectQuery:
Collaboration diagram for org.turro.elephant.direct.AbstractDirectQuery:

Public Member Functions

String createQueryURL (String values)
 
boolean itsMe (String id)
 
boolean myTurn (HttpServletRequest request)
 
void execute (ServletContext context, HttpServletRequest request, HttpServletResponse response)
 
void execute (IConstructor constructor)
 

Protected Member Functions

abstract String getIdentifier ()
 
abstract List doSearch (KeyValueMap map, String query)
 
String generateJson (String rootElement, String itemElement, List results)
 
JsonObjectBuilder createJsonItem (String itemElement, Object item)
 
void writeJsonResponse (HttpServletResponse response, String json)
 

Detailed Description

Author
Lluis TurrĂ³ Cutiller lluis.nosp@m.@tur.nosp@m.ro.or.nosp@m.g

Definition at line 40 of file AbstractDirectQuery.java.

Member Function Documentation

◆ createJsonItem()

JsonObjectBuilder org.turro.elephant.direct.AbstractDirectQuery.createJsonItem ( String  itemElement,
Object  item 
)
protected

Definition at line 92 of file AbstractDirectQuery.java.

92  {
93  if(item instanceof String) {
94  return Json.createObjectBuilder().add(itemElement, (String) item);
95  } else if(item instanceof Double) {
96  return Json.createObjectBuilder().add(itemElement, (Double) item);
97  } else if(item instanceof Integer) {
98  return Json.createObjectBuilder().add(itemElement, (Integer) item);
99  } else if(item instanceof Boolean) {
100  return Json.createObjectBuilder().add(itemElement, (Boolean) item);
101  } else {
102  return Json.createObjectBuilder().add(itemElement, item.toString());
103  }
104  }
Here is the caller graph for this function:

◆ createQueryURL()

String org.turro.elephant.direct.AbstractDirectQuery.createQueryURL ( String  values)

Definition at line 42 of file AbstractDirectQuery.java.

42  {
43  return ElephantContext.getRootWebPath() +
44  DirectContents.DIRECT_CONTENT_PATH + getIdentifier() +
45  "?" + Actions.createRightNowAction("ds=true;" + values) + "&q={query}";
46  }

◆ doSearch()

abstract List org.turro.elephant.direct.AbstractDirectQuery.doSearch ( KeyValueMap  map,
String  query 
)
abstractprotected

Reimplemented in org.turro.dossier.search.DossierDirectQuery.

Here is the caller graph for this function:

◆ execute() [1/2]

void org.turro.elephant.direct.AbstractDirectQuery.execute ( IConstructor  constructor)

Definition at line 65 of file AbstractDirectQuery.java.

65  {
66  KeyValueMap map = Actions.isRightNowAction(constructor) ?
67  Actions.getRightNowAction(constructor) :
68  Actions.getAction(constructor);
69  if(map != null && "true".equals(map.get("ds"))) {
70  if(map.containsKey("sroot") && map.containsKey("sitem")) {
71  writeJsonResponse(constructor.getResponse(),
72  generateJson(map.get("sroot"), map.get("sitem"), doSearch(map, constructor.getParameter("q"))));
73  } else {
74  doSearch(map, constructor.getParameter("q"));
75  }
76  }
77  }
String generateJson(String rootElement, String itemElement, List results)
void writeJsonResponse(HttpServletResponse response, String json)
abstract List doSearch(KeyValueMap map, String query)
Here is the call graph for this function:

◆ execute() [2/2]

void org.turro.elephant.direct.AbstractDirectQuery.execute ( ServletContext  context,
HttpServletRequest  request,
HttpServletResponse  response 
)

Implements org.turro.elephant.direct.IDirectContent.

Definition at line 61 of file AbstractDirectQuery.java.

61  {
62  execute(ElephantContext.getConstructor(request, response));
63  }
void execute(ServletContext context, HttpServletRequest request, HttpServletResponse response)
Here is the call graph for this function:

◆ generateJson()

String org.turro.elephant.direct.AbstractDirectQuery.generateJson ( String  rootElement,
String  itemElement,
List  results 
)
protected

Definition at line 84 of file AbstractDirectQuery.java.

84  {
85  JsonObjectBuilder builder = Json.createObjectBuilder();
86  JsonArrayBuilder array = Json.createArrayBuilder();
87  results.forEach(i -> array.add(createJsonItem(itemElement, i)));
88  builder.add(rootElement, array);
89  return builder.build().toString();
90  }
JsonObjectBuilder createJsonItem(String itemElement, Object item)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ getIdentifier()

abstract String org.turro.elephant.direct.AbstractDirectQuery.getIdentifier ( )
abstractprotected

Reimplemented in org.turro.dossier.search.DossierDirectQuery.

Here is the caller graph for this function:

◆ itsMe()

boolean org.turro.elephant.direct.AbstractDirectQuery.itsMe ( String  id)

Implements org.turro.elephant.direct.IDirectContent.

Definition at line 51 of file AbstractDirectQuery.java.

51  {
52  return getIdentifier().equals(id);
53  }
Here is the call graph for this function:

◆ myTurn()

boolean org.turro.elephant.direct.AbstractDirectQuery.myTurn ( HttpServletRequest  request)

Implements org.turro.elephant.direct.IDirectContent.

Definition at line 56 of file AbstractDirectQuery.java.

56  {
57  return DirectContents.isYourTurn(request, getIdentifier());
58  }
Here is the call graph for this function:

◆ writeJsonResponse()

void org.turro.elephant.direct.AbstractDirectQuery.writeJsonResponse ( HttpServletResponse  response,
String  json 
)
protected

Definition at line 106 of file AbstractDirectQuery.java.

106  {
107  try {
108  response.setContentType("application/json");
109  //response.setCharacterEncoding(ElephantContext.getEncoding());
110  response.getWriter().write(json);
111  } catch (IOException ex) {
112  Logger.getLogger(AbstractDirectQuery.class.getName()).log(Level.SEVERE, null, ex);
113  }
114  }
Here is the caller graph for this function:

The documentation for this class was generated from the following file: