Search in sources :

Example 1 with Element

use of com.servoy.j2db.persistence.ContentSpec.Element 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;
}
Also used : ISupportUpdateableName(com.servoy.j2db.persistence.ISupportUpdateableName) ISupportChilds(com.servoy.j2db.persistence.ISupportChilds) IScriptElement(com.servoy.j2db.persistence.IScriptElement) Element(com.servoy.j2db.persistence.ContentSpec.Element) AbstractBase(com.servoy.j2db.persistence.AbstractBase) RemoteException(java.rmi.RemoteException) RepositoryException(com.servoy.j2db.persistence.RepositoryException) IGlobalValueEntry(com.servoy.j2db.dataprocessing.IGlobalValueEntry) JSONObject(org.json.JSONObject) IPersist(com.servoy.j2db.persistence.IPersist) IPersistVisitor(com.servoy.j2db.persistence.IPersistVisitor) JSONObject(org.json.JSONObject) IRootObject(com.servoy.j2db.persistence.IRootObject) ScriptNameValidator(com.servoy.j2db.persistence.ScriptNameValidator) UUID(com.servoy.j2db.util.UUID) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) ConcurrentMap(java.util.concurrent.ConcurrentMap) HashSet(java.util.HashSet)

Example 2 with Element

use of com.servoy.j2db.persistence.ContentSpec.Element in project servoy-client by Servoy.

the class AbstractBase method clearProperty.

public void clearProperty(String propertyName) {
    // TODO is it ok here to also clear custom properties? jsonCustomProperties get/set have different methods for that; and now a separate clear is added for custom properties as well
    if (propertiesMap.containsKey(propertyName) || jsonCustomProperties != null && jsonCustomProperties.containsKey(propertyName)) {
        isChanged = true;
        // call the setter with content spec default so any cached data is cleared
        Element element = StaticContentSpecLoader.getContentSpec().getPropertyForObjectTypeByName(getTypeID(), propertyName);
        setProperty(propertyName, element == null ? null : element.getDefaultClassValue());
        if (propertiesMap.containsKey(propertyName)) {
            propertiesMap.remove(propertyName);
        } else if (jsonCustomProperties != null && jsonCustomProperties.containsKey(propertyName)) {
            jsonCustomProperties.remove(propertyName);
        }
        if (bufferPropertiesMap != null) {
            // the setProperty above might set (wrongly) default value in bufferPropertiesMap as well during import
            bufferPropertiesMap.remove(propertyName);
        }
    }
}
Also used : Element(com.servoy.j2db.persistence.ContentSpec.Element)

Example 3 with Element

use of com.servoy.j2db.persistence.ContentSpec.Element in project servoy-client by Servoy.

the class AbstractBase method setPropertyInternal.

protected void setPropertyInternal(String propertyName, Object val) {
    Boolean newPropAndWasChanged = null;
    if (propertiesMap.containsKey(propertyName)) {
        if (!StaticContentSpecLoader.PROPERTY_NAME.getPropertyName().equals(propertyName)) {
            checkForChange(propertiesMap.get(propertyName), val);
        } else {
            checkForNameChange((String) propertiesMap.get(propertyName), (String) val);
        }
    } else {
        newPropAndWasChanged = Boolean.valueOf(isChanged);
        isChanged = true;
    }
    if (bufferPropertiesMap != null) {
        bufferPropertiesMap.put(propertyName, val);
    } else {
        if (isNotExtendingAnotherPersist()) {
            Element element = StaticContentSpecLoader.getContentSpec().getPropertyForObjectTypeByName(getTypeID(), propertyName);
            if (element != null && Utils.equalObjects(val, element.getDefaultClassValue())) {
                if (newPropAndWasChanged != null) {
                    // changed was set because property was added, now we remove property again, revert to previous changed state
                    isChanged = newPropAndWasChanged.booleanValue();
                }
                propertiesMap.remove(propertyName);
                return;
            }
        }
        propertiesMap.put(propertyName, val);
    }
}
Also used : Element(com.servoy.j2db.persistence.ContentSpec.Element)

Example 4 with Element

use of com.servoy.j2db.persistence.ContentSpec.Element in project servoy-client by Servoy.

the class AbstractBase method getProperty.

public Object getProperty(String propertyName) {
    Object value = null;
    boolean isInPropertiesMap = false;
    if (bufferPropertiesMap != null && bufferPropertiesMap.containsKey(propertyName)) {
        value = bufferPropertiesMap.get(propertyName);
        isInPropertiesMap = true;
    } else if (propertiesMap.containsKey(propertyName)) {
        value = propertiesMap.get(propertyName);
        isInPropertiesMap = true;
    }
    if (!isInPropertiesMap || value instanceof JSONObject) {
        if (!StaticContentSpecLoader.PROPERTY_CUSTOMPROPERTIES.getPropertyName().equals(propertyName) && this instanceof ISupportExtendsID && PersistHelper.isOverrideElement((ISupportExtendsID) this)) {
            IPersist superPersist = PersistHelper.getSuperPersist((ISupportExtendsID) this);
            if (superPersist != null) {
                Object propertyValue = ((AbstractBase) superPersist).getProperty(propertyName);
                if (value instanceof JSONObject) {
                    if (propertyValue instanceof JSONObject) {
                        return mergeJSONObjects((JSONObject) propertyValue, (JSONObject) value);
                    }
                } else {
                    return propertyValue;
                }
            }
            Element element = StaticContentSpecLoader.getContentSpec().getPropertyForObjectTypeByName(getTypeID(), propertyName);
            if (element != null) {
                Object propertyValue = element.getDefaultClassValue();
                if (value instanceof JSONObject) {
                    if (propertyValue instanceof JSONObject) {
                        value = mergeJSONObjects((JSONObject) propertyValue, (JSONObject) value);
                    }
                } else {
                    value = propertyValue;
                }
            }
        } else {
            // content spec default value
            Element element = StaticContentSpecLoader.getContentSpec().getPropertyForObjectTypeByName(getTypeID(), propertyName);
            if (element != null) {
                Object propertyValue = element.getDefaultClassValue();
                if (value instanceof JSONObject) {
                    if (propertyValue instanceof JSONObject) {
                        value = mergeJSONObjects((JSONObject) propertyValue, (JSONObject) value);
                    }
                } else {
                    value = propertyValue;
                }
            }
        }
    }
    return makeCopy(value);
}
Also used : JSONObject(org.json.JSONObject) ServoyJSONObject(com.servoy.j2db.util.ServoyJSONObject) Element(com.servoy.j2db.persistence.ContentSpec.Element) JSONObject(org.json.JSONObject) ServoyJSONObject(com.servoy.j2db.util.ServoyJSONObject)

Example 5 with Element

use of com.servoy.j2db.persistence.ContentSpec.Element in project servoy-client by Servoy.

the class SpecGenerator method readModelAndHandlers.

private void readModelAndHandlers(List<SpecTemplateModel> specTemplateList) {
    MethodTemplatesLoader.loadMethodTemplatesFromXML();
    ContentSpec spec = StaticContentSpecLoader.getContentSpec();
    for (SpecTemplateModel componentSpec : specTemplateList) {
        List<Element> props = Utils.asList(spec.getPropertiesForObjectType(componentSpec.getRepositoryType()));
        List<Element> model = new ArrayList<Element>();
        List<ApiMethod> handlers = new ArrayList<ApiMethod>();
        for (Element element : props) {
            if (isAllowedProperty(componentSpec.getName(), element.getName())) {
                if (BaseComponent.isEventProperty(element.getName())) {
                    if (element.getDeprecatedMoveContentID() == 0) {
                        MethodTemplate template = MethodTemplate.getTemplate(ScriptMethod.class, element.getName());
                        List<String> parametersNames = new ArrayList<String>();
                        List<String> parameterTypes = new ArrayList<String>();
                        List<String> optionalParameters = new ArrayList<String>();
                        if (template.getArguments() != null) {
                            for (MethodArgument arg : template.getArguments()) {
                                parametersNames.add(arg.getName());
                                parameterTypes.add(arg.getType().getName());
                                if (arg.isOptional())
                                    optionalParameters.add(arg.getName());
                            }
                        }
                        String returnType = template.getReturnType() != null ? template.getReturnType().getName() : null;
                        handlers.add(new ApiMethod(element.getName(), returnType, parametersNames, parameterTypes, optionalParameters, metaDataForApi.get(template.getName())));
                    }
                } else if (getSpecTypeFromRepoType(componentSpec.getName(), element) != null) {
                    model.add(element);
                }
            }
        }
        if ("listbox".equals(componentSpec.getName())) {
            ContentSpec cs = new ContentSpec();
            model.add(cs.new Element(-1, IRepository.FIELDS, "multiselectListbox", IRepository.BOOLEAN, Boolean.FALSE));
        }
        if ("splitpane".equals(componentSpec.getName())) {
            ContentSpec cs = new ContentSpec();
            model.add(cs.new Element(-1, IRepository.FIELDS, "divLocation", IRepository.INTEGER, Integer.valueOf(-1)));
            model.add(cs.new Element(-1, IRepository.FIELDS, "divSize", IRepository.INTEGER, Integer.valueOf(5)));
            model.add(cs.new Element(-1, IRepository.FIELDS, "resizeWeight", IRepository.INTEGER, Integer.valueOf(-1)));
            model.add(cs.new Element(-1, IRepository.FIELDS, "pane1MinSize", IRepository.INTEGER, Integer.valueOf(-1)));
            model.add(cs.new Element(-1, IRepository.FIELDS, "pane2MinSize", IRepository.INTEGER, Integer.valueOf(-1)));
        }
        if ("portal".equals(componentSpec.getName())) {
            ContentSpec cs = new ContentSpec();
            model.add(cs.new Element(-1, IRepository.FIELDS, "relatedFoundset", -1, null));
            model.add(cs.new Element(-1, IRepository.FIELDS, "childElements", -1, null));
            model.add(cs.new Element(-1, IRepository.FIELDS, "columnHeaders", -1, null));
            model.add(cs.new Element(-1, IRepository.FIELDS, "headersClasses", -1, null));
            model.add(cs.new Element(-1, IRepository.INTEGER, "headerHeight", IRepository.INTEGER, 32));
        }
        if (componentSpec.getRepositoryType() == IRepository.TABPANELS) {
            ContentSpec cs = new ContentSpec();
            Element el = cs.new Element(-1, IRepository.FIELDS, "tabIndex", IRepository.SERVERS, "");
            if (isAllowedProperty(componentSpec.getName(), el.getName()) && getSpecTypeFromRepoType(componentSpec.getName(), el) != null) {
                model.add(el);
            }
            el = cs.new Element(-1, IRepository.TABPANELS, "tabs", IRepository.SERVERS, null);
            model.add(el);
            el = cs.new Element(-1, IRepository.TABPANELS, "readOnly", IRepository.BOOLEAN, Boolean.FALSE);
            model.add(el);
        }
        if (addFindmodeModelEntries.contains(componentSpec.getName())) {
            ContentSpec cs = new ContentSpec();
            Element el = cs.new Element(-1, IRepository.FIELDS, "findmode", IRepository.STRING, null);
            model.add(el);
        }
        if (addReadOnlyModelEntries.contains(componentSpec.getName())) {
            ContentSpec cs = new ContentSpec();
            Element el = cs.new Element(-1, IRepository.FIELDS, "readOnly", IRepository.STRING, null);
            model.add(el);
        }
        componentSpec.setModel(model);
        componentSpec.setHandlers(handlers);
    }
}
Also used : ContentSpec(com.servoy.j2db.persistence.ContentSpec) MethodArgument(com.servoy.j2db.persistence.MethodArgument) Element(com.servoy.j2db.persistence.ContentSpec.Element) ArrayList(java.util.ArrayList) MethodTemplate(com.servoy.j2db.persistence.MethodTemplate)

Aggregations

Element (com.servoy.j2db.persistence.ContentSpec.Element)5 JSONObject (org.json.JSONObject)2 IGlobalValueEntry (com.servoy.j2db.dataprocessing.IGlobalValueEntry)1 AbstractBase (com.servoy.j2db.persistence.AbstractBase)1 ContentSpec (com.servoy.j2db.persistence.ContentSpec)1 IPersist (com.servoy.j2db.persistence.IPersist)1 IPersistVisitor (com.servoy.j2db.persistence.IPersistVisitor)1 IRootObject (com.servoy.j2db.persistence.IRootObject)1 IScriptElement (com.servoy.j2db.persistence.IScriptElement)1 ISupportChilds (com.servoy.j2db.persistence.ISupportChilds)1 ISupportUpdateableName (com.servoy.j2db.persistence.ISupportUpdateableName)1 MethodArgument (com.servoy.j2db.persistence.MethodArgument)1 MethodTemplate (com.servoy.j2db.persistence.MethodTemplate)1 RepositoryException (com.servoy.j2db.persistence.RepositoryException)1 ScriptNameValidator (com.servoy.j2db.persistence.ScriptNameValidator)1 ServoyJSONObject (com.servoy.j2db.util.ServoyJSONObject)1 UUID (com.servoy.j2db.util.UUID)1 RemoteException (java.rmi.RemoteException)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1