blob: 973b3aaa3e741668d1f10f1165214e2ce253a2cd [file] [log] [blame]
/*
*
* Copyright (c) 2011, 2016 - Loetz GmbH&Co.KG (69115 Heidelberg, Germany)
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Initial contribution:
* Loetz GmbH & Co. KG
*
*/
package org.eclipse.osbp.vaaclipse.addons.softwarefactory.userfilter;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashSet;
import java.util.List;
import java.util.Locale;
import java.util.Set;
import javax.annotation.PostConstruct;
import javax.inject.Inject;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaDelete;
import javax.persistence.criteria.Join;
import javax.persistence.criteria.JoinType;
import javax.persistence.criteria.Predicate;
import javax.persistence.criteria.Root;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.osbp.authentication.account.dtos.UserAccountDto;
import org.eclipse.osbp.authentication.account.dtos.UserAccountFilterDto;
import org.eclipse.osbp.authentication.account.dtos.mapper.UserAccountDtoMapper;
import org.eclipse.osbp.authentication.account.dtos.mapper.UserAccountFilterDtoMapper;
import org.eclipse.osbp.authentication.account.entities.UserAccount;
import org.eclipse.osbp.authentication.account.entities.UserAccountFilter;
import org.eclipse.osbp.dsl.common.datatypes.IDto;
import org.eclipse.osbp.dsl.dto.lib.impl.DtoServiceAccess;
import org.eclipse.osbp.dsl.dto.lib.services.IDTOServiceWithMutablePersistence;
import org.eclipse.osbp.dsl.dto.lib.services.Query;
import org.eclipse.osbp.dsl.dto.lib.services.filters.ILFilter;
import org.eclipse.osbp.dsl.dto.lib.services.filters.LCompare;
import org.eclipse.osbp.dsl.dto.lib.services.filters.LCompare.Equal;
import org.eclipse.osbp.dsl.dto.lib.services.filters.LJoinFilter;
import org.eclipse.osbp.dsl.semantic.common.types.LPackage;
import org.eclipse.osbp.dsl.semantic.entity.LEntity;
import org.eclipse.osbp.dsl.semantic.entity.LEntityAttribute;
import org.eclipse.osbp.dsl.semantic.entity.OSBPEntityPackage;
import org.eclipse.osbp.persistence.IPersistenceService;
import org.eclipse.osbp.runtime.common.annotations.DtoUtils;
import org.eclipse.osbp.runtime.common.types.IBundleSpace;
import org.eclipse.osbp.runtime.web.vaadin.common.data.BeanServiceLazyLoadingContainer;
import org.eclipse.osbp.runtime.web.vaadin.common.data.StatefulDelegatingDtoSearchService;
import org.eclipse.osbp.ui.api.contextfunction.IVaadinDialogProvider;
import org.eclipse.osbp.ui.api.metadata.IDSLMetadataService;
import org.eclipse.osbp.ui.api.user.IUser;
import org.eclipse.osbp.utils.common.EntityUtils;
import org.eclipse.osbp.vaadin.emf.api.IModelingContext;
import org.eclipse.osbp.vaadin.emf.data.fields.EObjectComboBox;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.vaadin.data.Property.ValueChangeEvent;
import com.vaadin.data.Property.ValueChangeListener;
import com.vaadin.ui.Button;
import com.vaadin.ui.Button.ClickEvent;
import com.vaadin.ui.Button.ClickListener;
import com.vaadin.ui.CheckBox;
import com.vaadin.ui.ComboBox;
import com.vaadin.ui.Component;
import com.vaadin.ui.HorizontalLayout;
import com.vaadin.ui.ListSelect;
import com.vaadin.ui.Notification;
import com.vaadin.ui.VerticalLayout;
// TODO: Auto-generated Javadoc
/**
* The Class UserFilterDialogProvider.
*/
@SuppressWarnings({ "serial", "restriction" })
public class UserFilterDialogProvider implements IVaadinDialogProvider,
ValueChangeListener, IUser.UserLocaleListener {
/** The persistence service. */
@Inject
private IPersistenceService persistenceService;
/** The bundle space. */
@Inject
private IBundleSpace bundleSpace;
/** The modeling context. */
@Inject
IModelingContext modelingContext;
/** The user field. */
private ComboBox userField;
/** The entity field. */
private EObjectComboBox entityField;
/** The filter field. */
private ListSelect filterField;
/** The filter select all. */
private Button filterSelectAll;
/** The filter select none. */
private Button filterSelectNone;
/** The save. */
private Button save;
/** The filter check invers. */
private CheckBox filterCheckInvers;
/** The filter delimiter. */
private final String FILTER_DELIMITER = ":";
/** The persistence id. */
private String persistenceId = "authentication";
/** The emf. */
private EntityManagerFactory emf;
/** The Constant LOGGER. */
private static final Logger LOGGER = LoggerFactory
.getLogger(UserFilterDialogProvider.class);
/** The metadata service. */
@Inject
private IDSLMetadataService dslMetadataService;
/** The user. */
@Inject
private IUser user;
/**
* The listener interface for receiving userComboBoxValueChange events. The
* class that is interested in processing a userComboBoxValueChange event
* implements this interface, and the object created with that class is
* registered with a component using the component's
* <code>addUserComboBoxValueChangeListener<code> method. When
* the userComboBoxValueChange event occurs, that object's appropriate
* method is invoked.
*
* @see UserComboBoxValueChangeEvent
*/
private class UserComboBoxValueChangeListener implements
ValueChangeListener {
/*
* (non-Javadoc)
*
* @see
* com.vaadin.data.Property.ValueChangeListener#valueChange(com.vaadin
* .data.Property.ValueChangeEvent)
*/
@Override
public void valueChange(ValueChangeEvent event) {
entityField.clear();
filterField.setContainerDataSource(null);
filterSelectAll.setEnabled(false);
filterSelectNone.setEnabled(false);
filterCheckInvers.clear();
}
}
/**
* The listener interface for receiving entityComboBoxValueChange events.
* The class that is interested in processing a entityComboBoxValueChange
* event implements this interface, and the object created with that class
* is registered with a component using the component's
* <code>addEntityComboBoxValueChangeListener<code> method. When
* the entityComboBoxValueChange event occurs, that object's appropriate
* method is invoked.
*
* @see EntityComboBoxValueChangeEvent
*/
private class EntityComboBoxValueChangeListener implements
ValueChangeListener {
/*
* (non-Javadoc)
*
* @see
* com.vaadin.data.Property.ValueChangeListener#valueChange(com.vaadin
* .data.Property.ValueChangeEvent)
*/
@Override
public void valueChange(ValueChangeEvent event) {
filterField.setContainerDataSource(null);
LEntity entityFieldValue = (LEntity) entityField.getValue();
if (entityFieldValue != null) {
for (LEntityAttribute entityAttr : entityFieldValue
.getAllAttributes()) {
if (entityAttr.isDomainKey()) {
filterField.setItemCaptionPropertyId(entityAttr
.getName());
fillfilterComboBox(entityFieldValue);
}
}
}
}
}
/**
* The listener interface for receiving filterValueChange events. The class
* that is interested in processing a filterValueChange event implements
* this interface, and the object created with that class is registered with
* a component using the component's
* <code>addFilterValueChangeListener<code> method. When
* the filterValueChange event occurs, that object's appropriate
* method is invoked.
*
* @see FilterValueChangeEvent
*/
private class FilterValueChangeListener implements ValueChangeListener {
/*
* (non-Javadoc)
*
* @see
* com.vaadin.data.Property.ValueChangeListener#valueChange(com.vaadin
* .data.Property.ValueChangeEvent)
*/
@Override
public void valueChange(ValueChangeEvent event) {
@SuppressWarnings("unchecked")
Collection<IDto> value = (Collection<IDto>) filterField.getValue();
int size = value.size();
if (size > 0 && size < filterField.getItemIds().size()) {
filterCheckInvers.setEnabled(true);
}
}
}
/**
* The listener interface for receiving filterSelectAllClick events. The
* class that is interested in processing a filterSelectAllClick event
* implements this interface, and the object created with that class is
* registered with a component using the component's
* <code>addFilterSelectAllClickListener<code> method. When
* the filterSelectAllClick event occurs, that object's appropriate
* method is invoked.
*
* @see FilterSelectAllClickEvent
*/
private class FilterSelectAllClickListener implements ClickListener {
/*
* (non-Javadoc)
*
* @see
* com.vaadin.ui.Button.ClickListener#buttonClick(com.vaadin.ui.Button
* .ClickEvent)
*/
@Override
public void buttonClick(ClickEvent event) {
filterField.setValue(filterField.getItemIds());
filterCheckInvers.setEnabled(false);
filterCheckInvers.clear();
}
}
/**
* The listener interface for receiving filterSelectNoneClick events. The
* class that is interested in processing a filterSelectNoneClick event
* implements this interface, and the object created with that class is
* registered with a component using the component's
* <code>addFilterSelectNoneClickListener<code> method. When
* the filterSelectNoneClick event occurs, that object's appropriate
* method is invoked.
*
* @see FilterSelectNoneClickEvent
*/
private class FilterSelectNoneClickListener implements ClickListener {
/*
* (non-Javadoc)
*
* @see
* com.vaadin.ui.Button.ClickListener#buttonClick(com.vaadin.ui.Button
* .ClickEvent)
*/
@Override
public void buttonClick(ClickEvent event) {
filterField.clear();
filterCheckInvers.setEnabled(false);
filterCheckInvers.clear();
}
}
/**
* The listener interface for receiving saveClick events. The class that is
* interested in processing a saveClick event implements this interface, and
* the object created with that class is registered with a component using
* the component's <code>addSaveClickListener<code> method. When
* the saveClick event occurs, that object's appropriate
* method is invoked.
*
* @see SaveClickEvent
*/
private class SaveClickListener implements ClickListener {
/*
* (non-Javadoc)
*
* @see
* com.vaadin.ui.Button.ClickListener#buttonClick(com.vaadin.ui.Button
* .ClickEvent)
*/
@Override
public void buttonClick(ClickEvent event) {
updateUserAccountFilterTable();
}
}
/*
* (non-Javadoc)
*
* @see
* com.vaadin.data.Property.ValueChangeListener#valueChange(com.vaadin.data
* .Property.ValueChangeEvent)
*/
@Override
public void valueChange(ValueChangeEvent event) {
if (userField.getValue() != null && entityField.getValue() != null
&& (filterField.getValue() != null)) {
save.setEnabled(true);
} else {
save.setEnabled(false);
}
}
/* (non-Javadoc)
* @see org.eclipse.osbp.ui.api.contextfunction.IUserFilterDialogProvider#getDialog()
*/
@Override
public Component getDialog() {
VerticalLayout content = new VerticalLayout();
createView(content);
return content;
}
/**
* Inits the.
*/
@PostConstruct
public void init() {
// Registration of class loader as required for the persistence service.
persistenceService.registerPersistenceUnit(persistenceId,
UserAccountFilter.class);
emf = persistenceService.getEntityManagerFactory(persistenceId);
}
/**
* Creates the view.
*
* @param parent
* the parent
*/
@Override
public void createView(VerticalLayout parent) {
parent.setSpacing(true);
parent.setMargin(true);
parent.setSizeFull();
parent.setPrimaryStyleName("osbp");
HorizontalLayout comboArea = new HorizontalLayout();
comboArea.addStyleName("loginUserArea");
comboArea.setSizeFull();
comboArea.setMargin(true);
parent.addComponent(comboArea);
HorizontalLayout dataArea = new HorizontalLayout();
dataArea.addStyleName("loginLoginArea");
dataArea.setSizeFull();
dataArea.setMargin(true);
parent.addComponent(dataArea);
userField = new ComboBox();
userField.setItemCaptionPropertyId("userName");
userField.setImmediate(true);
userField.setSizeFull();
comboArea.addComponent(userField);
entityField = new EObjectComboBox(modelingContext.getAdapterFactory());
entityField.setImmediate(true);
entityField.setSizeFull();
comboArea.addComponent(entityField);
HorizontalLayout buttonArea = new HorizontalLayout();
buttonArea.setId("loginButtonArea");
buttonArea.addStyleName("loginButtonArea");
buttonArea.setSizeFull();
buttonArea.setMargin(true);
parent.addComponent(buttonArea);
filterCheckInvers = new CheckBox();
filterCheckInvers.setImmediate(true);
filterCheckInvers.setEnabled(false);
buttonArea.addComponent(filterCheckInvers);
filterSelectAll = new Button("all");
filterSelectAll.setSizeFull();
filterSelectAll.setImmediate(true);
filterSelectAll.setEnabled(false);
buttonArea.addComponent(filterSelectAll);
filterSelectNone = new Button("none");
filterSelectNone.setSizeFull();
filterSelectNone.setImmediate(true);
filterSelectNone.setEnabled(false);
buttonArea.addComponent(filterSelectNone);
save = new Button("save");
save.setSizeFull();
save.setImmediate(true);
save.setEnabled(false);
buttonArea.addComponent(save);
filterField = new ListSelect();
filterField.setValue("entry to filter");
filterField.setImmediate(true);
filterField.setMultiSelect(true);
filterField.setSizeFull();
filterField.setRows(25);
dataArea.addComponent(filterField);
fillItems();
// Listener
userField.addValueChangeListener(this);
userField.addValueChangeListener(new UserComboBoxValueChangeListener());
entityField.addValueChangeListener(this);
entityField
.addValueChangeListener(new EntityComboBoxValueChangeListener());
filterField.addValueChangeListener(this);
filterField.addValueChangeListener(new FilterValueChangeListener());
filterSelectAll.addClickListener(new FilterSelectAllClickListener());
filterSelectNone.addClickListener(new FilterSelectNoneClickListener());
save.addClickListener(new SaveClickListener());
user.addUserLocaleListener(this);
}
/**
* Fill items.
*/
protected void fillItems() {
fillUsersComboBox();
fillEntityComboBoxContent();
}
/**
* Fill users combo box.
*/
// ---------- Helper Methods ------------
private void fillUsersComboBox() {
IDTOServiceWithMutablePersistence<UserAccountDto> service = (IDTOServiceWithMutablePersistence<UserAccountDto>) DtoServiceAccess
.getService(UserAccountDto.class);
// getting all existing users.
// not using directly the UserAccountDtoService via find-Method due to
// the necessary to use a container
// therefore we use here the combination of
// StatefulDelegatingDtoSearchService and
// BeanServiceLazyLoadingContainer.
StatefulDelegatingDtoSearchService<UserAccountDto> loadingService = new StatefulDelegatingDtoSearchService<>(
service, UserAccountDto.class);
BeanServiceLazyLoadingContainer<UserAccountDto> datasource = new BeanServiceLazyLoadingContainer<>(
loadingService, UserAccountDto.class, null);
userField.setContainerDataSource(datasource);
}
/**
* Fill entity combo box content.
*/
private void fillEntityComboBoxContent() {
List<LEntity> result = new ArrayList<LEntity>();
for(EObject eObj:dslMetadataService.getAll(OSBPEntityPackage.Literals.LENTITY)) {
result.add((LEntity)eObj);
}
entityField.setCollection(result);
}
/**
* Fillfilter combo box.
*
* @param entity
* the entity
*/
private void fillfilterComboBox(LEntity entity) {
String fqnDto = EntityUtils.getDtoFQNForLEntity(entity);
try {
@SuppressWarnings("unchecked")
Class<Object> dtoClass = (Class<Object>) bundleSpace
.forName(fqnDto);
// IMPORTANT!!!! DO NOT REMOVE!!!!
// Required to avoid NullPointerException trying to read data from BeanServiceLazyLoadingContainer<Object> datasource.
// Without this registration the IDTOServiceWithMutablePersistence<Object> service (being instance of AbstractDTOService) has 'null' as EntityManagerFactory.
persistenceService.registerPersistenceUnit(entity.getPersistenceUnit(), dtoClass);
IDTOServiceWithMutablePersistence<Object> service = (IDTOServiceWithMutablePersistence<Object>) DtoServiceAccess
.getService(dtoClass);
StatefulDelegatingDtoSearchService<Object> loadingService = new StatefulDelegatingDtoSearchService<>(
service, dtoClass);
BeanServiceLazyLoadingContainer<Object> datasource = new BeanServiceLazyLoadingContainer<>(
loadingService, dtoClass, null);
int size1 = filterField.getItemIds().size();
filterField.setContainerDataSource(datasource);
int size2 = filterField.getItemIds().size();
if (size1 == 0 && size2 > 0) {
filterSelectAll.setEnabled(true);
filterSelectNone.setEnabled(true);
}
// optional preselect
preSelectFilter();
} catch (ClassNotFoundException e) {
LOGGER.error("{}", e);
}
}
/**
* Pre select filter.
*/
private void preSelectFilter() {
// New empty list for the old selected and persisted filters that will
// be preselected.
final Set<IDto> selectedFilters = new HashSet<IDto>();
// Searching for candidates for preselection
for (UserAccountFilterDto accountFilterDto : getFilters()) {
String filter = accountFilterDto.getFilter();
String filterId = getFilterId(filter);
String filterEntity = getFilterEntity(filter);
@SuppressWarnings("unchecked")
Collection<IDto> items = (Collection<IDto>) filterField
.getContainerDataSource().getItemIds();
LEntity entityValue = (LEntity) entityField.getValue();
String entityDtoName = EntityUtils
.getQualifiedDtoNameForQualifiedEntityName(filterEntity);
for (IDto dto : items) {
String dtoName = dto.getClass().getName();
// Excluding not existing entities within the filters in
// UserAccountFilter
if (!dtoName.equals(entityDtoName)) {
break;
} else {
// Preselection of the invers checkbox
boolean inversValue = accountFilterDto.getInvers();
if (filterCheckInvers.getValue() != inversValue) {
filterCheckInvers.setValue(inversValue);
}
// Identify the entity candidates comparing their ID with
// the persisted ID within the filter in UserAccountFilter
Object idValue = DtoUtils.getValue(dto,
getIdName(entityValue));
// In case that the id is a Integer it has to be transformed
// into String to be compare with the id of the filter.
if (idValue instanceof Integer) {
idValue = String.valueOf(idValue);
}
if (filterId.equals(idValue)) {
selectedFilters.add(dto);
}
}
}
System.out.println();
}
// preseletion of the filter
filterField.setValue(selectedFilters);
}
/**
* Gets the filter id.
*
* @param filter
* the filter
* @return the filter id
*/
private String getFilterId(String filter) {
String[] splittedFilter = filter.split(FILTER_DELIMITER);
if (splittedFilter.length > 1) {
return splittedFilter[1];
}
return "";
}
/**
* Gets the filter entity.
*
* @param filter
* the filter
* @return the filter entity
*/
private String getFilterEntity(String filter) {
String[] splittedFilter = filter.split(FILTER_DELIMITER);
if (splittedFilter.length > 0) {
return splittedFilter[0];
}
return "";
}
/**
* Gets the filters.
*
* @return the filters
*/
private Collection<UserAccountFilterDto> getFilters() {
// UserAccount
UserAccountDto user = (UserAccountDto) userField.getValue();
// create UserAccountDTOService
IDTOServiceWithMutablePersistence<UserAccountFilterDto> service = (IDTOServiceWithMutablePersistence<UserAccountFilterDto>) DtoServiceAccess
.getService(UserAccountFilterDto.class);
// find all useraccountfilter elements with the reference to the
// providing user account id.
ILFilter filter = null;
if (user != null) {
Equal idCompareFilter = new LCompare.Equal("id", user.getId());
filter = new LJoinFilter("userAccount", idCompareFilter);
}
Collection<UserAccountFilterDto> userAccountFilters = service
.find(new Query(filter));
return userAccountFilters;
}
/**
* Update user account filter table.
*/
private void updateUserAccountFilterTable() {
// UserAccountDto user = (UserAccountDto) userField.getValue();
// JvmType type = getJvmTypeFromUserDto(user);
EntityManager em = emf.createEntityManager();
// create a new transaction
em.getTransaction().begin();
// Native - Solution
// nativeDeleteAndUpdate(em);
// CriteriaBuilder - Solution
criteriaDeleteAndUpdate(em);
// JPQL - Solution
// jpqlDeleteAnUpdate(em);
em.getTransaction().commit();
em.close();
}
/**
* Jpql delete an update.
*
* @param em
* the em
*/
@SuppressWarnings("unused")
private void jpqlDeleteAnUpdate(EntityManager em) {
// ########## NOT EXISTING. This are only not working tests.
// javax.persistence.Query query =
// em.createQuery("FROM CCNG.USER_ACCOUNT_FILTER AS u WHERE u.USER_ACCOUNT_ID = '"
// + ((UserAccountDto)userField.getValue()).getId() + "'");
// javax.persistence.Query query =
// em.createQuery("SELECT filter.filter FROM CCNG.USER_ACCOUNT_FILTER filter");
// javax.persistence.Query query =
// em.createNativeQuery("SELECT ID FROM CCNG.USER_ACCOUNT_FILTER WHERE USER_ACCOUNT_ID = '"
// + ((UserAccountDto)userField.getValue()).getId() + "'");
// for (Object resultElement : query.getResultList()) {
// System.out.println("resultElement: " + resultElement);
// } ;
}
/**
* Criteria delete and update.
*
* @param em
* the em
*/
private void criteriaDeleteAndUpdate(EntityManager em) {
UserAccountDto user = (UserAccountDto) userField.getValue();
CriteriaBuilder cb = em.getCriteriaBuilder();
// delete all existing entries as prerequisite for the following update
// of the user account
// create delete criteria
CriteriaDelete<UserAccountFilter> delete = cb
.createCriteriaDelete(UserAccountFilter.class);
// set the root class
Root<UserAccountFilter> userAccountFilterRootDelete = delete
.from(UserAccountFilter.class);
Join<UserAccountFilter, UserAccount> uaJoin = userAccountFilterRootDelete
.join("userAccount", JoinType.LEFT);
// set where clause
Predicate cbEqualId = cb.equal(uaJoin.get("id"), user.getId());
String likeString = EntityUtils.getFQNForLEntity((LEntity) entityField
.getValue()) + FILTER_DELIMITER + "%";
Predicate cbLikeEntity = cb.like(
userAccountFilterRootDelete.get("filter"), likeString);
delete.where(cb.and(cbEqualId, cbLikeEntity));
// perform delete
@SuppressWarnings("unused")
int deleteResult = em.createQuery(delete).executeUpdate();
// create an empty userAccount and set only the id.
UserAccountDtoMapper<UserAccountDto, UserAccount> userAccountMapper = new UserAccountDtoMapper<>();
UserAccount userAccount = userAccountMapper.createEntity();
userAccount.setId(user.getId());
UserAccountFilterDtoMapper<UserAccountFilterDto, UserAccountFilter> userAccountFilterMapper = new UserAccountFilterDtoMapper<>();
// creation of all the required data to insert
LEntity entityValue = ((LEntity) entityField.getValue());
EObject container = entityValue.eContainer();
if (container != null && container instanceof LPackage) {
LPackage pckg = (LPackage) container;
String pckgName = pckg.getName();
String fqn = pckgName + "." + entityValue.getName();
@SuppressWarnings("unchecked")
Collection<IDto> keys = (Collection<IDto>) filterField.getValue();
// add new entries for this user
for (IDto dto : keys) {
Object idValue = DtoUtils.getValue(dto, getIdName(entityValue));
String filterValue = fqn + FILTER_DELIMITER + idValue;
// create userAccountFilter entity
UserAccountFilter userAccountFilter = userAccountFilterMapper
.createEntity();
userAccountFilter.setId(java.util.UUID.randomUUID().toString());
userAccountFilter.setFilter(filterValue);
userAccountFilter.setInvers(filterCheckInvers.getValue());
userAccountFilter.setUserAccount(userAccount);
// persist the userAccountFilter entity
em.persist(userAccountFilter);
}
Notification.show("SAVED", "The " + keys.size()
+ " filter were successfully saved.",
Notification.Type.HUMANIZED_MESSAGE);
}
}
/**
* Native delete and update.
*
* @param em
* the em
*/
@SuppressWarnings("unused")
private void nativeDeleteAndUpdate(EntityManager em) {
UserAccountDto user = (UserAccountDto) userField.getValue();
// NativeQuery - Solution
// delete all existing entries for the updating user account
javax.persistence.Query query = em
.createNativeQuery("DELETE FROM CCNG.USER_ACCOUNT_FILTER WHERE USER_ACCOUNT_ID = '"
+ user.getId() + "'");
int deleteResult = query.executeUpdate();
// creation of all the required data to insert
LEntity entityValue = ((LEntity) entityField.getValue());
EObject container = entityValue.eContainer();
if (container != null && container instanceof LPackage) {
LPackage pckg = (LPackage) container;
String pckgName = pckg.getName();
String fqn = pckgName + "." + entityValue.getName();
@SuppressWarnings("unchecked")
Collection<IDto> keys = (Collection<IDto>) filterField.getValue();
// add new entries for this user
for (IDto dto : keys) {
Object idValue = DtoUtils.getValue(dto, getIdName(entityValue));
String filterValue = fqn + ":" + idValue;
query = em
.createNativeQuery("INSERT INTO CCNG.USER_ACCOUNT_FILTER (ID, FILTER, USER_ACCOUNT_ID, INVERS) VALUES (sys_guid(), '"
+ filterValue
+ "', '"
+ user.getId()
+ "', "
+ getInversValue(filterCheckInvers.getValue())
+ ")");
int updateResult = query.executeUpdate();
System.out.println();
}
}
}
/**
* Gets the invers value.
*
* @param value
* the value
* @return the invers value
*/
private int getInversValue(Boolean value) {
return value ? 1 : 0;
}
/**
* Gets the id name.
*
* @param entity
* the entity
* @return the id name
*/
//
private String getIdName(LEntity entity) {
for (LEntityAttribute attr : entity.getAllAttributes()) {
if (attr.isId() || attr.isUuid()) {
return attr.getName();
}
}
return "";
}
/* (non-Javadoc)
* @see org.eclipse.osbp.vaaclipse.publicapi.authentication.IUser.UserLocaleListener#localeChanged(java.util.Locale)
*/
@Override
public void localeChanged(Locale locale) {
userField.setDescription(dslMetadataService.translate(locale.toLanguageTag(), "username_tip"));
entityField.setDescription(dslMetadataService.translate(locale.toLanguageTag(), "entity_tip"));
filterCheckInvers.setCaption(dslMetadataService.translate(locale.toLanguageTag(), "invers"));
filterCheckInvers.setDescription(dslMetadataService.translate(locale.toLanguageTag(), "invers_tip"));
filterSelectAll.setCaption(dslMetadataService.translate(locale.toLanguageTag(), "all"));
filterSelectAll.setDescription(dslMetadataService.translate(locale.toLanguageTag(), "all_tip"));
filterSelectNone.setCaption(dslMetadataService.translate(locale.toLanguageTag(), "none"));
filterSelectNone.setDescription(dslMetadataService.translate(locale.toLanguageTag(), "none_tip"));
save.setCaption(dslMetadataService.translate(locale.toLanguageTag(), "save"));
save.setDescription(dslMetadataService.translate(locale.toLanguageTag(), "save_tip"));
filterField.setDescription(dslMetadataService.translate(locale.toLanguageTag(), "data_tip"));
}
// --------------------------------------------------------
}