use of com.servoy.j2db.persistence.ISupportChilds in project servoy-client by Servoy.
the class FlattenedSolution method clonePersist.
@SuppressWarnings({ "unchecked", "nls" })
public <T extends AbstractBase> T clonePersist(T persist, String newName, AbstractBase newParent) {
T clone = (T) persist.clonePersist(persist.getParent() == newParent ? null : newParent);
final Map<Object, Object> updatedElementIds = AbstractPersistFactory.resetUUIDSRecursively(clone, getPersistFactory(), false);
if (persist.getParent() == newParent) {
newParent.addChild(clone);
}
// make sure that this persist is not seen as a copy a real persist/form
clone.setRuntimeProperty(CLONE_PROPERTY, null);
if (clone instanceof ISupportUpdateableName) {
try {
((ISupportUpdateableName) clone).updateName(new ScriptNameValidator(this), newName);
} catch (Exception e) {
if (newParent != null) {
newParent.removeChild(clone);
}
throw new RuntimeException("name '" + newName + "' invalid for the clone of " + ((ISupportName) persist).getName() + ", error: " + e.getMessage());
}
}
if (clone instanceof ISupportChilds) {
clone.acceptVisitor(new IPersistVisitor() {
public Object visit(IPersist o) {
if (o instanceof AbstractBase) {
Map<String, Object> propertiesMap = ((AbstractBase) o).getPropertiesMap();
for (Map.Entry<String, Object> entry : propertiesMap.entrySet()) {
Object elementId = updatedElementIds.get(entry.getValue());
if (elementId instanceof Integer) {
Element element = StaticContentSpecLoader.getContentSpec().getPropertyForObjectTypeByName(o.getTypeID(), entry.getKey());
if (element.getTypeID() == IRepository.ELEMENTS)
((AbstractBase) o).setProperty(entry.getKey(), elementId);
} else if (entry.getValue() instanceof JSONObject) {
updateElementReferences((JSONObject) entry.getValue(), updatedElementIds);
}
}
}
return null;
}
});
}
if (securityAccess != null) {
ConcurrentMap<Object, Integer> securityValues = securityAccess.getLeft();
for (Object elementUUID : new HashSet(securityValues.keySet())) {
if (updatedElementIds.containsKey(elementUUID.toString())) {
UUID uuid = Utils.getAsUUID(updatedElementIds.get(elementUUID.toString()), false);
if (uuid != null) {
securityValues.put(uuid, securityValues.get(elementUUID));
}
}
}
}
flush(persist);
getIndex().reload();
return clone;
}
use of com.servoy.j2db.persistence.ISupportChilds in project servoy-client by Servoy.
the class FlattenedSolution method getSolutionCopy.
public Solution getSolutionCopy(boolean create) {
if (mainSolution == null) {
if (loginFlattenedSolution != null) {
return loginFlattenedSolution.getSolutionCopy(create);
}
return null;
}
if (copySolution != null || !create)
return copySolution;
try {
SimplePersistFactory factory = getPersistFactory();
copySolution = SimplePersistFactory.createDummyCopy(mainSolution);
copySolution.setChangeHandler(new ChangeHandler(factory) {
// overwrite this new Object to skip the call to rootObject.registerNewObject(object); which shouldn't be needed for solution model solutions.
@Override
public IPersist createNewObject(ISupportChilds parent, int object_type_id, int element_id, UUID uuid) throws RepositoryException {
return factory.createObject(parent, object_type_id, element_id, uuid);
}
});
copySolution.getChangeHandler().addIPersistListener(this);
getIndex().setSolutionModelSolution(copySolution);
} catch (Exception e) {
Debug.error(e);
}
return copySolution;
}
use of com.servoy.j2db.persistence.ISupportChilds in project servoy-client by Servoy.
the class FormElementHelper method getControlledTabSeqReplacementFor.
/**
* Generates a Servoy controlled tab-sequence-index. We try to avoid sending default (0 or null) tabSeq even
* for forms that do use default tab sequence in order to avoid problems with nesting default and non-default tabSeq forms.
*
* @param designValue the value the persist holds for the tabSeq.
* @param form the form containing the persist
* @param persistIfAvailable the persist. For now, 'component' type properties might work with non-persist-linked FormElements so it could be null.
* When those become persist based as well this will never be null.
* @return the requested controlled tabSeq (should make tabSeq be identical to the one shown in developer).
*/
public Integer getControlledTabSeqReplacementFor(Integer designValue, PropertyDescription pd, Form flattenedForm, IPersist persistIfAvailable, // TODO more args will be needed here such as the tabSeq property name or description
FlattenedSolution flattenedSolution, // TODO more args will be needed here such as the tabSeq property name or description
boolean design) {
// TODO this can be removed when we know we'll always have a persist here; currently don't handle this in any way as it's not supported
if (persistIfAvailable == null || (nestedCall.get() != null && nestedCall.get().booleanValue()))
return designValue;
nestedCall.set(Boolean.TRUE);
final boolean responsiveForm = flattenedForm.isResponsiveLayout();
try {
if (flattenedForm.isFormComponent() && persistIfAvailable instanceof AbstractBase) {
String mainFormName = ((AbstractBase) persistIfAvailable).getRuntimeProperty(FORM_COMPONENT_FORM_NAME);
if (mainFormName != null) {
flattenedForm = flattenedSolution.getFlattenedForm(flattenedSolution.getForm(mainFormName));
// just return the skip value if this is somehow invalid.
if (flattenedForm == null)
return Integer.valueOf(-2);
}
}
boolean formWasModifiedViaSolutionModel = flattenedSolution.hasCopy(flattenedForm);
Map<TabSeqProperty, Integer> cachedTabSeq = null;
if (formWasModifiedViaSolutionModel) {
Pair<Long, Map<TabSeqProperty, Integer>> pair = flattenedForm.getRuntimeProperty(FORM_TAB_SEQUENCE);
if (pair != null && flattenedForm.getLastModified() == pair.getLeft().longValue()) {
cachedTabSeq = pair.getRight();
}
} else
cachedTabSeq = formTabSequences.get(flattenedForm.getUUID());
if (cachedTabSeq == null) {
cachedTabSeq = new HashMap<TabSeqProperty, Integer>();
SortedList<TabSeqProperty> selected = new SortedList<TabSeqProperty>(new Comparator<TabSeqProperty>() {
public int compare(TabSeqProperty o1, TabSeqProperty o2) {
int seq1 = o1.getSeqValue();
int seq2 = o2.getSeqValue();
if (seq1 == ISupportTabSeq.DEFAULT && seq2 == ISupportTabSeq.DEFAULT) {
if (responsiveForm) {
if (o1.element.getParent() == o2.element.getParent()) {
int positionComparator = PositionComparator.comparePoint(false, o1.getLocation(), o2.getLocation());
if (positionComparator != 0) {
return positionComparator;
}
} else {
List<ISupportChilds> ancestors = new ArrayList<ISupportChilds>();
IPersist persist = o1.element;
while (persist.getParent() instanceof AbstractContainer) {
ancestors.add(persist.getParent());
persist = persist.getParent();
}
persist = o2.element;
while (persist.getParent() instanceof AbstractContainer) {
if (ancestors.contains(persist.getParent())) {
// we found the common ancestor
int index = ancestors.indexOf(persist.getParent());
IPersist comparablePersist = index == 0 ? o1.element : ancestors.get(index - 1);
int positionComparator = PositionComparator.comparePoint(false, ((ISupportBounds) comparablePersist).getLocation(), ((ISupportBounds) persist).getLocation());
if (positionComparator != 0) {
return positionComparator;
}
}
persist = persist.getParent();
}
}
} else {
int positionComparator = PositionComparator.comparePoint(false, o1.getLocation(), o2.getLocation());
if (positionComparator != 0) {
return positionComparator;
}
}
}
return compareTabSeq(seq1, o1.element, seq2, o2.element, flattenedSolution);
}
});
Map<TabSeqProperty, List<TabSeqProperty>> listFormComponentMap = new HashMap<TabSeqProperty, List<TabSeqProperty>>();
List<TabSeqProperty> listFormComponentElements = null;
TabSeqProperty listFormComponentTabSeq = null;
Iterator<IFormElement> iterator = flattenedForm.getFlattenedObjects(null).iterator();
while (iterator.hasNext()) {
IFormElement formElement = iterator.next();
if (FormTemplateGenerator.isWebcomponentBean(formElement)) {
String componentType = FormTemplateGenerator.getComponentTypeName(formElement);
WebObjectSpecification specification = WebComponentSpecProvider.getSpecProviderState().getWebComponentSpecification(componentType);
if (specification != null) {
Collection<PropertyDescription> properties = specification.getProperties(NGTabSeqPropertyType.NG_INSTANCE);
Collection<PropertyDescription> formComponentProperties = specification.getProperties(FormComponentPropertyType.INSTANCE);
boolean isListFormComponent = isListFormComponent(formComponentProperties);
if (properties != null && properties.size() > 0) {
IBasicWebComponent webComponent = (IBasicWebComponent) formElement;
for (PropertyDescription tabSeqProperty : properties) {
int tabseq = Utils.getAsInteger(webComponent.getProperty(tabSeqProperty.getName()));
TabSeqProperty seqProperty = new TabSeqProperty(formElement, tabSeqProperty.getName());
if (listFormComponentTabSeq == null && isListFormComponent) {
listFormComponentTabSeq = seqProperty;
listFormComponentElements = new ArrayList<TabSeqProperty>();
listFormComponentMap.put(listFormComponentTabSeq, listFormComponentElements);
}
if (tabseq >= 0) {
selected.add(seqProperty);
} else {
cachedTabSeq.put(seqProperty, Integer.valueOf(-2));
}
}
}
addFormComponentProperties(formComponentProperties, formElement, flattenedSolution, cachedTabSeq, selected, listFormComponentElements, design, new HashSet<String>());
}
} else if (formElement instanceof ISupportTabSeq) {
if (((ISupportTabSeq) formElement).getTabSeq() >= 0) {
selected.add(new TabSeqProperty(formElement, StaticContentSpecLoader.PROPERTY_TABSEQ.getPropertyName()));
} else {
cachedTabSeq.put(new TabSeqProperty(formElement, StaticContentSpecLoader.PROPERTY_TABSEQ.getPropertyName()), Integer.valueOf(-2));
}
}
}
int i = 1;
for (TabSeqProperty tabSeq : selected) {
cachedTabSeq.put(tabSeq, Integer.valueOf(i++));
}
for (TabSeqProperty tabSeq : listFormComponentMap.keySet()) {
List<TabSeqProperty> elements = listFormComponentMap.get(tabSeq);
if (elements != null) {
Integer value = cachedTabSeq.get(tabSeq);
// all elements inside list form component have same tabindex as the list itself
for (TabSeqProperty tabSeqElement : elements) {
cachedTabSeq.put(tabSeqElement, value);
}
}
}
if (!formWasModifiedViaSolutionModel) {
formTabSequences.putIfAbsent(flattenedForm.getUUID(), cachedTabSeq);
} else {
flattenedForm.setRuntimeProperty(FORM_TAB_SEQUENCE, new Pair<>(Long.valueOf(flattenedForm.getLastModified()), cachedTabSeq));
}
}
IPersist realPersist = flattenedForm.findChild(persistIfAvailable.getUUID());
if (realPersist == null) {
realPersist = persistIfAvailable;
}
Integer controlledTabSeq = cachedTabSeq.get(new TabSeqProperty(realPersist, pd.getName()));
// if not in tabSeq, use "skip" value
if (controlledTabSeq == null)
controlledTabSeq = Integer.valueOf(-2);
return controlledTabSeq;
} finally {
nestedCall.set(Boolean.FALSE);
}
}
use of com.servoy.j2db.persistence.ISupportChilds in project servoy-client by Servoy.
the class ServoyFunctionPropertyType method toJSON.
public JSONWriter toJSON(JSONWriter writer, String key, Object object, PropertyDescription pd, DataConversion clientConversion, FlattenedSolution fs, FormElement fe, WebFormComponent formComponent) throws JSONException {
Map<String, Object> map = new HashMap<>();
if (object != null && fs != null) {
// $NON-NLS-1$
String[] components = object.toString().split("-");
if (components.length == 5) {
String scriptString = null;
// this is a uuid
ScriptMethod sm = fs.getScriptMethod(object.toString());
if (sm != null) {
ISupportChilds parent = sm.getParent();
if (parent instanceof Solution) {
scriptString = "scopes." + sm.getScopeName() + "." + sm.getName();
} else if (parent instanceof Form) {
if (formComponent != null) {
// use the real, runtime form
scriptString = formComponent.getDataAdapterList().getForm().getForm().getName() + "." + sm.getName();
} else {
scriptString = ((Form) parent).getName() + "." + sm.getName();
}
} else if (parent instanceof TableNode && fe != null) {
scriptString = "entity." + fe.getForm().getName() + "." + sm.getName();
}
object = scriptString;
} else
Debug.log("can't find a scriptmethod for: " + object);
}
}
try {
if (object instanceof String) {
addScriptToMap((String) object, map);
} else if (object instanceof NativeFunction) {
nativeFunctionToJSON((NativeFunction) object, map);
} else if (object instanceof FunctionWrapper && ((FunctionWrapper) object).getWrappedFunction() instanceof NativeFunction) {
nativeFunctionToJSON((NativeFunction) ((FunctionWrapper) object).getWrappedFunction(), map);
} else if (object instanceof Map) {
map = new HashMap<String, Object>((Map<String, Object>) object);
if (map.get("script") instanceof String)
addScriptToMap((String) map.get("script"), map);
}
} catch (Exception ex) {
Debug.error(ex);
}
return JSONUtils.toBrowserJSONFullValue(writer, key, map.size() == 0 ? null : map, null, clientConversion, null);
}
use of com.servoy.j2db.persistence.ISupportChilds in project servoy-client by Servoy.
the class PersistHelper method getFlattenedPersist.
public static ISupportChilds getFlattenedPersist(FlattenedSolution flattenedSolution, Form parent, ISupportChilds persist) {
ISupportChilds flattenedPersist = persist;
if (flattenedPersist instanceof Form) {
flattenedPersist = flattenedSolution.getFlattenedForm(flattenedPersist);
}
if (flattenedPersist instanceof LayoutContainer && !(flattenedPersist instanceof FlattenedLayoutContainer)) {
FlattenedForm ff = flattenedSolution.getFlattenedForm(parent) instanceof FlattenedForm ? (FlattenedForm) flattenedSolution.getFlattenedForm(parent) : flattenedSolution.createFlattenedForm(parent);
flattenedPersist = new FlattenedLayoutContainer(ff, (LayoutContainer) flattenedPersist);
}
return flattenedPersist;
}
Aggregations