NotesWhat is notes.io?

Notes brand slogan

Notes - notes.io

//$Id$
package com.manageengine.ela.server.common.client.structure;

import com.adventnet.ds.query.*;
import com.adventnet.la.util.PersistenceDBUtil;
import com.adventnet.la.util.ProductBundle;
import com.adventnet.persistence.DataAccessException;
import com.adventnet.persistence.DataObject;
import com.adventnet.persistence.Row;
import com.manageengine.ela.server.common.response.BaseStatusCode;
import com.manageengine.ela.server.common.response.PredefinedStatusCodes;
import com.manageengine.ela.server.common.util.JSONUtil;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.util.Iterator;

import static com.manageengine.ela.server.common.database.constants.TableNameConstants.ELA_EMBER_COLUMN_CONFIGURATIONS;
import static com.manageengine.ela.server.common.database.constants.TableNameConstants.ELA_EMBER_TABLE_DETAILS;

/**
* @author Pavish Kumar R
*/

public class BaseTableStructure implements ClientStructureModel
{

@Override
public JSONObject retrieveStructure(TableUniqueIdentifier tableIdentifier) throws BaseStatusCode
{
try
{
//Table default query
SelectQuery query = getTableStrucutureQuery(tableIdentifier);

//DataObject
DataObject dataObject = PersistenceDBUtil.getPersistence().get(query);

//Table details
JSONObject tableDef = processDataObject(tableIdentifier, dataObject);

JSONObject tableDetails = new JSONObject();
tableDetails.put(ClientTableStructure.TABLE_PROPERTIES, tableDef);

JSONObject columnDef = new JSONObject();

//Column defn
JSONArray columndefn = getColumnDefinition(tableIdentifier, dataObject);
columnDef.put("COLUMNDEFINITION", columndefn); //No I18N

//Custom columns
JSONArray customColumns = getAllColumns(tableIdentifier,dataObject);
columnDef.put("CUSTOMCOLUMNS", customColumns); //No I18N

tableDetails.put(ClientTableStructure.COLUMN_PROPERTIES, columnDef);

return tableDetails;
}
catch (BaseStatusCode baseStatusCode)
{
throw baseStatusCode;
}
catch (DataAccessException e)
{
throw BaseStatusCode.getBaseStatusCode(PredefinedStatusCodes.SQL_PROBLEM);
}
catch (JSONException e)
{
throw BaseStatusCode.getBaseStatusCode(PredefinedStatusCodes.UNDEFINED);
}
}

@Override
public JSONObject handleStructureModifications(TableUniqueIdentifier identifier, JSONObject structure) throws BaseStatusCode {
return structure;
}

@Override
public void customizeColumns(TableUniqueIdentifier identifier, String[] columns, boolean makeVisible) throws BaseStatusCode
{
try
{
UpdateQuery updateQuery = new UpdateQueryImpl(ELA_EMBER_COLUMN_CONFIGURATIONS);
Criteria criteria = new Criteria(Column.getColumn(ELA_EMBER_COLUMN_CONFIGURATIONS , "TABLE_ID") , identifier.getTableId() , QueryConstants.EQUAL);
criteria = criteria.and(Column.getColumn(ELA_EMBER_COLUMN_CONFIGURATIONS , "DISPLAY_KEY") , columns , QueryConstants.IN); // No I18N
updateQuery.setCriteria(criteria);
updateQuery.setUpdateColumn("COLUMN_DISPLAY_TYPE" , makeVisible? "VISIBLE":"HIDDEN");
PersistenceDBUtil.getPersistence().update(updateQuery);
}
catch (DataAccessException e)
{
throw BaseStatusCode.getBaseStatusCode(PredefinedStatusCodes.SQL_PROBLEM);
}
}

protected SelectQuery getTableStrucutureQuery(TableUniqueIdentifier tableIdentifier) throws DataAccessException
{
Criteria parent = new Criteria(Column.getColumn(ELA_EMBER_TABLE_DETAILS, "TABLEID"), tableIdentifier.getTableId(), QueryConstants.EQUAL);
SelectQueryImpl tableDetailsQuery = new SelectQueryImpl(Table.getTable(ELA_EMBER_TABLE_DETAILS));
tableDetailsQuery.addSelectColumn(Column.getColumn(null, "*"));
tableDetailsQuery.addSortColumn(new SortColumn(Column.getColumn(ELA_EMBER_COLUMN_CONFIGURATIONS, "INDEX"), true));
tableDetailsQuery.setCriteria(parent);
tableDetailsQuery.addJoin(new Join(Table.getTable(ELA_EMBER_TABLE_DETAILS), Table.getTable(ELA_EMBER_COLUMN_CONFIGURATIONS), new String[]{"TABLEID"}, new String[]{"TABLEID"},Join.INNER_JOIN)); //No I18N
return tableDetailsQuery;
}

protected JSONObject processDataObject(TableUniqueIdentifier tableIdentifier, DataObject dobj) throws DataAccessException, JSONException
{
return JSONUtil.rowToJSON(dobj.getRow(ELA_EMBER_TABLE_DETAILS));
}

protected JSONArray getColumnDefinition(TableUniqueIdentifier tableIdentifier, DataObject dobj) throws JSONException, DataAccessException, BaseStatusCode
{
JSONArray columnDefinitionArray = new JSONArray();
Criteria child = new Criteria(Column.getColumn(ELA_EMBER_COLUMN_CONFIGURATIONS, "COLUMN_DISPLAY_TYPE"), new String[]{"VISIBLE", "FIXED"}, QueryConstants.IN);
Iterator<?> rowIterator = dobj.getRows(ELA_EMBER_COLUMN_CONFIGURATIONS, child);
Boolean isInserted = false;

while (rowIterator.hasNext())
{
Row row = (Row) rowIterator.next();
Float index = (Float) row.get("INDEX"); //No I18N
if(!isInserted && index >= getCustomColumnInsertionIndex())
{
JSONArray additionalCols = customizeColumnDefinition(tableIdentifier, dobj);
if(additionalCols != null)
{
for(int i=0;i<additionalCols.length();i++)
{
columnDefinitionArray.put(additionalCols.getJSONObject(i));
}
}
isInserted = true;
}
columnDefinitionArray.put(JSONUtil.rowToJSON(row));
}

if(!isInserted)
{
JSONArray additionalCols = customizeColumnDefinition(tableIdentifier, dobj);
if(additionalCols != null)
{
for(int i=0;i<additionalCols.length();i++)
{
columnDefinitionArray.put(additionalCols.get(i));
}
}
}

return columnDefinitionArray;
}

protected JSONArray getAllColumns(TableUniqueIdentifier tableIdentifier, DataObject dobj) throws DataAccessException, BaseStatusCode, JSONException
{
Criteria child = new Criteria(Column.getColumn(ELA_EMBER_COLUMN_CONFIGURATIONS, "COLUMN_DISPLAY_TYPE"), new String[]{"VISIBLE", "HIDDEN"}, QueryConstants.IN);
child = child.and(new Criteria(Column.getColumn(ELA_EMBER_COLUMN_CONFIGURATIONS, "ISINDICATOR"), 0, QueryConstants.EQUAL));
Iterator rowIterator = dobj.getRows(ELA_EMBER_COLUMN_CONFIGURATIONS, child);
JSONArray columnDisplayName = new JSONArray();
while (rowIterator.hasNext())
{
Row row = (Row) rowIterator.next();
String colName = (String)row.get("DISPLAY_KEY"); //No I18N
Long colId = (Long)row.get("CONFIG_ID"); //No I18N
JSONObject colOBj = new JSONObject();
colOBj.put("DISPLAY_NAME", ProductBundle.getInstance().getString(tableIdentifier.getLocale(),colName));
colOBj.put("CONFIG_ID", colId);
columnDisplayName.put(colOBj);
}
return columnDisplayName;
}

protected JSONArray customizeColumnDefinition(TableUniqueIdentifier tableIdentifier, DataObject dataObject) throws BaseStatusCode
{
return null;
}

protected JSONArray customizeFullColumnList(TableUniqueIdentifier tableIdentifier, DataObject dataObject) throws BaseStatusCode
{
return null;
}

protected Float getCustomColumnInsertionIndex()
{
return 0F;
}

}
     
 
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.