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.DataObject;
import com.adventnet.persistence.Row;
import com.manageengine.ela.server.common.cache.ServerDetailsBean;
import com.manageengine.ela.server.common.database.actions.DataBaseReqestProcessor;
import com.manageengine.ela.server.common.ember.tables.EmberTableIdConstants;
import com.manageengine.ela.server.common.response.BaseStatusCode;
import com.manageengine.ela.server.common.response.PredefinedStatusCodes;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.util.Locale;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.locks.ReadWriteLock;
import java.util.concurrent.locks.ReentrantReadWriteLock;

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 praveen.aj
*
*/
public class ClientTableStructure
{
private static final Map<String, JSONObject> TABLESTRUCTURE_CACHE = new ConcurrentHashMap<String, JSONObject>();
private static final Map<String, ClientStructureModel> TABLE_STRUCTURE_MODEL_CONTAINER = new ConcurrentHashMap<>();

public static final String PSEUDO_COLUMNS = "pseudo_columns"; //No I18N
public static final String ORIGINAL_COLUMNS = "original_columns"; //No I18N

public static final String COLUMN_PROPERTIES = "column_properties"; //No I18N
public static final String TABLE_PROPERTIES = "table_properties"; //No I18N

public static final String COLUMN_DEFINITION = "COLUMNDEFINITION"; //No I18N
public static final String CUSTOM_COLUMNS = "CUSTOMCOLUMNS"; //No I18N

public static final String TABLE_ID = "TABLE_ID"; //No I18N

private static final ReadWriteLock RWLOCK = new ReentrantReadWriteLock(true);

public static JSONObject getTableStructure(TableUniqueIdentifier tableIdentifier)
{
JSONObject tableStructureJsonObject = new JSONObject();
try
{
JSONObject structure = getColumnConfigurationFromCache(tableIdentifier);
structure = new JSONObject(structure.toString());
ClientStructureModel model = TABLE_STRUCTURE_MODEL_CONTAINER.get(tableIdentifier.getUniqueId());
if(model != null)
{
model.handleStructureModifications(tableIdentifier,structure);
}
tableStructureJsonObject.put(TABLE_ID, tableIdentifier.getTableId());
getLocaleTranslatedColumns(structure, tableIdentifier.getLocale());
tableStructureJsonObject.put("structure", structure); //No I18N
}
catch(Exception exp)
{
exp.printStackTrace();
}
return tableStructureJsonObject;
}

public static JSONArray getColumnDefinition(TableUniqueIdentifier tableIdentifier) throws BaseStatusCode
{
JSONObject structure = getColumnConfigurationFromCache(tableIdentifier);
getLocaleTranslatedColumns(structure,tableIdentifier.getLocale());
try
{
if(!structure.isNull("COLUMNDEFINITION")) //No I18N
{
return structure.getJSONArray("COLUMNDEFINITION"); //No I18N
}
}
catch(Exception exp)
{
throw BaseStatusCode.getBaseStatusCode(PredefinedStatusCodes.UNDEFINED);
}
return null;
}

public static JSONObject getTableProperties(TableUniqueIdentifier tableIdentifier) throws BaseStatusCode
{
JSONObject tableProperties = new JSONObject();
try
{
JSONObject tableCache = getTableDetailsFromCache(tableIdentifier);
tableProperties = tableCache.getJSONObject(TABLE_PROPERTIES);
}
catch(JSONException exp)
{
throw BaseStatusCode.getBaseStatusCode(PredefinedStatusCodes.INVALID_PARAMETERS);
}
return tableProperties;
}

public static void removeTableStructureFromCache(TableUniqueIdentifier tableIdentifier) throws BaseStatusCode
{
TABLESTRUCTURE_CACHE.remove(tableIdentifier.getUniqueId());
}

public static void removeTableStructureFromCache(String uniqueID) throws BaseStatusCode
{
TABLESTRUCTURE_CACHE.remove(uniqueID);
}

public static void clearAllCache()
{
TABLESTRUCTURE_CACHE.clear();
}

public static String getStructureHandler(TableUniqueIdentifier tableIdentifier)
{
try
{
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.setCriteria(parent);
DataObject dobj = PersistenceDBUtil.getPersistence().get(tableDetailsQuery);
Row row = dobj.getFirstRow(ELA_EMBER_TABLE_DETAILS);
return (String)row.get("STRUCTURE_HANDLER_CLASS");
}
catch (Exception exp)
{
exp.printStackTrace();
}
return null;
}

private static JSONObject getBaseStructureForTable(TableUniqueIdentifier tableIdentifier) throws BaseStatusCode
{
ClientStructureModel model = null;
if(TABLE_STRUCTURE_MODEL_CONTAINER.get(tableIdentifier.getUniqueId())!=null)
{
model = TABLE_STRUCTURE_MODEL_CONTAINER.get(tableIdentifier.getUniqueId());
}
else
{
String structureHandler = getStructureHandler(tableIdentifier);
if(structureHandler != null)
{
try
{
Class<?> dynamicStructureClass = Class.forName(structureHandler);
model = ((ClientStructureModel) dynamicStructureClass.getConstructor().newInstance());
TABLE_STRUCTURE_MODEL_CONTAINER.put(tableIdentifier.getUniqueId(),model);

}
catch (Exception exp)
{
throw BaseStatusCode.getBaseStatusCode(PredefinedStatusCodes.INVALID_PARAMETERS);
}
}
else
{
throw BaseStatusCode.getBaseStatusCode(PredefinedStatusCodes.INVALID_PARAMETERS);
}
}
return model.retrieveStructure(tableIdentifier);
}

private static JSONObject getColumnConfigurationFromCache(TableUniqueIdentifier tableIdentifier) throws BaseStatusCode
{
JSONObject structure = new JSONObject();
try
{
JSONObject tableCache = getTableDetailsFromCache(tableIdentifier);
structure = tableCache.getJSONObject(COLUMN_PROPERTIES);
}
catch(JSONException exp)
{
throw BaseStatusCode.getBaseStatusCode(PredefinedStatusCodes.INVALID_PARAMETERS);
}
return structure;
}

private static JSONObject getTableDetailsFromCache(TableUniqueIdentifier tableIdentifier) throws BaseStatusCode
{
JSONObject tableDetails = new JSONObject();
if(TABLESTRUCTURE_CACHE.get(tableIdentifier.getUniqueId()) == null)
{
tableDetails = collectEmberTableDetails(tableIdentifier);
TABLESTRUCTURE_CACHE.put(tableIdentifier.getUniqueId(), tableDetails);
}
else
{
RWLOCK.readLock().lock();
try
{
tableDetails = TABLESTRUCTURE_CACHE.get(tableIdentifier.getUniqueId());
}
finally
{
RWLOCK.readLock().unlock();
}
}
return tableDetails;
}

private static JSONObject collectEmberTableDetails(TableUniqueIdentifier tableIdentifier) throws BaseStatusCode
{
RWLOCK.writeLock().lock();
try
{
return getBaseStructureForTable(tableIdentifier);
}
catch (BaseStatusCode e)
{
throw e;
}
finally
{
RWLOCK.writeLock().unlock();
}
}

private static void updateWindowsDependentColumns()
{
try
{
Criteria criteria1 = new Criteria(Column.getColumn(ELA_EMBER_COLUMN_CONFIGURATIONS, "TABLEID"), EmberTableIdConstants.DEVICE_WINDOWS_MANAGEMENT, QueryConstants.EQUAL); //Dashboard //NO I18N
criteria1 = criteria1.and(new Criteria(Column.getColumn(ELA_EMBER_COLUMN_CONFIGURATIONS, "COLUMN_DISPLAY_TYPE"), "VISIBLE", QueryConstants.EQUAL)); //NO I18N

Criteria criteria2 = new Criteria(Column.getColumn(ELA_EMBER_COLUMN_CONFIGURATIONS, "TABLEID"), EmberTableIdConstants.DEVICE_ALL_DASHBOARD, QueryConstants.EQUAL); //Windows device details //NO I18N
criteria2 = criteria2.and(new Criteria(Column.getColumn(ELA_EMBER_COLUMN_CONFIGURATIONS, "COLUMN_DISPLAY_TYPE"), "VISIBLE", QueryConstants.EQUAL)); //NO I18N

Criteria criteria3 = new Criteria(Column.getColumn(ELA_EMBER_COLUMN_CONFIGURATIONS, "COLUMNNAME"), "NEXT_SCAN_TIME", QueryConstants.EQUAL); //Windows device details //NO I18N

DataBaseReqestProcessor.executeUpdateQuery(ELA_EMBER_COLUMN_CONFIGURATIONS , "COLUMN_DISPLAY_TYPE" , "HIDDEN" , (criteria1.and(criteria3)).or(criteria2.and(criteria3))); //NO I18N
}
catch(Exception exp)
{
exp.printStackTrace();
}
}
static
{
if(!ServerDetailsBean.getInstance().isWindows())
{
updateWindowsDependentColumns();
}
}

public static void getLocaleTranslatedColumns(JSONObject tableStructure,Locale locale)
{
try
{
ProductBundle instance = ProductBundle.getInstance();
if (tableStructure.has("COLUMNDEFINITION"))
{
JSONArray coloumnList = tableStructure.getJSONArray("COLUMNDEFINITION");
for (int i = 0; i < coloumnList.length(); i++)
{
try
{
String keyValue = coloumnList.getJSONObject(i).optString("DISPLAY_KEY", null);
if (keyValue != null && !keyValue.trim().isEmpty())
{
String localeString = instance.getString(locale, keyValue);
localeString = localeString.equals(keyValue) ? "" : localeString;
coloumnList.getJSONObject(i).put("DISPLAY_NAME", localeString);
}
}
catch (Exception e)
{
e.printStackTrace();
}
}
}
}
catch (JSONException e)
{
e.printStackTrace();
}
}

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