private UserPrefDO createUserPref(final PFUserDO user, final UserPrefArea area, final String name) { UserPrefDO userPref = new UserPrefDO(); userPref.setUser(user); userPref.setArea(area); userPref.setName(name); return userPref; } }
/** * Copies all values from the given src object excluding the values created and modified. Null values will be * excluded. * * @param src */ @Override public ModificationStatus copyValuesFrom(final BaseDO<? extends Serializable> source, final String... ignoreFields) { ModificationStatus modificationStatus = super.copyValuesFrom(source, ignoreFields); final UserPrefDO src = (UserPrefDO) source; if (src.getUserPrefEntries() != null) { for (final UserPrefEntryDO srcEntry : src.getUserPrefEntries()) { final UserPrefEntryDO destEntry = ensureAndGetAccessEntry(srcEntry.getParameter()); final ModificationStatus st = destEntry.copyValuesFrom(srcEntry); modificationStatus = getModificationStatus(modificationStatus, st); } final Iterator<UserPrefEntryDO> iterator = getUserPrefEntries().iterator(); while (iterator.hasNext()) { final UserPrefEntryDO destEntry = iterator.next(); if (src.getUserPrefEntry(destEntry.getParameter()) == null) { iterator.remove(); } } } return modificationStatus; }
@Override public void validate(final IValidatable<String> validatable) { if (data.getArea() == null) { return; } final String value = validatable.getValue(); if (parentPage.userPrefDao.doesParameterNameAlreadyExist(data.getId(), data.getUser(), data.getArea(), value)) { name.error(getString("userPref.error.nameDoesAlreadyExist")); } } });
public UserPrefEntryDO ensureAndGetAccessEntry(final String parameter) { if (this.prefEntries == null) { setUserPrefEntries(new TreeSet<UserPrefEntryDO>()); } UserPrefEntryDO entry = getUserPrefEntry(parameter); if (entry == null) { entry = new UserPrefEntryDO(); entry.setParameter(parameter); this.addUserPrefEntry(entry); } return entry; }
if (data.getArea() == null) { log.warn("Could not create ParameterRepeater because UserPrefArea is not given."); return; if (isNew() == true && data.getUserPrefEntries() == null) { parentPage.userPrefDao.addUserPrefParameters(data, data.getArea()); if (data.getUserPrefEntries() != null) { for (final UserPrefEntryDO param : data.getSortedUserPrefEntries()) { final FieldsetPanel fs = gridBuilder .newFieldset(param.getI18nKey() != null ? getString(param.getI18nKey()) : param.getParameter()) param, "valueAsObject"), parentPage, param.getParameter()); if (data.getArea() == UserPrefArea.USER_FAVORITE) { userSelectPanel.setShowFavorites(false); "valueAsObject"), parentPage, param.getParameter()); if (data.getArea() == UserPrefArea.TASK_FAVORITE) { taskSelectPanel.setShowFavorites(false); groupSelectPanel.init(); } else if (Kost2DO.class.isAssignableFrom(param.getType()) == true) { final UserPrefEntryDO taskParam = data.getUserPrefEntry(param.getDependsOn()); Integer taskId = null; if (taskParam == null) { userPrefDao, param, "valueAsObject"),
assertFalse(userPrefDao.doesParameterNameAlreadyExist((Integer) id, user, UserPrefArea.TIMESHEET_TEMPLATE, "test")); userPref = userPrefDao.getById(id); assertEquals(5, userPref.getUserPrefEntries().size()); // user, task, kost2, location, description. final Iterator<UserPrefEntryDO> it = userPref.getSortedUserPrefEntries().iterator(); UserPrefEntryDO entry = it.next(); assertUserPrefEntry(entry, "user", PFUserDO.class, user2.getId().toString(), "user", null, "1"); assertEquals("Micromata", timesheet.getLocation()); assertEquals("Wrote a test case...", timesheet.getDescription()); userPref.getUserPrefEntry("location").setValue("At home"); userPrefDao.update(userPref); String[] names = userPrefDao.getPrefNames(UserPrefArea.TIMESHEET_TEMPLATE); assertEquals("test", names[0]); List<UserPrefEntryDO> dependents = userPref .getDependentUserPrefEntries(userPref.getUserPrefEntry("user").getParameter()); assertNull(dependents); dependents = userPref.getDependentUserPrefEntries(userPref.getUserPrefEntry("task").getParameter()); assertEquals(1, dependents.size()); assertEquals("kost2", dependents.get(0).getParameter());
@Override public void clearIds() { super.clearIds(); for (final UserPrefEntryDO entry : form.getData().getUserPrefEntries()) { entry.setId(null); } }
private UserPrefDO initUserPref(final UserPrefDO userPref, final UserPrefArea area, final Object object) { userPref.setArea(area); userPref.setUser(ThreadLocalUserContext.getUser()); if (object != null) { userPrefDao.addUserPrefParameters(userPref, object); } else { userPrefDao.addUserPrefParameters(userPref, area); } return userPref; }
@Override public UserPrefDO newInstance() { return new UserPrefDO(); }
@Transient public String getUserPrefEntryAsString(final String parameter) { final UserPrefEntryDO entry = getUserPrefEntry(parameter); if (entry == null) { return null; } return entry.getValue(); }
private void evaluateAnnotations(final UserPrefDO userPref, final Class<?> beanType) { if (userPref.getUserPrefEntries() == null) { return; } final Field[] fields = beanType.getDeclaredFields(); int no = 0; for (final Field field : fields) { if (field.isAnnotationPresent(UserPrefParameter.class) == true) { UserPrefEntryDO userPrefEntry = null; for (final UserPrefEntryDO entry : userPref.getUserPrefEntries()) { if (field.getName().equals(entry.getParameter()) == true) { userPrefEntry = entry; break; } } if (userPrefEntry == null) { userPrefEntry = new UserPrefEntryDO(); evaluateAnnotation(userPrefEntry, beanType, field); userPref.addUserPrefEntry(userPrefEntry); } else { evaluateAnnotation(userPrefEntry, beanType, field); } if (StringUtils.isBlank(userPrefEntry.orderString) == true) { userPrefEntry.orderString = "ZZZ" + StringHelper.format2DigitNumber(no++); } userPrefEntry.setParameter(field.getName()); } } }
@Override public boolean isVisible() { // Show area only if given, otherwise the drop down choice for area is shown. return data.getArea() == null; } };
/** * @see org.projectforge.web.wicket.CellItemListenerPropertyColumn#populateItem(org.apache.wicket.markup.repeater.Item, * java.lang.String, org.apache.wicket.model.IModel) */ @Override public void populateItem(final Item<ICellPopulator<UserPrefDO>> item, final String componentId, final IModel<UserPrefDO> rowModel) { final UserPrefDO userPref = rowModel.getObject(); final String label; if (userPref.getArea() != null) { label = getString(userPref.getArea().getI18nKey()); } else { label = ""; } item.add(new ListSelectActionPanel(componentId, rowModel, UserPrefEditPage.class, userPref.getId(), UserPrefListPage.this, label)); cellItemListener.populateItem(item, componentId, rowModel); addRowClick(item); } });
/** * @see org.projectforge.framework.persistence.api.BaseDao#hasAccess(Object, OperationType) */ @Override public boolean hasAccess(final PFUserDO user, final UserPrefDO obj, final UserPrefDO oldObj, final OperationType operationType, final boolean throwException) { if (accessChecker.userEquals(user, obj.getUser()) == true) { return true; } if (throwException == true) { throw new AccessException("userPref.error.userIsNotOwner"); } else { return false; } }
private void setValue(final UserPrefEntryDO param, final Object value) { userPrefDao.setValueObject(param, value); final List<UserPrefEntryDO> dependents = getData().getDependentUserPrefEntries(param.getParameter()); if (dependents != null) { for (final UserPrefEntryDO entry : dependents) { if (Kost2DO.class.isAssignableFrom(entry.getType()) == true) { final Kost2DropDownChoice choice = (Kost2DropDownChoice) form.dependentsMap.get(entry.getParameter()); choice.setTaskId((Integer) value); } } } }
final Field[] fields = obj.getClass().getDeclaredFields(); AccessibleObject.setAccessible(fields, true); if (userPref.getUserPrefEntries() != null) { for (final UserPrefEntryDO entry : userPref.getUserPrefEntries()) { Field field = null; for (final Field f : fields) {
/** * Creates a template of the given object for the given area. * @param area * @param object Master object to fill the UserPrefDO from. * @see UserPrefDao#addUserPrefParameters(UserPrefDO, Object) */ public UserPrefEditPage(final UserPrefArea area, final Object object) { super(new PageParameters(), "userPref"); final UserPrefDO userPref = new UserPrefDO(); initUserPref(userPref, area, object); super.init(userPref); }
/** * @see org.projectforge.web.fibu.ISelectCallerPage#select(java.lang.String, java.lang.Integer) */ public void select(final String property, final Object selectedValue) { final UserPrefEntryDO param = getData().getUserPrefEntry(property); if (param == null) { log.error("Property '" + property + "' not supported for selection."); } else { setValue(param, selectedValue); } }
@Override public boolean isVisible() { // Show area only if given, otherwise the drop down choice for area is shown. return data.getArea() != null; } }.suppressLabelForWarning();