NotesWhat is notes.io?

Notes brand slogan

Notes - notes.io

//$Id$
package com.manageengine.ela.webclient.ember.common.request.handlers;

import java.util.*;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import com.adventnet.ds.query.Column;
import com.adventnet.ds.query.Criteria;
import com.adventnet.ds.query.QueryConstants;
import com.adventnet.ds.query.SortColumn;
import com.manageengine.ela.server.common.client.datasource.ClientDBDataFormatter;
import com.manageengine.ela.server.common.response.BaseStatusCode;
import com.manageengine.ela.server.common.response.PredefinedStatusCodes;

/**
* Created by Stenal P Jolly
*/
public class EmberTableRequestHandler extends BaseJSONTableRequestHandler
{

private int limit = 0;
private int offset = 1;

private boolean isAutoComplete = false;
private Integer searchType = null;

private ArrayList<Column> columnArrayList = null;

public EmberTableRequestHandler(JSONObject request, Locale locale) throws BaseStatusCode
{
super(request,locale);
try
{
isAutoComplete = reqJsonObject.has("IS_AUTOCOMPLETE") && reqJsonObject.getBoolean("IS_AUTOCOMPLETE"); // No I18N
searchType = reqJsonObject.has("SEARCH_TYPE") ? reqJsonObject.getInt("SEARCH_TYPE") : null; // No I18N

if (isAutoComplete)
{
limit = 7;
offset = 1;
}
else
{
if (reqJsonObject.has("LIMIT"))
{
limit = reqJsonObject.getInt("LIMIT"); // No I18N
}
if (reqJsonObject.has("STARTFROM"))
{
offset = reqJsonObject.getInt("STARTFROM"); // No I18N
}
}

if (reqJsonObject.has("PARTIAL")) // No I18N
{
JSONArray partialList = reqJsonObject.getJSONArray("PARTIAL"); // No I18N
columnArrayList = new ArrayList<>();
for(int index = 0 ; index < partialList.length() ; index++)
{
JSONObject jsonObject = partialList.getJSONObject(index);
String tableName = jsonObject.getString("TABLE_NAME"); // No I18N
JSONArray columnArray = jsonObject.getJSONArray("COLUMN_LIST");
for(int colIndex = 0 ; colIndex < columnArray.length() ; colIndex++)
{
Column column = Column.getColumn(tableName , columnArray.getString(colIndex));
columnArrayList.add(column);
}

}
}

}
catch (JSONException e)
{
throw BaseStatusCode.getBaseStatusCode(PredefinedStatusCodes.INVALID_PARAMETERS);
}
}

/* sql columns APIs */
public ArrayList<Column> getSQLColumnList() throws BaseStatusCode
{
if (columnArrayList == null)
{
return ClientDBDataFormatter.getInstence().getColumnList(tableUniqueIdentifier);
}
else
{
return ClientDBDataFormatter.getInstence().getColumnList(tableUniqueIdentifier , columnArrayList);
}
}

public Map<String , ArrayList<Column>> getAllSQLColumns() throws BaseStatusCode
{
if (columnArrayList == null)
{
return ClientDBDataFormatter.getInstence().getAllColumns(tableUniqueIdentifier);
}
else
{
return ClientDBDataFormatter.getInstence().getAllColumns(tableUniqueIdentifier , columnArrayList);
}
}

public List<?> getCustomValues(String customCriteriaKey , String tableName , String columnName , boolean isMultivalue)
{
try
{
if (containsParameter(customCriteriaKey))
{
if (isMultivalue)
{
String[] lisValue = getString(customCriteriaKey).split(",");
return Arrays.asList(lisValue);
}
else
{
String value = getString(customCriteriaKey);
return Arrays.asList(value);
}
}

}
catch (Exception exp)
{
exp.printStackTrace();
}
return null;

}

public int getLimit()
{
return limit;
}

public void setLimit(int limit)
{
if(limit < 0)
{
limit = 0;
}
this.limit = limit;
}

public void setOffset(int offset)
{
if (offset < 0)
{
offset = 0;
}
this.offset = offset;
}

public int getOffset()
{
return offset;
}

public boolean isAutoComplete()
{
return isAutoComplete;
}

private static String[] getStringArray(JSONArray jsonArray)
{
String[] stringArray = null;
if (jsonArray != null)
{
int length = jsonArray.length();
stringArray = new String[length];
for(int i = 0 ; i < length ; i++)
{
stringArray[i] = jsonArray.optString(i);
}
}
return stringArray;
}

/* SQL custom APIs */
public Criteria getSQLOUFilterCriteria(String tableName , String columnName) throws BaseStatusCode
{
Criteria criteria = null;
try
{
JSONArray filterListJsonArray = (reqJsonObject.isNull("OU_CHILD_FILTER")) ? null : reqJsonObject.getJSONArray("OU_CHILD_FILTER"); // No I18N
if (filterListJsonArray != null && filterListJsonArray.length() > 0)
{
criteria = new Criteria(Column.getColumn(tableName , columnName) , getStringArray(filterListJsonArray) , QueryConstants.IN);
}
filterListJsonArray = (reqJsonObject.isNull("OU_PARENT_FILTER")) ? null : reqJsonObject.getJSONArray("OU_PARENT_FILTER"); // No I18N
if (filterListJsonArray != null && filterListJsonArray.length() > 0)
{
for(int index = 0 ; index < filterListJsonArray.length() ; index++)
{
if (criteria == null)
{
criteria = new Criteria(Column.getColumn(tableName , columnName) , "*" + filterListJsonArray.getString(index) , QueryConstants.LIKE);
}
else
{
criteria = criteria.or(new Criteria(Column.getColumn(tableName , columnName) , "*" + filterListJsonArray.getString(index) , QueryConstants.LIKE));
}
}

}

}
catch (Exception exp)
{
throw BaseStatusCode.getBaseStatusCode(PredefinedStatusCodes.INVALID_PARAMETERS);
}
return criteria;
}

public Column getSQLSearchByColumn() throws JSONException
{
String searchColumn = !(reqJsonObject.isNull("SEARCHBY")) ? reqJsonObject.getString("SEARCHBY") : null; // No I18N
String searchTable = !(reqJsonObject.isNull("SEARCH_TABLE")) ? reqJsonObject.getString("SEARCH_TABLE") : null; // No I18N
if (searchColumn != null && searchTable != null)
{
return Column.getColumn(searchTable , searchColumn);
}
else
{
return null;
}
}

public String getSQLSearchActionValue() throws JSONException
{
return reqJsonObject.optString("SEARCH_VALUE" , null); // No I18N
}
@Deprecated
public boolean isSearchRequest() throws JSONException
{
//TODO get flag from client side
return reqJsonObject.has("SEARCH_VALUE"); // No I18N
}

public List<SortColumn> getSQLSortColumns() throws JSONException // List is provided for future expansion
{
ArrayList<SortColumn> sortColumns = new ArrayList<SortColumn>();
/* Optional Json Parameters */
String sortBy = (reqJsonObject.has("SORTBY")) ? reqJsonObject.getString("SORTBY") : null; // No I18N
String sortByTable = (reqJsonObject.has("SORTBY_TABLE")) ? reqJsonObject.getString("SORTBY_TABLE") : null; // No I18N
Boolean isAscending = !reqJsonObject.has("SORTTYPE") || reqJsonObject.getString("SORTTYPE").equals("1"); // No I18N

if (sortBy != null && sortByTable != null && !sortBy.equals("") && !sortByTable.equals(""))
{
SortColumn sortColumn = new SortColumn(Column.getColumn(sortByTable , sortBy) , isAscending);
sortColumns.add(sortColumn);
}
return sortColumns;
}

public Criteria getSQLSearchCriteria() throws JSONException
{
String searchColumn = (reqJsonObject.has("SEARCHBY")) ? reqJsonObject.getString("SEARCHBY") : null; // No I18N
String searchTable = (reqJsonObject.has("SEARCH_TABLE")) ? reqJsonObject.getString("SEARCH_TABLE") : null; // No I18N
String searchValue = (reqJsonObject.has("SEARCH_VALUE")) ? reqJsonObject.getString("SEARCH_VALUE") : null; // No I18N
if (searchColumn != null && searchTable != null)
{
return (new Criteria(Column.getColumn(searchTable , searchColumn) , searchValue , QueryConstants.CONTAINS));
}
return null;
}

public Criteria getSQLCustomCriteria(String customCriteriaKey , String tableName , String columnName , boolean isMultivalue)
{
try
{
if (containsParameter(customCriteriaKey))
{
if (isMultivalue)
{
String[] lisValue = getString(customCriteriaKey).split(",");
return new Criteria(Column.getColumn(tableName , columnName) , lisValue , QueryConstants.IN);
}
else
{
String value = getString(customCriteriaKey);
return new Criteria(Column.getColumn(tableName , columnName) , value , QueryConstants.EQUAL);
}
}

}
catch (Exception exp)
{
exp.printStackTrace();
}
return null;

}

public Integer getoptSearchType(Integer defaultType)
{
if(searchType == null)
{
return defaultType;
}
return searchType;
}


}
     
 
what is notes.io
 

Notes.io is a web-based application for taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000 notes created and continuing...

With notes.io;

  • * You can take a note from anywhere and any device with internet connection.
  • * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
  • * You can quickly share your contents without website, blog and e-mail.
  • * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
  • * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.

Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.

Easy: Notes.io doesn’t require installation. Just write and share note!

Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )

Free: Notes.io works for 12 years and has been free since the day it was started.


You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;


Email: [email protected]

Twitter: http://twitter.com/notesio

Instagram: http://instagram.com/notes.io

Facebook: http://facebook.com/notesio



Regards;
Notes.io Team

     
 
Shortened Note Link
 
 
Looding Image
 
     
 
Long File
 
 

For written notes was greater than 18KB Unable to shorten.

To be smaller than 18KB, please organize your notes, or sign in.