|
| 1 | +package sap.sample.cmsdbdriver.plugin.custom; |
| 2 | + |
| 3 | +import java.sql.Types; |
| 4 | +import java.util.HashMap; |
| 5 | +import java.util.List; |
| 6 | +import java.util.Map; |
| 7 | +import java.util.Set; |
| 8 | + |
| 9 | +import com.crystaldecisions.sdk.occa.infostore.CePropertyID; |
| 10 | +import com.crystaldecisions.sdk.occa.infostore.IDestination; |
| 11 | +import com.crystaldecisions.sdk.occa.infostore.IDestinations; |
| 12 | +import com.crystaldecisions.sdk.occa.infostore.IInfoObject; |
| 13 | +import com.crystaldecisions.sdk.occa.infostore.IInfoObjects; |
| 14 | +import com.crystaldecisions.sdk.occa.infostore.IProcessingInfo; |
| 15 | +import com.crystaldecisions.sdk.occa.infostore.ISchedulingInfo; |
| 16 | +import com.crystaldecisions.sdk.properties.IProperties; |
| 17 | +import com.crystaldecisions.sdk.properties.IProperty; |
| 18 | +import com.sap.connectivity.cs.java.drivers.cms.CMSDBDriverException; |
| 19 | +import com.sap.connectivity.cs.java.drivers.cms.api.CustomObject; |
| 20 | +import com.sap.connectivity.cs.java.drivers.cms.api.IQueryElement; |
| 21 | +import com.sap.connectivity.cs.java.drivers.sdk.datafoundation.IUnvTable; |
| 22 | +import com.sap.connectivity.cs.java.drivers.sdk.datafoundation.UnvTableFieldDef; |
| 23 | +import com.sap.connectivity.cs.sqlparser.Condition.Operand; |
| 24 | + |
| 25 | +import sap.sample.cmsdbdriver.plugin.core.IResultPlugin; |
| 26 | +import sap.sample.cmsdbdriver.plugin.core.IResultTable; |
| 27 | +import sap.sample.cmsdbdriver.plugin.core.PluginBase; |
| 28 | + |
| 29 | +public class ScheduleInfoTableResults extends IResultTable implements IUnvTable { |
| 30 | + |
| 31 | + private static final String TABLE_NAME = "ScheduleInfo"; |
| 32 | + |
| 33 | + private static final String NO = "no"; |
| 34 | + private static final String DETAILS = "Details"; |
| 35 | + private static final String VALUE = "PropertyValue"; |
| 36 | + private static final String LEVEL = "PropertyLevel"; |
| 37 | + private static final String PATH = "PropertyPath"; |
| 38 | + private static final String NAME = "PropertyName"; |
| 39 | + private static final String IS_CONTAINER = "PropertyIsContainer"; |
| 40 | + |
| 41 | + final private PluginBase pluginBase; |
| 42 | + |
| 43 | + final private Map<String, UnvTableFieldDef> columns = new HashMap<String, UnvTableFieldDef>(); |
| 44 | + private String queryFields; |
| 45 | + |
| 46 | + /** |
| 47 | + * Define the list of Fields for the virtual table |
| 48 | + */ |
| 49 | + public ScheduleInfoTableResults(IResultPlugin plugin) { |
| 50 | + super(plugin); |
| 51 | + columns.put(NO, new UnvTableFieldDef(NO, Types.INTEGER)); |
| 52 | + columns.put(DETAILS, new UnvTableFieldDef(DETAILS, Types.VARCHAR)); |
| 53 | + pluginBase = (PluginBase)plugin; |
| 54 | + |
| 55 | + } |
| 56 | + |
| 57 | + /** |
| 58 | + * Returns the name of the virtual table |
| 59 | + * @return virtual table name |
| 60 | + */ |
| 61 | + @Override |
| 62 | + public String getName() { |
| 63 | + return TABLE_NAME; |
| 64 | + } |
| 65 | + |
| 66 | + @Override |
| 67 | + /** |
| 68 | + * Returns the fields defined for the virtual table |
| 69 | + * @return list of table fields |
| 70 | + */ |
| 71 | + public Map<String, UnvTableFieldDef> getTableFields() { |
| 72 | + return this.columns; |
| 73 | + } |
| 74 | + |
| 75 | + @Override |
| 76 | + /** |
| 77 | + * use the getQueryElement() or getIds() to prepare data for setValues() |
| 78 | + */ |
| 79 | + public void initialize(IQueryElement queryElement, Set<Integer> ids) { |
| 80 | + // nothing to initialize/prepare |
| 81 | + queryFields = ""; |
| 82 | + for (int i=0; i<queryElement.getCondition().operands().size(); i++) { |
| 83 | + if (queryElement.getCondition().operands().get(i).toString().contentEquals(TABLE_NAME + "." + DETAILS)) { |
| 84 | + queryFields = queryElement.getCondition().operands().get(i + 1).toString(); |
| 85 | + queryFields = queryFields.trim().replaceAll("'", "").replaceAll("\\s+", ","); |
| 86 | + } |
| 87 | + } |
| 88 | + } |
| 89 | + |
| 90 | + |
| 91 | + @Override |
| 92 | + public void setValues(int id) throws CMSDBDriverException { |
| 93 | + IInfoObjects infoObjects = pluginBase.getConnection().queryCMS("select si_id, " + queryFields + " from ci_infoobjects where si_id = " + id); |
| 94 | + // should not be the case |
| 95 | + if (infoObjects == null) return; |
| 96 | + if (infoObjects.size() == 0) return; |
| 97 | + IInfoObject infoObject = (IInfoObject)infoObjects.get(0); |
| 98 | + //IProperties properties = infoObject.properties().getProperties(CePropertyID.SI_DESTINATIONS); |
| 99 | + |
| 100 | + String fields[] = queryFields.split(","); |
| 101 | + for (int i=0; i<fields.length; i++) { |
| 102 | + fields[i] = fields[i].trim(); |
| 103 | + String[] subFields = fields[i].split("\\."); |
| 104 | + if (subFields[0].equalsIgnoreCase("si_scheduleinfo")) { |
| 105 | + ISchedulingInfo sInfo = infoObject.getSchedulingInfo(); |
| 106 | + if (subFields.length == 1) { |
| 107 | + setValues(id, "SchedulingInfo", sInfo.properties(), 0, ""); |
| 108 | + } else { |
| 109 | + IProperty prop = sInfo.properties().getProperty(subFields[1]); |
| 110 | + if (prop != null) { |
| 111 | + if (prop.isContainer()) { |
| 112 | + setValues(id, "SchedulingInfo", (IProperties)prop.getValue(), 1, CePropertyID.idToName(prop.getID())); |
| 113 | + } else { |
| 114 | + if (getCustomObject() == null) setCustomObject(new CustomObject()); |
| 115 | + setObjectProperties("SchedulingInfo", 1, "", prop); |
| 116 | + addRow(id); |
| 117 | + } |
| 118 | + } |
| 119 | + } |
| 120 | + } else if (subFields[0].equalsIgnoreCase("si_processinfo")) { |
| 121 | + IProcessingInfo pInfo = infoObject.getProcessingInfo(); |
| 122 | + if (subFields.length == 1) { |
| 123 | + setValues(id, "ProcessingInfo", pInfo.properties(), 0, ""); |
| 124 | + } else { |
| 125 | + IProperty prop = pInfo.properties().getProperty(subFields[1]); |
| 126 | + if (prop != null) { |
| 127 | + if (prop.isContainer()) { |
| 128 | + setValues(id, "ProcessingInfo", (IProperties)prop.getValue(), 1, CePropertyID.idToName(prop.getID())); |
| 129 | + } else { |
| 130 | + if (getCustomObject() == null) setCustomObject(new CustomObject()); |
| 131 | + setObjectProperties("ProcessingInfo", 1, "", prop); |
| 132 | + addRow(id); |
| 133 | + } |
| 134 | + } |
| 135 | + } |
| 136 | + } |
| 137 | + } |
| 138 | + } |
| 139 | + |
| 140 | + private void setValues(int id, String text, IProperties properties, int level, String path) throws CMSDBDriverException { |
| 141 | + String s = ""; |
| 142 | + Set<Integer> keys = properties.keySet(); |
| 143 | + for (int key : keys) { |
| 144 | + if (getCustomObject() == null) setCustomObject(new CustomObject()); |
| 145 | + IProperty prop = properties.getProperty(key); |
| 146 | + setObjectProperties(text, level, path, prop); |
| 147 | + if (prop.isContainer()) { |
| 148 | + setValues(id, text, (IProperties)prop.getValue(), level + 1, path + (path.length() > 0 ? "." : "") + CePropertyID.idToName(prop.getID())); |
| 149 | + } else { |
| 150 | + addRow(id); |
| 151 | + } |
| 152 | + } |
| 153 | + } |
| 154 | + |
| 155 | + private void setObjectProperties(String text, int level, String path, IProperty prop) { |
| 156 | + setObjectProperty(TABLE_NAME + "." + ScheduleInfoTableResults.DETAILS, |
| 157 | + String.class.getName(), text); |
| 158 | + setObjectProperty(TABLE_NAME + "." + ScheduleInfoTableResults.LEVEL, |
| 159 | + Integer.class.getName(), level); |
| 160 | + setObjectProperty(TABLE_NAME + "." + ScheduleInfoTableResults.PATH, |
| 161 | + String.class.getName(), path); |
| 162 | + setObjectProperty(TABLE_NAME + "." + ScheduleInfoTableResults.NAME, |
| 163 | + String.class.getName(), CePropertyID.idToName(prop.getID())); |
| 164 | + setObjectProperty(TABLE_NAME + "." + ScheduleInfoTableResults.IS_CONTAINER, |
| 165 | + Boolean.class.getName(), prop.isContainer()); |
| 166 | + if (prop.isContainer()) return; |
| 167 | + setObjectProperty(TABLE_NAME + "." + ScheduleInfoTableResults.VALUE, |
| 168 | + String.class.getName(), "" + prop.getValue()); |
| 169 | + |
| 170 | + } |
| 171 | +} |
| 172 | + |
0 commit comments