use of com.twinsoft.convertigo.beans.core.DatabaseObject in project convertigo by convertigo.
the class GetChildren method getChildren.
public static void getChildren(String qname, Element parent, int depth) throws Exception {
DatabaseObject dbo = Engine.theApp.databaseObjectsManager.getDatabaseObjectByQName(qname);
List<DatabaseObject> children = dbo.getDatabaseObjectChildren();
// Get all children of the dbo
Element elt = createDboElement(parent.getOwnerDocument(), dbo, !children.isEmpty());
/*
* In case of ScreenClass, we have to get Criteria, ExtractionRule and Sheets manually.
* If fact, if the dbo is an inherited screen class, inherited Criteria, ExtractionRule and Sheets,
* won't be retrieved by the method #getDatabaseObjectChildren.
*/
if (dbo instanceof ScreenClass) {
ScreenClass sc = (ScreenClass) dbo;
boolean hasChildren = false;
// Get all Criteria
List<Criteria> criteria = sc.getCriterias();
for (Criteria criterion : criteria) {
children.remove(criterion);
Element eltCriterion = createScreenClassChildElement(parent.getOwnerDocument(), criterion, dbo);
elt.appendChild(eltCriterion);
hasChildren = true;
}
// Get all Extraction Rules
List<ExtractionRule> extractionRules = sc.getExtractionRules();
for (ExtractionRule extractionRule : extractionRules) {
children.remove(extractionRule);
Element eltExtractionRule = createScreenClassChildElement(parent.getOwnerDocument(), extractionRule, dbo);
elt.appendChild(eltExtractionRule);
hasChildren = true;
}
// Get all Sheets
List<Sheet> sheets = sc.getSheets();
for (Sheet sheet : sheets) {
children.remove(sheet);
Element eltSheet = createScreenClassChildElement(parent.getOwnerDocument(), sheet, dbo);
elt.appendChild(eltSheet);
hasChildren = true;
}
// In case of JavelinScreenClass, we also have to get the block factory manually
if (dbo instanceof JavelinScreenClass) {
JavelinScreenClass jsc = (JavelinScreenClass) sc;
BlockFactory blockFactory = jsc.getBlockFactory();
children.remove(blockFactory);
Element eltBlockFactory = createScreenClassChildElement(parent.getOwnerDocument(), blockFactory, dbo);
elt.appendChild(eltBlockFactory);
hasChildren = true;
}
if (hasChildren) {
elt.setAttribute("hasChildren", "true");
}
}
parent.appendChild(elt);
if (depth > 0) {
for (DatabaseObject child : children) {
getChildren(child.getQName(), elt, depth - 1);
}
}
}
use of com.twinsoft.convertigo.beans.core.DatabaseObject in project convertigo by convertigo.
the class Set method getServiceResult.
protected void getServiceResult(HttpServletRequest request, Document document) throws Exception {
Element root = document.getDocumentElement();
String[] qnames = request.getParameterValues("qnames[]");
// Remove duplicates if someone sends the qname more than once
java.util.Set<String> uniqueQnames = new HashSet<>(Arrays.asList(qnames));
for (String objectQName : uniqueQnames) {
// Create the response : success or fail
Element response = document.createElement("response");
response.setAttribute("qname", objectQName);
try {
String value = request.getParameter("value");
String property = request.getParameter("property");
DatabaseObject dbo = Engine.theApp.databaseObjectsManager.getDatabaseObjectByQName(objectQName);
// Check if we try to update project name
if (dbo instanceof Project && "name".equals(property)) {
Project project = (Project) dbo;
String objectNewName = getPropertyValue(dbo, property, value).toString();
Engine.theApp.databaseObjectsManager.renameProject(project, objectNewName);
}
BeanInfo bi = CachedIntrospector.getBeanInfo(dbo.getClass());
PropertyDescriptor[] propertyDescriptors = bi.getPropertyDescriptors();
boolean propertyFound = false;
for (int i = 0; !propertyFound && i < propertyDescriptors.length; ++i) {
String propertyName = propertyDescriptors[i].getName();
initialPropertyElt = dbo.toXml(document, propertyName);
// Find the property we want to change
if (propertyFound = propertyName.equals(property)) {
Method setter = propertyDescriptors[i].getWriteMethod();
Class<?> propertyTypeClass = propertyDescriptors[i].getReadMethod().getReturnType();
if (propertyTypeClass.isPrimitive()) {
propertyTypeClass = ClassUtils.primitiveToWrapper(propertyTypeClass);
}
try {
String propertyValue = getPropertyValue(dbo, propertyName, value).toString();
Object oPropertyValue = com.twinsoft.convertigo.engine.admin.services.database_objects.Set.createObject(propertyTypeClass, propertyValue);
if (dbo.isCipheredProperty(propertyName)) {
Method getter = propertyDescriptors[i].getReadMethod();
String initialPropertyValue = (String) getter.invoke(dbo, (Object[]) null);
if (oPropertyValue.equals(initialPropertyValue) || DatabaseObject.encryptPropertyValue(initialPropertyValue).equals(oPropertyValue)) {
oPropertyValue = initialPropertyValue;
} else {
dbo.hasChanged = true;
}
}
// Update property value
if (oPropertyValue != null) {
Object[] args = { oPropertyValue };
setter.invoke(dbo, args);
}
} catch (IllegalArgumentException e) {
throw e;
}
}
}
// Invalid given property parameter
if (!propertyFound) {
throw new IllegalArgumentException("Property '" + property + "' not found for object '" + dbo.getQName() + "'");
}
response.setAttribute("state", "success");
response.setAttribute("message", "Property " + property + " has been successfully updated.");
Element elt = dbo.toXml(document, property);
elt.setAttribute("name", dbo.toString());
elt.setAttribute("hasChanged", Boolean.toString(dbo.hasChanged));
response.appendChild(elt);
} catch (Exception e) {
Engine.logAdmin.error("Error during saving the properties!\n" + e.getMessage());
response.setAttribute("state", "error");
response.setAttribute("message", "Error during saving the properties!");
// To restore the original value
response.appendChild(initialPropertyElt);
} finally {
root.appendChild(response);
}
}
}
use of com.twinsoft.convertigo.beans.core.DatabaseObject in project convertigo by convertigo.
the class DboUtils method getTechnology.
public static String getTechnology(DatabaseObject parentObject, Class<? extends DatabaseObject> objectClass) {
String technology = null;
DatabaseObject parent = parentObject;
if (parent != null) {
// case of Variable
if (Variable.class.isAssignableFrom(objectClass)) {
return technology = parent.getClass().getName();
}
// parent is a connector
if (parent instanceof Connector) {
return technology = ((Connector) parent).getClass().getName();
}
// parent is a sequence
if (parent instanceof Sequence) {
return technology = ((Sequence) parent).getClass().getName();
}
// parent is a statement
if (parent instanceof Statement) {
return technology = "com.twinsoft.convertigo.beans.statements.BlockStatement";
}
// parent is a step
if (parent instanceof Step) {
technology = "com.twinsoft.convertigo.beans.steps.BlockStep";
if (getClassName(parent.getClass()).startsWith("XML")) {
technology = parent.getClass().getName();
}
return technology;
}
// parent is a transaction
if (parent instanceof Transaction) {
if (parent instanceof HtmlTransaction) {
return technology = "com.twinsoft.convertigo.beans.transactions.HtmlTransaction";
} else if (parent instanceof SiteClipperTransaction) {
return technology = "com.twinsoft.convertigo.beans.transactions.SiteClipperTransaction";
}
}
// parent is a screenclass
if (parent instanceof ScreenClass) {
while ((parent = parent.getParent()) instanceof ScreenClass) {
;
}
if (parent instanceof JavelinConnector)
technology = ((JavelinConnector) parent).getEmulatorTechnology();
if (parent instanceof HtmlConnector)
technology = "com.twinsoft.convertigo.beans.screenclasses.HtmlScreenClass";
if (parent instanceof SiteClipperConnector)
technology = "com.twinsoft.convertigo.beans.screenclasses.SiteClipperScreenClass";
}
}
return technology;
}
use of com.twinsoft.convertigo.beans.core.DatabaseObject in project convertigo by convertigo.
the class MobileSmartSourcePropertyDescriptor method getTags.
public static String[] getTags(DatabaseObjectTreeObject databaseObjectTreeObject, String propertyName) {
DatabaseObject bean = (DatabaseObject) databaseObjectTreeObject.getObject();
ITagsProperty tagsProperty = null;
if (bean instanceof ITagsProperty) {
tagsProperty = (ITagsProperty) bean;
} else {
return new String[] { "" };
}
String[] sResults = tagsProperty.getTagsForProperty(propertyName);
return sResults;
}
use of com.twinsoft.convertigo.beans.core.DatabaseObject in project convertigo by convertigo.
the class MobileSmartSourceTypeCellEditor method getTags.
private String[] getTags() {
if (databaseObjectTreeObject != null && propertyDescriptor != null) {
String propertyName = (String) propertyDescriptor.getId();
DatabaseObject bean = (DatabaseObject) databaseObjectTreeObject.getObject();
if (bean instanceof ITagsProperty) {
return ((ITagsProperty) bean).getTagsForProperty(propertyName);
}
}
return new String[] { "" };
}
Aggregations