List of usage examples for org.springframework.util ReflectionUtils findField
@Nullable public static Field findField(Class<?> clazz, String name)
From source file:org.apache.syncope.client.console.panels.AnyObjectSearchResultPanel.java
@Override protected List<IColumn<AnyObjectTO, String>> getColumns() { final List<IColumn<AnyObjectTO, String>> columns = new ArrayList<>(); for (String name : prefMan.getList(getRequest(), String.format(Constants.PREF_ANY_OBJECT_DETAILS_VIEW, type))) { final Field field = ReflectionUtils.findField(AnyObjectTO.class, name); if ("token".equalsIgnoreCase(name)) { columns.add(new PropertyColumn<AnyObjectTO, String>(new ResourceModel(name, name), name, name)); } else if (field != null && field.getType().equals(Date.class)) { columns.add(new PropertyColumn<AnyObjectTO, String>(new ResourceModel(name, name), name, name)); } else {/*from w ww.j a va2 s. c o m*/ columns.add(new PropertyColumn<AnyObjectTO, String>(new ResourceModel(name, name), name, name)); } } for (String name : prefMan.getList(getRequest(), String.format(Constants.PREF_ANY_OBJECT_PLAIN_ATTRS_VIEW, type))) { if (pSchemaNames.contains(name)) { columns.add(new AttrColumn<AnyObjectTO>(name, SchemaType.PLAIN)); } } for (String name : prefMan.getList(getRequest(), String.format(Constants.PREF_ANY_OBJECT_DER_ATTRS_VIEW, type))) { if (dSchemaNames.contains(name)) { columns.add(new AttrColumn<AnyObjectTO>(name, SchemaType.DERIVED)); } } // Add defaults in case of no selection if (columns.isEmpty()) { for (String name : AnyObjectDisplayAttributesModalPage.ANY_OBJECT_DEFAULT_SELECTION) { columns.add(new PropertyColumn<AnyObjectTO, String>(new ResourceModel(name, name), name, name)); } } columns.add(new ActionColumn<AnyObjectTO, String>(new ResourceModel("actions", "")) { private static final long serialVersionUID = -3503023501954863131L; @Override public ActionLinksPanel<AnyObjectTO> getActions(final String componentId, final IModel<AnyObjectTO> model) { final ActionLinksPanel.Builder<AnyObjectTO> panel = ActionLinksPanel .builder(page.getPageReference()); panel.add(new ActionLink<AnyObjectTO>() { private static final long serialVersionUID = -7978723352517770645L; @Override public void onClick(final AjaxRequestTarget target, final AnyObjectTO ignore) { final IModel<AnyHandler<AnyObjectTO>> formModel = new CompoundPropertyModel<>( new AnyHandler<>(model.getObject())); altDefaultModal.setFormModel(formModel); target.add(altDefaultModal.setContent(new StatusModal<AnyObjectTO>(altDefaultModal, pageRef, formModel.getObject().getInnerObject(), false))); altDefaultModal.header(new Model<>( getString("any.edit", new Model<>(new AnyHandler<>(model.getObject()))))); altDefaultModal.show(true); } }, ActionLink.ActionType.MANAGE_RESOURCES, StandardEntitlement.USER_READ) .add(new ActionLink<AnyObjectTO>() { private static final long serialVersionUID = -7978723352517770644L; @Override public void onClick(final AjaxRequestTarget target, final AnyObjectTO ignore) { send(AnyObjectSearchResultPanel.this, Broadcast.EXACT, new AjaxWizard.EditItemActionEvent<>( new AnyHandler<>( new AnyObjectRestClient().read(model.getObject().getKey())), target)); } }, ActionLink.ActionType.EDIT, String.format("%s_%s", type, AnyEntitlement.READ)) .add(new ActionLink<AnyObjectTO>() { private static final long serialVersionUID = -7978723352517770645L; @Override public void onClick(final AjaxRequestTarget target, final AnyObjectTO ignore) { final AnyObjectTO clone = SerializationUtils.clone(model.getObject()); clone.setKey(0L); send(AnyObjectSearchResultPanel.this, Broadcast.EXACT, new AjaxWizard.NewItemActionEvent<>(new AnyHandler<>(clone), target)); } }, ActionLink.ActionType.CLONE, StandardEntitlement.USER_CREATE) .add(new ActionLink<AnyObjectTO>() { private static final long serialVersionUID = -7978723352517770646L; @Override public void onClick(final AjaxRequestTarget target, final AnyObjectTO ignore) { try { restClient.delete(model.getObject().getETagValue(), model.getObject().getKey()); info(getString(Constants.OPERATION_SUCCEEDED)); target.add(container); } catch (SyncopeClientException e) { LOG.error("While deleting object {}", model.getObject().getKey(), e); error(getString(Constants.ERROR) + ": " + e.getMessage()); } SyncopeConsoleSession.get().getNotificationPanel().refresh(target); } }, ActionLink.ActionType.DELETE, String.format("%s_%s", type, AnyEntitlement.DELETE)); return panel.build(componentId, model.getObject()); } @Override public ActionLinksPanel<Serializable> getHeader(final String componentId) { final ActionLinksPanel.Builder<Serializable> panel = ActionLinksPanel .builder(page.getPageReference()); panel.add(new ActionLink<Serializable>() { private static final long serialVersionUID = -7978723352517770644L; @Override public void onClick(final AjaxRequestTarget target, final Serializable ignore) { // still missing content target.add(modal.setContent(new AnyObjectDisplayAttributesModalPage<>(modal, page.getPageReference(), pSchemaNames, dSchemaNames, type))); modal.header(new ResourceModel("any.attr.display", "")); modal.show(true); } }, ActionLink.ActionType.CHANGE_VIEW, String.format("%s_%s", type, AnyEntitlement.READ)) .add(new ActionLink<Serializable>() { private static final long serialVersionUID = -7978723352517770644L; @Override public void onClick(final AjaxRequestTarget target, final Serializable ignore) { if (target != null) { target.add(container); } } }, ActionLink.ActionType.RELOAD, String.format("%s_%s", type, AnyEntitlement.SEARCH)); return panel.build(componentId); } }); return columns; }
From source file:org.apache.syncope.client.console.panels.BeanPanel.java
public BeanPanel(final String id, final IModel<T> bean, final Map<String, Pair<AbstractFiqlSearchConditionBuilder, List<SearchClause>>> sCondWrapper, final String... excluded) { super(id, bean); setOutputMarkupId(true);/* ww w.j a v a 2 s . com*/ this.sCondWrapper = sCondWrapper; this.excluded = new ArrayList<>(Arrays.asList(excluded)); this.excluded.add("serialVersionUID"); this.excluded.add("class"); final LoadableDetachableModel<List<String>> model = new LoadableDetachableModel<List<String>>() { private static final long serialVersionUID = 5275935387613157437L; @Override protected List<String> load() { final List<String> result = new ArrayList<>(); if (BeanPanel.this.getDefaultModelObject() != null) { ReflectionUtils.doWithFields(BeanPanel.this.getDefaultModelObject().getClass(), new FieldCallback() { public void doWith(final Field field) throws IllegalArgumentException, IllegalAccessException { result.add(field.getName()); } }, new FieldFilter() { public boolean matches(final Field field) { return !BeanPanel.this.excluded.contains(field.getName()); } }); } return result; } }; add(new ListView<String>("propView", model) { private static final long serialVersionUID = 9101744072914090143L; @SuppressWarnings({ "unchecked", "rawtypes" }) @Override protected void populateItem(final ListItem<String> item) { final String fieldName = item.getModelObject(); item.add(new Label("fieldName", new ResourceModel(fieldName, fieldName))); Field field = ReflectionUtils.findField(bean.getObject().getClass(), fieldName); if (field == null) { return; } final SearchCondition scondAnnot = field.getAnnotation(SearchCondition.class); final Schema schemaAnnot = field.getAnnotation(Schema.class); BeanWrapper wrapper = PropertyAccessorFactory.forBeanPropertyAccess(bean.getObject()); Panel panel; if (scondAnnot != null) { final String fiql = (String) wrapper.getPropertyValue(fieldName); final List<SearchClause> clauses; if (StringUtils.isEmpty(fiql)) { clauses = new ArrayList<>(); } else { clauses = SearchUtils.getSearchClauses(fiql); } final AbstractFiqlSearchConditionBuilder builder; switch (scondAnnot.type()) { case "USER": panel = new UserSearchPanel.Builder(new ListModel<>(clauses)).required(false) .build("value"); builder = SyncopeClient.getUserSearchConditionBuilder(); break; case "GROUP": panel = new GroupSearchPanel.Builder(new ListModel<>(clauses)).required(false) .build("value"); builder = SyncopeClient.getGroupSearchConditionBuilder(); break; default: panel = new AnyObjectSearchPanel.Builder(scondAnnot.type(), new ListModel<>(clauses)) .required(false).build("value"); builder = SyncopeClient.getAnyObjectSearchConditionBuilder(null); } if (BeanPanel.this.sCondWrapper != null) { BeanPanel.this.sCondWrapper.put(fieldName, Pair.of(builder, clauses)); } } else if (List.class.equals(field.getType())) { Class<?> listItemType = String.class; if (field.getGenericType() instanceof ParameterizedType) { listItemType = (Class<?>) ((ParameterizedType) field.getGenericType()) .getActualTypeArguments()[0]; } if (listItemType.equals(String.class) && schemaAnnot != null) { SchemaRestClient schemaRestClient = new SchemaRestClient(); final List<AbstractSchemaTO> choices = new ArrayList<>(); for (SchemaType type : schemaAnnot.type()) { switch (type) { case PLAIN: choices.addAll( schemaRestClient.getSchemas(SchemaType.PLAIN, schemaAnnot.anyTypeKind())); break; case DERIVED: choices.addAll( schemaRestClient.getSchemas(SchemaType.DERIVED, schemaAnnot.anyTypeKind())); break; case VIRTUAL: choices.addAll( schemaRestClient.getSchemas(SchemaType.VIRTUAL, schemaAnnot.anyTypeKind())); break; default: } } panel = new AjaxPalettePanel.Builder<>().setName(fieldName) .build("value", new PropertyModel<>(bean.getObject(), fieldName), new ListModel<>( choices.stream().map(EntityTO::getKey).collect(Collectors.toList()))) .hideLabel(); } else if (listItemType.isEnum()) { panel = new AjaxPalettePanel.Builder<>().setName(fieldName) .build("value", new PropertyModel<>(bean.getObject(), fieldName), new ListModel(Arrays.asList(listItemType.getEnumConstants()))) .hideLabel(); } else { panel = new MultiFieldPanel.Builder<>(new PropertyModel<>(bean.getObject(), fieldName)) .build("value", fieldName, buildSinglePanel(bean.getObject(), field.getType(), fieldName, "panel")) .hideLabel(); } } else { panel = buildSinglePanel(bean.getObject(), field.getType(), fieldName, "value").hideLabel(); } item.add(panel.setRenderBodyOnly(true)); } }.setReuseItems(true).setOutputMarkupId(true)); }
From source file:org.apache.syncope.client.console.panels.GroupSearchResultPanel.java
@Override protected List<IColumn<GroupTO, String>> getColumns() { final List<IColumn<GroupTO, String>> columns = new ArrayList<>(); for (String name : prefMan.getList(getRequest(), Constants.PREF_GROUP_DETAILS_VIEW)) { final Field field = ReflectionUtils.findField(GroupTO.class, name); if ("token".equalsIgnoreCase(name)) { columns.add(new PropertyColumn<GroupTO, String>(new ResourceModel(name, name), name, name)); } else if (field != null && field.getType().equals(Date.class)) { columns.add(new PropertyColumn<GroupTO, String>(new ResourceModel(name, name), name, name)); } else {/*from w ww. j a v a 2 s . c o m*/ columns.add(new PropertyColumn<GroupTO, String>(new ResourceModel(name, name), name, name)); } } for (String name : prefMan.getList(getRequest(), Constants.PREF_GROUP_PLAIN_ATTRS_VIEW)) { if (pSchemaNames.contains(name)) { columns.add(new AttrColumn<GroupTO>(name, SchemaType.PLAIN)); } } for (String name : prefMan.getList(getRequest(), Constants.PREF_GROUP_DER_ATTRS_VIEW)) { if (dSchemaNames.contains(name)) { columns.add(new AttrColumn<GroupTO>(name, SchemaType.DERIVED)); } } // Add defaults in case of no selection if (columns.isEmpty()) { for (String name : GroupDisplayAttributesModalPage.GROUP_DEFAULT_SELECTION) { columns.add(new PropertyColumn<GroupTO, String>(new ResourceModel(name, name), name, name)); } prefMan.setList(getRequest(), getResponse(), Constants.PREF_GROUP_DETAILS_VIEW, Arrays.asList(GroupDisplayAttributesModalPage.GROUP_DEFAULT_SELECTION)); } columns.add(new ActionColumn<GroupTO, String>(new ResourceModel("actions", "")) { private static final long serialVersionUID = -3503023501954863131L; @Override public ActionLinksPanel<GroupTO> getActions(final String componentId, final IModel<GroupTO> model) { final ActionLinksPanel.Builder<GroupTO> panel = ActionLinksPanel.builder(page.getPageReference()); panel.add(new ActionLink<GroupTO>() { private static final long serialVersionUID = -7978723352517770645L; @Override public void onClick(final AjaxRequestTarget target, final GroupTO ignore) { final IModel<AnyHandler<GroupTO>> formModel = new CompoundPropertyModel<>( new AnyHandler<>(model.getObject())); altDefaultModal.setFormModel(formModel); target.add(altDefaultModal.setContent(new StatusModal<GroupTO>(altDefaultModal, pageRef, formModel.getObject().getInnerObject(), false))); altDefaultModal.header(new Model<>( getString("any.edit", new Model<>(new AnyHandler<>(model.getObject()))))); altDefaultModal.show(true); } }, ActionLink.ActionType.MANAGE_RESOURCES, StandardEntitlement.USER_READ) .add(new ActionLink<GroupTO>() { private static final long serialVersionUID = -7978723352517770644L; @Override public void onClick(final AjaxRequestTarget target, final GroupTO ignore) { send(GroupSearchResultPanel.this, Broadcast.EXACT, new AjaxWizard.EditItemActionEvent<>( new GroupHandler( new GroupRestClient().read(model.getObject().getKey())), target)); } }, ActionLink.ActionType.EDIT, StandardEntitlement.GROUP_READ) .add(new ActionLink<GroupTO>() { private static final long serialVersionUID = -7978723352517770644L; @Override public void onClick(final AjaxRequestTarget target, final GroupTO ignore) { final GroupTO clone = SerializationUtils.clone(model.getObject()); clone.setKey(0L); send(GroupSearchResultPanel.this, Broadcast.EXACT, new AjaxWizard.NewItemActionEvent<>(new GroupHandler(clone), target)); } }, ActionLink.ActionType.CLONE, StandardEntitlement.GROUP_CREATE) .add(new ActionLink<GroupTO>() { private static final long serialVersionUID = -7978723352517770644L; @Override public void onClick(final AjaxRequestTarget target, final GroupTO ignore) { try { restClient.delete(model.getObject().getETagValue(), model.getObject().getKey()); info(getString(Constants.OPERATION_SUCCEEDED)); target.add(container); } catch (SyncopeClientException e) { error(getString(Constants.ERROR) + ": " + e.getMessage()); LOG.error("While deleting object {}", model.getObject().getKey(), e); } SyncopeConsoleSession.get().getNotificationPanel().refresh(target); } }, ActionLink.ActionType.DELETE, StandardEntitlement.GROUP_DELETE); return panel.build(componentId); } @Override public ActionLinksPanel<Serializable> getHeader(final String componentId) { final ActionLinksPanel.Builder<Serializable> panel = ActionLinksPanel .builder(page.getPageReference()); return panel.add(new ActionLink<Serializable>() { private static final long serialVersionUID = -7978723352517770644L; @Override public void onClick(final AjaxRequestTarget target, final Serializable ignore) { target.add(modal.setContent(new GroupDisplayAttributesModalPage<>(modal, page.getPageReference(), pSchemaNames, dSchemaNames))); modal.header(new ResourceModel("any.attr.display", "")); modal.show(true); } }, ActionLink.ActionType.CHANGE_VIEW, StandardEntitlement.GROUP_READ) .add(new ActionLink<Serializable>() { private static final long serialVersionUID = -7978723352517770644L; @Override public void onClick(final AjaxRequestTarget target, final Serializable ignore) { if (target != null) { target.add(container); } } }, ActionLink.ActionType.RELOAD, StandardEntitlement.GROUP_SEARCH).build(componentId); } }); return columns; }
From source file:org.apache.syncope.client.console.panels.SchemaTypePanel.java
@Override protected List<IColumn<AbstractSchemaTO, String>> getColumns() { final List<IColumn<AbstractSchemaTO, String>> columns = new ArrayList<>(); for (final String field : COL_NAMES.get(schemaType)) { final Field clazzField = ReflectionUtils.findField(schemaType.getToClass(), field); if (clazzField != null) { if (clazzField.getType().equals(Boolean.class) || clazzField.getType().equals(boolean.class)) { columns.add(new BooleanPropertyColumn<>(new ResourceModel(field), field, field)); } else { final IColumn<AbstractSchemaTO, String> column = new PropertyColumn<AbstractSchemaTO, String>( new ResourceModel(field), field, field) { private static final long serialVersionUID = 3282547854226892169L; @Override/*from w w w . j a v a 2 s . c o m*/ public String getCssClass() { String css = super.getCssClass(); if ("key".equals(field)) { css = StringUtils.isBlank(css) ? "col-xs-1" : css + " col-xs-1"; } return css; } }; columns.add(column); } } } return columns; }
From source file:org.apache.syncope.client.console.panels.UserSearchResultPanel.java
@Override protected List<IColumn<UserTO, String>> getColumns() { final List<IColumn<UserTO, String>> columns = new ArrayList<>(); for (String name : prefMan.getList(getRequest(), Constants.PREF_USERS_DETAILS_VIEW)) { final Field field = ReflectionUtils.findField(UserTO.class, name); if ("token".equalsIgnoreCase(name)) { columns.add(new PropertyColumn<UserTO, String>(new ResourceModel(name, name), name, name)); } else if (field != null && field.getType().equals(Date.class)) { columns.add(new PropertyColumn<UserTO, String>(new ResourceModel(name, name), name, name)); } else {/*from ww w .ja va 2 s .com*/ columns.add(new PropertyColumn<UserTO, String>(new ResourceModel(name, name), name, name)); } } for (String name : prefMan.getList(getRequest(), Constants.PREF_USERS_PLAIN_ATTRS_VIEW)) { if (pSchemaNames.contains(name)) { columns.add(new AttrColumn<UserTO>(name, SchemaType.PLAIN)); } } for (String name : prefMan.getList(getRequest(), Constants.PREF_USERS_DER_ATTRS_VIEW)) { if (dSchemaNames.contains(name)) { columns.add(new AttrColumn<UserTO>(name, SchemaType.DERIVED)); } } // Add defaults in case of no selection if (columns.isEmpty()) { for (String name : UserDisplayAttributesModalPage.USER_DEFAULT_SELECTION) { columns.add(new PropertyColumn<UserTO, String>(new ResourceModel(name, name), name, name)); } prefMan.setList(getRequest(), getResponse(), Constants.PREF_USERS_DETAILS_VIEW, Arrays.asList(UserDisplayAttributesModalPage.USER_DEFAULT_SELECTION)); } columns.add(new ActionColumn<UserTO, String>(new ResourceModel("actions", "")) { private static final long serialVersionUID = -3503023501954863131L; @Override public ActionLinksPanel<UserTO> getActions(final String componentId, final IModel<UserTO> model) { final ActionLinksPanel.Builder<UserTO> panel = ActionLinksPanel.builder(page.getPageReference()); panel.add(new ActionLink<UserTO>() { private static final long serialVersionUID = -7978723352517770644L; @Override public void onClick(final AjaxRequestTarget target, final UserTO ignore) { final IModel<AnyHandler<UserTO>> formModel = new CompoundPropertyModel<>( new AnyHandler<>(model.getObject())); altDefaultModal.setFormModel(formModel); target.add(altDefaultModal.setContent(new StatusModal<UserTO>(altDefaultModal, pageRef, formModel.getObject().getInnerObject(), false))); altDefaultModal.header(new Model<>( getString("any.edit", new Model<>(new AnyHandler<>(model.getObject()))))); altDefaultModal.show(true); } }, ActionLink.ActionType.MANAGE_RESOURCES, StandardEntitlement.USER_READ) .add(new ActionLink<UserTO>() { private static final long serialVersionUID = -7978723352517770644L; @Override public void onClick(final AjaxRequestTarget target, final UserTO ignore) { final IModel<AnyHandler<UserTO>> formModel = new CompoundPropertyModel<>( new AnyHandler<>(model.getObject())); altDefaultModal.setFormModel(formModel); target.add(altDefaultModal.setContent(new StatusModal<UserTO>(altDefaultModal, pageRef, formModel.getObject().getInnerObject(), true))); altDefaultModal.header(new Model<>( getString("any.edit", new Model<>(new AnyHandler<>(model.getObject()))))); altDefaultModal.show(true); } }, ActionLink.ActionType.ENABLE, StandardEntitlement.USER_READ) .add(new ActionLink<UserTO>() { private static final long serialVersionUID = -7978723352517770644L; @Override public void onClick(final AjaxRequestTarget target, final UserTO ignore) { send(UserSearchResultPanel.this, Broadcast.EXACT, new AjaxWizard.EditItemActionEvent<>( new AnyHandler<>( new UserRestClient().read(model.getObject().getKey())), target)); } }, ActionLink.ActionType.EDIT, StandardEntitlement.USER_READ).add(new ActionLink<UserTO>() { private static final long serialVersionUID = -7978723352517770644L; @Override public void onClick(final AjaxRequestTarget target, final UserTO ignore) { final UserTO clone = SerializationUtils.clone(model.getObject()); clone.setKey(0L); send(UserSearchResultPanel.this, Broadcast.EXACT, new AjaxWizard.NewItemActionEvent<>(new AnyHandler<>(clone), target)); } }, ActionLink.ActionType.CLONE, StandardEntitlement.USER_CREATE) .add(new ActionLink<UserTO>() { private static final long serialVersionUID = -7978723352517770644L; @Override public void onClick(final AjaxRequestTarget target, final UserTO ignore) { try { restClient.delete(model.getObject().getETagValue(), model.getObject().getKey()); info(getString(Constants.OPERATION_SUCCEEDED)); target.add(container); } catch (SyncopeClientException e) { LOG.error("While deleting object {}", model.getObject().getKey(), e); error(getString(Constants.ERROR) + ": " + e.getMessage()); } SyncopeConsoleSession.get().getNotificationPanel().refresh(target); } }, ActionLink.ActionType.DELETE, StandardEntitlement.USER_DELETE); return panel.build(componentId, model.getObject()); } @Override public ActionLinksPanel<Serializable> getHeader(final String componentId) { final ActionLinksPanel.Builder<Serializable> panel = ActionLinksPanel .builder(page.getPageReference()); return panel.add(new ActionLink<Serializable>() { private static final long serialVersionUID = -7978723352517770644L; @Override public void onClick(final AjaxRequestTarget target, final Serializable ignore) { target.add(modal.setContent(new UserDisplayAttributesModalPage<>(modal, page.getPageReference(), pSchemaNames, dSchemaNames))); modal.header(new ResourceModel("any.attr.display", "")); modal.show(true); } }, ActionLink.ActionType.CHANGE_VIEW, StandardEntitlement.USER_READ) .add(new ActionLink<Serializable>() { private static final long serialVersionUID = -7978723352517770644L; @Override public void onClick(final AjaxRequestTarget target, final Serializable ignore) { if (target != null) { target.add(container); } } }, ActionLink.ActionType.RELOAD, StandardEntitlement.USER_SEARCH).build(componentId); } }); return columns; }
From source file:org.apache.syncope.console.pages.Schema.java
private <T extends AbstractSchemaModalPage> List<IColumn> getColumns(final WebMarkupContainer webContainer, final ModalWindow modalWindow, final AttributableType attributableType, final SchemaType schemaType, final Collection<String> fields) { List<IColumn> columns = new ArrayList<IColumn>(); for (final String field : fields) { final Field clazzField = ReflectionUtils.findField(schemaType.getToClass(), field); if (clazzField != null) { if (clazzField.getType().equals(Boolean.class) || clazzField.getType().equals(boolean.class)) { columns.add(new AbstractColumn<AbstractSchemaTO, String>(new ResourceModel(field)) { private static final long serialVersionUID = 8263694778917279290L; @Override// w w w . j ava 2s . c om public void populateItem(final Item<ICellPopulator<AbstractSchemaTO>> item, final String componentId, final IModel<AbstractSchemaTO> model) { BeanWrapper bwi = new BeanWrapperImpl(model.getObject()); Object obj = bwi.getPropertyValue(field); item.add(new Label(componentId, "")); item.add(new AttributeModifier("class", new Model<String>(obj.toString()))); } @Override public String getCssClass() { return "small_fixedsize"; } }); } else { IColumn column = new PropertyColumn(new ResourceModel(field), field, field) { private static final long serialVersionUID = 3282547854226892169L; @Override public String getCssClass() { String css = super.getCssClass(); if ("name".equals(field)) { css = StringUtils.isBlank(css) ? "medium_fixedsize" : css + " medium_fixedsize"; } return css; } }; columns.add(column); } } } columns.add(new AbstractColumn<AbstractSchemaTO, String>(new ResourceModel("actions", "")) { private static final long serialVersionUID = 2054811145491901166L; @Override public String getCssClass() { return "action"; } @Override public void populateItem(final Item<ICellPopulator<AbstractSchemaTO>> item, final String componentId, final IModel<AbstractSchemaTO> model) { final AbstractSchemaTO schemaTO = model.getObject(); final ActionLinksPanel panel = new ActionLinksPanel(componentId, model, getPageReference()); panel.addWithRoles(new ActionLink() { private static final long serialVersionUID = -3722207913631435501L; @Override public void onClick(final AjaxRequestTarget target) { modalWindow.setPageCreator(new ModalWindow.PageCreator() { private static final long serialVersionUID = -7834632442532690940L; @Override public Page createPage() { AbstractSchemaModalPage page = SchemaModalPageFactory .getSchemaModalPage(attributableType, schemaType); page.setSchemaModalPage(Schema.this.getPageReference(), modalWindow, schemaTO, false); return page; } }); modalWindow.show(target); } }, ActionType.EDIT, allowedReadRoles); panel.addWithRoles(new ActionLink() { private static final long serialVersionUID = -3722207913631435501L; @Override public void onClick(final AjaxRequestTarget target) { switch (schemaType) { case DERIVED: restClient.deleteDerSchema(attributableType, schemaTO.getName()); break; case VIRTUAL: restClient.deleteVirSchema(attributableType, schemaTO.getName()); break; default: restClient.deleteSchema(attributableType, schemaTO.getName()); break; } info(getString(Constants.OPERATION_SUCCEEDED)); feedbackPanel.refresh(target); target.add(webContainer); } }, ActionType.DELETE, allowedDeleteRoles); item.add(panel); } }); return columns; }
From source file:org.apache.syncope.core.persistence.dao.impl.AbstractDAOImpl.java
protected String toOrderByStatement(final Class<? extends AbstractBaseBean> beanClass, final String prefix, final List<OrderByClause> orderByClauses) { StringBuilder statement = new StringBuilder(); for (OrderByClause clause : orderByClauses) { String field = clause.getField().trim(); if (ReflectionUtils.findField(beanClass, field) != null) { if (StringUtils.isNotBlank(prefix)) { statement.append(prefix).append('.'); }/*from w w w . java 2s .co m*/ statement.append(field).append(' ').append(clause.getDirection().name()); } } if (statement.length() > 0) { statement.insert(0, "ORDER BY "); } return statement.toString(); }
From source file:org.apache.syncope.core.persistence.dao.impl.SubjectSearchDAOImpl.java
private OrderBySupport parseOrderBy(final SubjectType type, final SearchSupport svs, final List<OrderByClause> orderByClauses) { final AttributableUtil attrUtil = AttributableUtil.getInstance(type.asAttributableType()); OrderBySupport orderBySupport = new OrderBySupport(); for (OrderByClause clause : orderByClauses) { OrderBySupport.Item obs = new OrderBySupport.Item(); Field subjectField = ReflectionUtils.findField(attrUtil.attributableClass(), clause.getField()); if (subjectField == null) { AbstractNormalSchema schema = schemaDAO.find(clause.getField(), attrUtil.schemaClass()); if (schema != null) { if (schema.isUniqueConstraint()) { orderBySupport.views.add(svs.uniqueAttr()); obs.select = new StringBuilder().append(svs.uniqueAttr().alias).append('.') .append(svs.fieldName(schema.getType())).append(" AS ").append(clause.getField()) .toString(); obs.where = new StringBuilder().append(svs.uniqueAttr().alias).append(".schema_name='") .append(clause.getField()).append("'").toString(); obs.orderBy = clause.getField() + " " + clause.getDirection().name(); } else { orderBySupport.views.add(svs.attr()); obs.select = new StringBuilder().append(svs.attr().alias).append('.') .append(svs.fieldName(schema.getType())).append(" AS ").append(clause.getField()) .toString(); obs.where = new StringBuilder().append(svs.attr().alias).append(".schema_name='") .append(clause.getField()).append("'").toString(); obs.orderBy = clause.getField() + " " + clause.getDirection().name(); }/*from w w w . j a v a 2 s . co m*/ } } else { orderBySupport.views.add(svs.field()); obs.select = svs.field().alias + "." + clause.getField(); obs.where = StringUtils.EMPTY; obs.orderBy = svs.field().alias + "." + clause.getField() + " " + clause.getDirection().name(); } if (obs.isEmpty()) { LOG.warn("Cannot build any valid clause from {}", clause); } else { orderBySupport.items.add(obs); } } return orderBySupport; }
From source file:org.apache.syncope.core.persistence.dao.impl.SubjectSearchDAOImpl.java
@SuppressWarnings("rawtypes") private String getQuery(final SubjectCond cond, final boolean not, final List<Object> parameters, final SubjectType type, final SearchSupport svs) { final AttributableUtil attrUtil = AttributableUtil.getInstance(type.asAttributableType()); Field subjectField = ReflectionUtils.findField(attrUtil.attributableClass(), cond.getSchema()); if (subjectField == null) { LOG.warn("Ignoring invalid schema '{}'", cond.getSchema()); return EMPTY_ATTR_QUERY; }//from w ww .j a va 2 s. c o m AbstractNormalSchema schema = attrUtil.newSchema(); schema.setName(subjectField.getName()); for (AttributeSchemaType attrSchemaType : AttributeSchemaType.values()) { if (subjectField.getType().isAssignableFrom(attrSchemaType.getType())) { schema.setType(attrSchemaType); } } // Deal with subject Integer fields logically mapping to boolean values // (SyncopeRole.inheritAttributes, for example) boolean foundBooleanMin = false; boolean foundBooleanMax = false; if (Integer.class.equals(subjectField.getType())) { for (Annotation annotation : subjectField.getAnnotations()) { if (Min.class.equals(annotation.annotationType())) { foundBooleanMin = ((Min) annotation).value() == 0; } else if (Max.class.equals(annotation.annotationType())) { foundBooleanMax = ((Max) annotation).value() == 1; } } } if (foundBooleanMin && foundBooleanMax) { if ("true".equalsIgnoreCase(cond.getExpression())) { cond.setExpression("1"); schema.setType(AttributeSchemaType.Long); } else if ("false".equalsIgnoreCase(cond.getExpression())) { cond.setExpression("0"); schema.setType(AttributeSchemaType.Long); } } // Deal with subject fields representing relationships to other entities // Only _id and _name are suppored if (subjectField.getType().getAnnotation(Entity.class) != null) { if (BeanUtils.findDeclaredMethodWithMinimalParameters(subjectField.getType(), "getId") != null) { cond.setSchema(cond.getSchema() + "_id"); schema.setType(AttributeSchemaType.Long); } if (BeanUtils.findDeclaredMethodWithMinimalParameters(subjectField.getType(), "getName") != null) { cond.setSchema(cond.getSchema() + "_name"); schema.setType(AttributeSchemaType.String); } } AbstractAttrValue attrValue = attrUtil.newAttrValue(); try { if (cond.getType() != AttributeCond.Type.LIKE && cond.getType() != AttributeCond.Type.ISNULL && cond.getType() != AttributeCond.Type.ISNOTNULL) { schema.getValidator().validate(cond.getExpression(), attrValue); } } catch (ValidationException e) { LOG.error("Could not validate expression '" + cond.getExpression() + "'", e); return EMPTY_ATTR_QUERY; } final StringBuilder query = new StringBuilder("SELECT DISTINCT subject_id FROM ").append(svs.field().name) .append(" WHERE "); fillAttributeQuery(query, attrValue, schema, cond, not, parameters, svs); return query.toString(); }
From source file:org.apache.syncope.core.persistence.jpa.dao.AbstractAnySearchDAO.java
protected Triple<PlainSchema, PlainAttrValue, AnyCond> check(final AnyCond cond, final AnyTypeKind kind) { AnyCond condClone = SerializationUtils.clone(cond); AnyUtils attrUtils = anyUtilsFactory.getInstance(kind); // Keeps track of difference between entity's getKey() and JPA @Id fields if ("key".equals(condClone.getSchema())) { condClone.setSchema("id"); }//from w ww. j a v a 2 s .co m Field anyField = ReflectionUtils.findField(attrUtils.anyClass(), condClone.getSchema()); if (anyField == null) { LOG.warn("Ignoring invalid schema '{}'", condClone.getSchema()); throw new IllegalArgumentException(); } PlainSchema schema = new JPAPlainSchema(); schema.setKey(anyField.getName()); for (AttrSchemaType attrSchemaType : AttrSchemaType.values()) { if (anyField.getType().isAssignableFrom(attrSchemaType.getType())) { schema.setType(attrSchemaType); } } // Deal with any Integer fields logically mapping to boolean values boolean foundBooleanMin = false; boolean foundBooleanMax = false; if (Integer.class.equals(anyField.getType())) { for (Annotation annotation : anyField.getAnnotations()) { if (Min.class.equals(annotation.annotationType())) { foundBooleanMin = ((Min) annotation).value() == 0; } else if (Max.class.equals(annotation.annotationType())) { foundBooleanMax = ((Max) annotation).value() == 1; } } } if (foundBooleanMin && foundBooleanMax) { schema.setType(AttrSchemaType.Boolean); } // Deal with any fields representing relationships to other entities if (anyField.getType().getAnnotation(Entity.class) != null) { Method relMethod = null; try { relMethod = ClassUtils.getPublicMethod(anyField.getType(), "getKey", new Class<?>[0]); } catch (Exception e) { LOG.error("Could not find {}#getKey", anyField.getType(), e); } if (relMethod != null && String.class.isAssignableFrom(relMethod.getReturnType())) { condClone.setSchema(condClone.getSchema() + "_id"); schema.setType(AttrSchemaType.String); } } PlainAttrValue attrValue = attrUtils.newPlainAttrValue(); if (condClone.getType() != AttributeCond.Type.LIKE && condClone.getType() != AttributeCond.Type.ILIKE && condClone.getType() != AttributeCond.Type.ISNULL && condClone.getType() != AttributeCond.Type.ISNOTNULL) { try { ((JPAPlainSchema) schema).validator().validate(condClone.getExpression(), attrValue); } catch (ValidationException e) { LOG.error("Could not validate expression '" + condClone.getExpression() + "'", e); throw new IllegalArgumentException(); } } return Triple.of(schema, attrValue, condClone); }