Search in sources :

Example 6 with UUID

use of com.servoy.j2db.util.UUID in project servoy-client by Servoy.

the class AbstractRepository method createNewRootObject.

/**
 * Create a new root object
 */
public IRootObject createNewRootObject(String name, int objectTypeId) throws RepositoryException {
    UUID uuid = UUID.randomUUID();
    IRootObject rootObject = createNewRootObject(name, objectTypeId, getNewElementID(uuid), uuid);
    // Put the root object in the cache.
    return rootObject;
}
Also used : UUID(com.servoy.j2db.util.UUID)

Example 7 with UUID

use of com.servoy.j2db.util.UUID in project servoy-client by Servoy.

the class AbstractRootObject method clearEditingState.

public void clearEditingState(IPersist persist) {
    persist.clearChanged();
    UUID persistUuid = persist.getUUID();
    removeFromList(removedObjects, persistUuid);
    removeFromList(newObjects, persistUuid);
}
Also used : UUID(com.servoy.j2db.util.UUID)

Example 8 with UUID

use of com.servoy.j2db.util.UUID in project servoy-client by Servoy.

the class JSSecurity method hasFormAccess.

private boolean hasFormAccess(String formName, String elementName, int accessType) {
    Form form = application.getFlattenedSolution().getForm(formName);
    int access = 0;
    if (form != null) {
        UUID accesUUID = null;
        if (elementName != null) {
            for (IPersist persist : form.getFlattenedFormElementsAndLayoutContainers()) {
                if (persist instanceof ISupportName && Utils.equalObjects(elementName, ((ISupportName) persist).getName())) {
                    accesUUID = persist.getUUID();
                    break;
                }
            }
        } else {
            accesUUID = form.getUUID();
        }
        if (accesUUID != null) {
            access = application.getFlattenedSolution().getSecurityAccess(accesUUID, form.getImplicitSecurityNoRights() ? IRepository.IMPLICIT_FORM_NO_ACCESS : IRepository.IMPLICIT_FORM_ACCESS);
        }
    }
    return ((access & accessType) != 0);
}
Also used : Form(com.servoy.j2db.persistence.Form) IPersist(com.servoy.j2db.persistence.IPersist) ISupportName(com.servoy.j2db.persistence.ISupportName) UUID(com.servoy.j2db.util.UUID)

Example 9 with UUID

use of com.servoy.j2db.util.UUID in project servoy-client by Servoy.

the class FormElementHelper method generateFormComponentPersists.

private static List<IFormElement> generateFormComponentPersists(INGFormElement parent, PropertyDescription pd, JSONObject json, Form frm, FlattenedSolution fs) {
    List<IFormElement> elements = new ArrayList<>();
    List<IFormElement> formelements = fs.getFlattenedForm(frm).getFlattenedObjects(PositionComparator.XY_PERSIST_COMPARATOR);
    for (IFormElement element : formelements) {
        element = (IFormElement) ((AbstractBase) element).clonePersist(null);
        // we kind of want to have this element a new uuid, but then it is very hard to get it stable.
        UUID newElementUUID = null;
        synchronized (formComponentElementsUUIDS) {
            Map<UUID, UUID> map = formComponentElementsUUIDS.get(parent.getPersistIfAvailable().getUUID());
            if (map == null) {
                map = new HashMap<>();
                formComponentElementsUUIDS.put(parent.getPersistIfAvailable().getUUID(), map);
            }
            newElementUUID = map.get(element.getUUID());
            if (newElementUUID == null) {
                newElementUUID = UUID.randomUUID();
                map.put(element.getUUID(), newElementUUID);
            }
        }
        ((AbstractBase) element).resetUUID(newElementUUID);
        String elementName = element.getName();
        if (elementName == null) {
            elementName = FormElement.SVY_NAME_PREFIX + String.valueOf(element.getID());
        }
        String templateName = getStartElementName(parent, pd) + elementName;
        String formName = parent.getForm().getName();
        if (parent.getForm().isFormComponent() && parent.getPersistIfAvailable() instanceof AbstractBase && ((AbstractBase) parent.getPersistIfAvailable()).getRuntimeProperty(FORM_COMPONENT_FORM_NAME) != null) {
            formName = ((AbstractBase) parent.getPersistIfAvailable()).getRuntimeProperty(FORM_COMPONENT_FORM_NAME);
        }
        ((AbstractBase) element).setRuntimeProperty(FORM_COMPONENT_FORM_NAME, formName);
        ((AbstractBase) element).setRuntimeProperty(FORM_COMPONENT_UUID, parent.getPersistIfAvailable().getUUID().toString());
        JSONObject elementJson = json.optJSONObject(elementName);
        if (elementJson != null) {
            Map<String, Method> methods = RepositoryHelper.getSetters(element);
            WebObjectSpecification legacySpec = FormTemplateGenerator.getWebObjectSpecification(element);
            for (String key : elementJson.keySet()) {
                Object val = elementJson.get(key);
                if (val != null && methods.get(key) != null) {
                    Method method = methods.get(key);
                    Class<?> paramType = method.getParameterTypes()[0];
                    if (!paramType.isAssignableFrom(val.getClass()) && !(paramType.isPrimitive() && val instanceof Number)) {
                        PropertyDescription property = legacySpec.getProperty(key);
                        if (property != null && property.getType() instanceof IDesignValueConverter) {
                            val = ((IDesignValueConverter) property.getType()).fromDesignValue(val, property);
                        } else {
                            // will not fit, very likely a uuid that should be an int.
                            if (val != null) {
                                IPersist found = fs.searchPersist(val.toString());
                                if (found != null)
                                    val = Integer.valueOf(found.getID());
                            }
                        }
                    }
                }
                if (val instanceof JSONObject && ((AbstractBase) element).getProperty(key) instanceof JSONObject) {
                    // if both are json (like a nested form) then merge it in.
                    ServoyJSONObject.mergeAndDeepCloneJSON((JSONObject) val, (JSONObject) ((AbstractBase) element).getProperty(key));
                } else if (val instanceof String && StaticContentSpecLoader.PROPERTY_CUSTOMPROPERTIES.getPropertyName().equals(key) && ((AbstractBase) element).getCustomProperties() != null) {
                    // custom properties needs to be merged in..
                    JSONObject original = new ServoyJSONObject(((AbstractBase) element).getCustomProperties(), true);
                    ServoyJSONObject.mergeAndDeepCloneJSON(new ServoyJSONObject((String) val, true), original);
                    ((AbstractBase) element).setCustomProperties(ServoyJSONObject.toString(original, true, true, true));
                } else if (val instanceof JSONArray && ((AbstractBase) element).getProperty(key) instanceof IChildWebObject[]) {
                    IChildWebObject[] webObjectChildren = (IChildWebObject[]) ((AbstractBase) element).getProperty(key);
                    JSONArray original = new JSONArray();
                    for (IChildWebObject element2 : webObjectChildren) {
                        original.put(element2.getJson());
                    }
                    ServoyJSONObject.mergeAndDeepCloneJSON((JSONArray) val, original);
                    ((AbstractBase) element).setProperty(key, original);
                } else
                    ((AbstractBase) element).setProperty(key, val);
            }
        }
        element.setName(templateName);
        elements.add(element);
    }
    return elements;
}
Also used : IChildWebObject(com.servoy.j2db.persistence.IChildWebObject) WebObjectSpecification(org.sablo.specification.WebObjectSpecification) IDesignValueConverter(com.servoy.j2db.persistence.IDesignValueConverter) ArrayList(java.util.ArrayList) AbstractBase(com.servoy.j2db.persistence.AbstractBase) JSONArray(org.json.JSONArray) Method(java.lang.reflect.Method) PropertyDescription(org.sablo.specification.PropertyDescription) IFormElement(com.servoy.j2db.persistence.IFormElement) ServoyJSONObject(com.servoy.j2db.util.ServoyJSONObject) JSONObject(org.json.JSONObject) ServoyJSONObject(com.servoy.j2db.util.ServoyJSONObject) IPersist(com.servoy.j2db.persistence.IPersist) IBasicWebObject(com.servoy.j2db.persistence.IBasicWebObject) JSONObject(org.json.JSONObject) ServoyJSONObject(com.servoy.j2db.util.ServoyJSONObject) IChildWebObject(com.servoy.j2db.persistence.IChildWebObject) UUID(com.servoy.j2db.util.UUID)

Example 10 with UUID

use of com.servoy.j2db.util.UUID in project servoy-client by Servoy.

the class SQLSheet method convertObjectToValue.

Object convertObjectToValue(String dataProviderID, Object obj, IConverterManager<IColumnConverter> columnConverterManager, IColumnValidatorManager columnValidatorManager, IRowChangeListener record) {
    Object convertedValue = obj;
    int columnIndex = getColumnIndex(dataProviderID);
    VariableInfo variableInfo = getCalculationOrColumnVariableInfo(dataProviderID, columnIndex);
    if (columnIndex >= 0) {
        ConverterInfo converterInfo = getColumnConverterInfo(columnIndex);
        if (converterInfo != null) {
            IColumnConverter conv = columnConverterManager.getConverter(converterInfo.converterName);
            if (conv == null) {
                // $NON-NLS-1$
                throw new IllegalStateException(Messages.getString("servoy.error.converterNotFound", new Object[] { converterInfo.converterName }));
            }
            try {
                convertedValue = conv.convertFromObject(converterInfo.props, variableInfo.type, convertedValue);
            } catch (Exception e) {
                throw new IllegalArgumentException(// $NON-NLS-1$
                Messages.getString(// $NON-NLS-1$
                "servoy.record.error.settingDataprovider", new Object[] { dataProviderID, Column.getDisplayTypeString(variableInfo.type), convertedValue }), e);
            }
        }
        if (// $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
        Settings.getInstance().getProperty("servoy.execute.column.validators.only.on.validate_and_save", "true").equals("false")) {
            // the length check (also done in FoundsetManager.validate(record))
            int valueLen = Column.getObjectSize(convertedValue, variableInfo.type);
            if (// insufficient space to save value
            valueLen > 0 && variableInfo.length > 0 && valueLen > variableInfo.length) {
                throw new IllegalArgumentException(// $NON-NLS-1$
                Messages.getString(// $NON-NLS-1$
                "servoy.record.error.columnSizeTooSmall", new Object[] { dataProviderID, Integer.valueOf(variableInfo.length), convertedValue }));
            }
            // run the validators  (also done in FoundsetManager.validate(record))
            Pair<String, Map<String, String>> validatorInfo = getColumnValidatorInfo(columnIndex);
            if (validatorInfo != null) {
                IColumnValidator validator = columnValidatorManager.getValidator(validatorInfo.getLeft());
                if (validator == null) {
                    Debug.error("Column '" + dataProviderID + "' does have column validator  information, but either the validator '" + validatorInfo.getLeft() + "'  is not available, is the validator installed? (default default_validators.jar in the plugins) or the validator information is incorrect.");
                    // $NON-NLS-1$
                    throw new IllegalStateException(Messages.getString("servoy.error.validatorNotFound", new Object[] { validatorInfo.getLeft() }));
                }
                if (validator instanceof IColumnValidator2) {
                    JSRecordMarkers recordMarkers = new JSRecordMarkers(record instanceof IRecord ? (IRecord) record : null, application);
                    ((IColumnValidator2) validator).validate(validatorInfo.getRight(), convertedValue, dataProviderID, recordMarkers, null);
                    if (recordMarkers.isInvalid()) {
                        if (recordMarkers.getMarkers().length == 1) {
                            throw new IllegalArgumentException(recordMarkers.getMarkers()[0].getI18NMessage());
                        } else {
                            // $NON-NLS-1$
                            String msg = Messages.getString("servoy.record.error.validation", new Object[] { dataProviderID, convertedValue });
                            throw new IllegalArgumentException(msg);
                        }
                    }
                } else {
                    try {
                        validator.validate(validatorInfo.getRight(), convertedValue);
                    } catch (IllegalArgumentException e) {
                        // $NON-NLS-1$
                        String msg = Messages.getString("servoy.record.error.validation", new Object[] { dataProviderID, convertedValue });
                        if (e.getMessage() != null && e.getMessage().length() != 0)
                            msg += ' ' + e.getMessage();
                        throw new IllegalArgumentException(msg);
                    }
                }
            }
        }
        if ((variableInfo.flags & IBaseColumn.UUID_COLUMN) != 0) {
            // this is a UUID column, convert from UUID
            UUID uuid = Utils.getAsUUID(convertedValue, false);
            if (uuid != null) {
                switch(Column.mapToDefaultType(variableInfo.type)) {
                    case IColumnTypes.TEXT:
                        convertedValue = uuid.toString();
                        break;
                    case IColumnTypes.MEDIA:
                        convertedValue = uuid.toBytes();
                        break;
                }
            }
        }
    }
    if (variableInfo.type != IColumnTypes.MEDIA || (variableInfo.flags & IBaseColumn.UUID_COLUMN) != 0) {
        try {
            // dont use timezone here, should only be done in ui related stuff
            convertedValue = Column.getAsRightType(variableInfo.type, variableInfo.flags, convertedValue, null, variableInfo.length, null, true, true);
        } catch (Exception e) {
            Debug.error(e);
            throw new IllegalArgumentException(// $NON-NLS-1$
            Messages.getString(// $NON-NLS-1$
            "servoy.record.error.settingDataprovider", new Object[] { dataProviderID, Column.getDisplayTypeString(variableInfo.type), convertedValue }));
        }
    }
    return convertedValue;
}
Also used : ServoyException(com.servoy.j2db.util.ServoyException) IOException(java.io.IOException) RepositoryException(com.servoy.j2db.persistence.RepositoryException) UUID(com.servoy.j2db.util.UUID) HashMap(java.util.HashMap) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap)

Aggregations

UUID (com.servoy.j2db.util.UUID)23 RepositoryException (com.servoy.j2db.persistence.RepositoryException)6 RemoteException (java.rmi.RemoteException)5 ArrayList (java.util.ArrayList)5 HashMap (java.util.HashMap)5 Map (java.util.Map)5 JSONObject (org.json.JSONObject)5 IPersist (com.servoy.j2db.persistence.IPersist)4 ServoyException (com.servoy.j2db.util.ServoyException)4 ServoyJSONObject (com.servoy.j2db.util.ServoyJSONObject)4 IDataSet (com.servoy.j2db.dataprocessing.IDataSet)3 Form (com.servoy.j2db.persistence.Form)3 Date (java.util.Date)3 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)3 ApplicationException (com.servoy.j2db.ApplicationException)2 FlattenedSolution (com.servoy.j2db.FlattenedSolution)2 JSDataSet (com.servoy.j2db.dataprocessing.JSDataSet)2 AbstractBase (com.servoy.j2db.persistence.AbstractBase)2 ChangeHandler (com.servoy.j2db.persistence.ChangeHandler)2 ISupportChilds (com.servoy.j2db.persistence.ISupportChilds)2