@Override public void setProperties(Object bean, HttpServletRequest request) { Enumeration<String> enu = request.getParameterNames(); while (enu.hasMoreElements()) { String name = enu.nextElement(); String value = request.getParameter(name); BeanUtil.setPropertyForcedSilent(bean, name, value); if (name.endsWith("Month")) { String dateParam = name.substring(0, name.lastIndexOf("Month")); if (request.getParameter(dateParam) != null) { continue; } Class<?> propertyTypeClass = BeanUtil.getPropertyType(bean, dateParam); if ((propertyTypeClass == null) || !propertyTypeClass.equals(Date.class)) { continue; } Date date = getDate(dateParam, request); if (date != null) { BeanUtil.setPropertyForcedSilent(bean, dateParam, date); } } } }
/** Sets petite bean property. */ public void setBeanProperty(String name, Object value) { Object bean = null; int ndx = name.length(); while (true) { ndx = name.lastIndexOf('.', ndx); if (ndx == -1) { break; } String beanName = name.substring(0, ndx); bean = getBean(beanName); if (bean != null) { break; } ndx--; } if (bean == null) { throw new PetiteException("Invalid bean property: " + name); } try { BeanUtil.setDeclaredProperty(bean, name.substring(ndx + 1), value); } catch (Exception ex) { throw new PetiteException("Invalid bean property: " + name, ex); } }
@Override public void setProperty(Object bean, String param, Object value) { try { BeanUtil.setProperty(bean, param, value); } catch (Exception e) { _log.error(e, e); } }
/** Reads filter config parameters and set into destination target. */ protected void readFilterConfigParameters( FilterConfig filterConfig, Object target, String... parameters) { for (String parameter : parameters) { String value = filterConfig.getInitParameter(parameter); if (value != null) { BeanUtil.setDeclaredProperty(target, parameter, value); } } }
@Override public int getIntegerSilent(Object bean, String param, int defaultValue) { int beanValue = defaultValue; if (bean != null) { try { Object value = BeanUtil.getProperty(bean, param); beanValue = Convert.toIntValue(value, defaultValue); } catch (Exception e) { } } return beanValue; }
@Override public byte getByteSilent(Object bean, String param, byte defaultValue) { byte beanValue = defaultValue; if (bean != null) { try { Object value = BeanUtil.getProperty(bean, param); beanValue = Convert.toByteValue(value, defaultValue); } catch (Exception e) { } } return beanValue; }
@Override public long getLongSilent(Object bean, String param, long defaultValue) { long beanValue = defaultValue; if (bean != null) { try { Object value = BeanUtil.getProperty(bean, param); beanValue = Convert.toLongValue(value, defaultValue); } catch (Exception e) { } } return beanValue; }
@Override public short getShortSilent(Object bean, String param, short defaultValue) { short beanValue = defaultValue; if (bean != null) { try { Object value = BeanUtil.getProperty(bean, param); beanValue = Convert.toShortValue(value, defaultValue); } catch (Exception e) { } } return beanValue; }
@Override public boolean getBoolean(Object bean, String param, boolean defaultValue) { boolean beanValue = defaultValue; if (bean != null) { try { Object value = BeanUtil.getProperty(bean, param); beanValue = Convert.toBooleanValue(value, defaultValue); } catch (Exception e) { _log.error(e, e); } } return beanValue; }
/** Returns petite bean property value. */ public Object getBeanProperty(String name) { int ndx = name.indexOf('.'); if (ndx == -1) { throw new PetiteException("Only bean name is specified, missing property name: " + name); } String beanName = name.substring(0, ndx); Object bean = getBean(beanName); if (bean == null) { throw new PetiteException("Bean doesn't exist: " + name); } try { return BeanUtil.getDeclaredProperty(bean, name.substring(ndx + 1)); } catch (Exception ex) { throw new PetiteException("Invalid bean property: " + name, ex); } }
@Override public double getDouble(Object bean, String param, double defaultValue) { double beanValue = defaultValue; if (bean != null) { try { Object value = BeanUtil.getProperty(bean, param); beanValue = Convert.toDoubleValue(value, defaultValue); } catch (Exception e) { _log.error(e, e); } } return beanValue; }
@Override public String getString(Object bean, String param, String defaultValue) { String beanValue = defaultValue; if (bean != null) { try { Object value = BeanUtil.getProperty(bean, param); beanValue = Convert.toString(value, defaultValue); } catch (Exception e) { _log.error(e, e); } } return beanValue; }
@Override public float getFloat(Object bean, String param, float defaultValue) { float beanValue = defaultValue; if (bean != null) { try { Object value = BeanUtil.getProperty(bean, param); beanValue = Convert.toFloatValue(value, defaultValue); } catch (Exception e) { _log.error(e, e); } } return beanValue; }
@Override public void process(StringBuilder out) { if (isPreviousChunkOfType(CHUNK_TABLE)) { appendMissingSpace(out); } DbEntityDescriptor ded = tableRef != null ? lookupTableRef(tableRef) : lookupType(resolveClass(data)); out.append(SET); DbEntityColumnDescriptor[] decList = ded.getColumnDescriptors(); String typeName = StringUtil.uncapitalize(ded.getEntityName()); // String table = resolveTable(tableRef, ded); int size = 0; for (DbEntityColumnDescriptor dec : decList) { String property = dec.getPropertyName(); Object value = BeanUtil.getDeclaredProperty(data, property); if (includeColumns == COLS_ONLY_EXISTING) { if (DbOomUtil.isEmptyColumnValue(dec, value)) { continue; } } if (size > 0) { out.append(',').append(' '); } size++; // do not add table reference in set // as only one table can be updated // also, Postgress database does not allow it (see #JODD-21) // out.append(table).append('.'); out.append(dec.getColumnName()).append('='); String propertyName = typeName + '.' + property; defineParameter(out, propertyName, value, dec); } if (size > 0) { out.append(' '); } }
@Override public T from(Map<String, Object> from) { try { T instance = type.newInstance(); for (Map.Entry<String, Object> entry : from.entrySet()) { String field = metadata.getDecodedFieldName(entry.getKey()); BeanUtil.setDeclaredPropertyForcedSilent(instance, field, entry.getValue()); } return instance; } catch (Exception e) { throw new SearchException( e, "Failed to create a new instance of %s for search results: %s", type.getName(), e.getMessage()); } }
@Override public Class<?> getObjectTypeSilent(Object bean, String param, Class<?> defaultValue) { Class<?> beanType = null; if (bean != null) { try { beanType = BeanUtil.getPropertyType(bean, param); } catch (Exception e) { } } if (beanType == null) { return defaultValue; } else { return beanType; } }
@Override public Object getObjectSilent(Object bean, String param, Object defaultValue) { Object beanValue = null; if (bean != null) { try { beanValue = BeanUtil.getProperty(bean, param); } catch (Exception e) { } } if (beanValue == null) { return defaultValue; } else { return beanValue; } }
/** Injects all parameters. */ protected void injectParams(Object bean, BeanDefinition def) { if (def.name == null) { return; } if (def.params == null) { def.params = resolveBeanParams(def.name, petiteConfig.getResolveReferenceParameters()); } int len = def.name.length() + 1; for (String param : def.params) { Object value = getParameter(param); String destination = param.substring(len); try { BeanUtil.setDeclaredProperty(bean, destination, value); } catch (Exception ex) { throw new PetiteException( "Unable to set parameter: '" + param + "' to bean: " + def.name, ex); } } }
protected SyncDLObject updateFileEntries( ZipReader zipReader, String zipFileId, JSONWebServiceActionParametersMap jsonWebServiceActionParametersMap) throws Exception { ServiceContext serviceContext = new ServiceContext(); List<NameValue<String, Object>> innerParameters = jsonWebServiceActionParametersMap.getInnerParameters("serviceContext"); if (innerParameters != null) { for (NameValue<String, Object> innerParameter : innerParameters) { try { BeanUtil.setProperty(serviceContext, innerParameter.getName(), innerParameter.getValue()); } catch (Exception e) { if (_log.isDebugEnabled()) { _log.debug(e.getMessage(), e); } } } } String urlPath = MapUtil.getString(jsonWebServiceActionParametersMap, "urlPath"); if (urlPath.endsWith("/add-file-entry")) { long repositoryId = MapUtil.getLong(jsonWebServiceActionParametersMap, "repositoryId"); long folderId = MapUtil.getLong(jsonWebServiceActionParametersMap, "folderId"); String sourceFileName = MapUtil.getString(jsonWebServiceActionParametersMap, "sourceFileName"); String mimeType = MapUtil.getString(jsonWebServiceActionParametersMap, "mimeType"); String title = MapUtil.getString(jsonWebServiceActionParametersMap, "title"); String description = MapUtil.getString(jsonWebServiceActionParametersMap, "description"); String changeLog = MapUtil.getString(jsonWebServiceActionParametersMap, "changeLog"); InputStream inputStream = zipReader.getEntryAsInputStream(zipFileId); File tempFile = null; try { tempFile = FileUtil.createTempFile(inputStream); String checksum = MapUtil.getString(jsonWebServiceActionParametersMap, "checksum"); return addFileEntry( repositoryId, folderId, sourceFileName, mimeType, title, description, changeLog, tempFile, checksum, serviceContext); } finally { FileUtil.delete(tempFile); } } else if (urlPath.endsWith("/add-folder")) { long repositoryId = MapUtil.getLong(jsonWebServiceActionParametersMap, "repositoryId"); long parentFolderId = MapUtil.getLong(jsonWebServiceActionParametersMap, "parentFolderId"); String name = MapUtil.getString(jsonWebServiceActionParametersMap, "name"); String description = MapUtil.getString(jsonWebServiceActionParametersMap, "description"); return addFolder(repositoryId, parentFolderId, name, description, serviceContext); } else if (urlPath.endsWith("/move-file-entry")) { long fileEntryId = MapUtil.getLong(jsonWebServiceActionParametersMap, "fileEntryId"); long newFolderId = MapUtil.getLong(jsonWebServiceActionParametersMap, "newFolderId"); return moveFileEntry(fileEntryId, newFolderId, serviceContext); } else if (urlPath.endsWith("/move-file-entry-to-trash")) { long fileEntryId = MapUtil.getLong(jsonWebServiceActionParametersMap, "fileEntryId"); return moveFileEntryToTrash(fileEntryId); } else if (urlPath.endsWith("/move-folder")) { long folderId = MapUtil.getLong(jsonWebServiceActionParametersMap, "folderId"); long parentFolderId = MapUtil.getLong(jsonWebServiceActionParametersMap, "parentFolderId"); return moveFolder(folderId, parentFolderId, serviceContext); } else if (urlPath.endsWith("/move-folder-to-trash")) { long folderId = MapUtil.getLong(jsonWebServiceActionParametersMap, "folderId"); return moveFolderToTrash(folderId); } else if (urlPath.endsWith("/patch-file-entry")) { long fileEntryId = MapUtil.getLong(jsonWebServiceActionParametersMap, "fileEntryId"); long sourceVersionId = MapUtil.getLong(jsonWebServiceActionParametersMap, "sourceVersionId"); String sourceFileName = MapUtil.getString(jsonWebServiceActionParametersMap, "sourceFileName"); String mimeType = MapUtil.getString(jsonWebServiceActionParametersMap, "mimeType"); String title = MapUtil.getString(jsonWebServiceActionParametersMap, "title"); String description = MapUtil.getString(jsonWebServiceActionParametersMap, "description"); String changeLog = MapUtil.getString(jsonWebServiceActionParametersMap, "changeLog"); boolean majorVersion = MapUtil.getBoolean(jsonWebServiceActionParametersMap, "majorVersion"); InputStream inputStream = zipReader.getEntryAsInputStream(zipFileId); File tempFile = null; try { tempFile = FileUtil.createTempFile(inputStream); String checksum = MapUtil.getString(jsonWebServiceActionParametersMap, "checksum"); return patchFileEntry( fileEntryId, sourceVersionId, sourceFileName, mimeType, title, description, changeLog, majorVersion, tempFile, checksum, serviceContext); } finally { FileUtil.delete(tempFile); } } else if (urlPath.endsWith("/update-file-entry")) { long fileEntryId = MapUtil.getLong(jsonWebServiceActionParametersMap, "fileEntryId"); String sourceFileName = MapUtil.getString(jsonWebServiceActionParametersMap, "sourceFileName"); String mimeType = MapUtil.getString(jsonWebServiceActionParametersMap, "mimeType"); String title = MapUtil.getString(jsonWebServiceActionParametersMap, "title"); String description = MapUtil.getString(jsonWebServiceActionParametersMap, "description"); String changeLog = MapUtil.getString(jsonWebServiceActionParametersMap, "changeLog"); boolean majorVersion = MapUtil.getBoolean(jsonWebServiceActionParametersMap, "majorVersion"); File tempFile = null; try { InputStream inputStream = zipReader.getEntryAsInputStream(zipFileId); if (inputStream != null) { tempFile = FileUtil.createTempFile(inputStream); } String checksum = MapUtil.getString(jsonWebServiceActionParametersMap, "checksum"); return updateFileEntry( fileEntryId, sourceFileName, mimeType, title, description, changeLog, majorVersion, tempFile, checksum, serviceContext); } finally { FileUtil.delete(tempFile); } } else if (urlPath.endsWith("/update-folder")) { long folderId = MapUtil.getLong(jsonWebServiceActionParametersMap, "folderId"); String name = MapUtil.getString(jsonWebServiceActionParametersMap, "name"); String description = MapUtil.getString(jsonWebServiceActionParametersMap, "description"); return updateFolder(folderId, name, description, serviceContext); } return null; }
@Override public void setPropertySilent(Object bean, String param, Object value) { BeanUtil.setPropertyForcedSilent(bean, param, value); }