Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug #13551: The order in which the form is displayed in the list changes after modification #820

Merged
merged 4 commits into from
Aug 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -105,5 +105,49 @@
</message>
</help>
</parameter>
<parameter>
<name>displaySort</name>
<label>
<message lang="fr">Ordre d'affichage des formulaires</message>
<message lang="en">Order of display of forms</message>
<message lang="de">Reihenfolge der Anzeige von Formularen</message>
</label>
<order>2</order>
<mandatory>true</mandatory>
<value>name</value>
<options>
<option>
<name>
<message lang="fr">Par ordre alphabétique</message>
<message lang="en">Name ascending</message>
<message lang="de">In alphabetischer Reihenfolge</message>
</name>
<value>name asc</value>
</option>
<option>
<name>
<message lang="fr">Date de création croissante</message>
<message lang="en">Creation date ascending</message>
<message lang="de">Erstellungsdatum aufsteigend</message>
</name>
<value>creationDate asc</value>
</option>
<option>
<name>
<message lang="fr">Date de création décroissante</message>
<message lang="en">Creation date descending</message>
<message lang="de">Erstellungsdatum absteigend</message>
</name>
<value>creationDate desc</value>
</option>
</options>
<type>select</type>
<updatable>always</updatable>
<help>
<message lang="fr">Permet de définir l'ordre d'affichage des formulaires</message>
<message lang="en">Allows you to define the order in which the forms are displayed</message>
<message lang="de">Ermöglicht es Ihnen, die Reihenfolge festzulegen, in der die Formulare angezeigt werden.</message>
</help>
</parameter>
</parameters>
</WAComponent>
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ public abstract class AbstractFormsOnlineIT {
static final String DYNAMIC_DATA_INSTANCE_ID = "formsOnline26";
static final String DEFAULT_INSTANCE_ID = "formsOnline100";

static final String ORDERBY_DEFAULT = "name";

static final String VALIDATOR_ID_29 = "29";
static final String VALIDATOR_ID_30 = "30";
static final String VALIDATOR_ID_31 = "31";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,13 +183,13 @@ private FormDetail getFormDetailExpectedResult() {
*/
@Test
public void testFindAllForms() throws Exception {
List<FormDetail> result = dao.findAllForms(DEFAULT_INSTANCE_ID);
List<FormDetail> result = dao.findAllForms(DEFAULT_INSTANCE_ID,ORDERBY_DEFAULT);
assertThat(result.size(), is(2));
}

@Test
public void testDeleteForm() throws Exception {
List<FormDetail> result = dao.findAllForms(DEFAULT_INSTANCE_ID);
List<FormDetail> result = dao.findAllForms(DEFAULT_INSTANCE_ID,ORDERBY_DEFAULT);
assertThat(result.size(), is(2));
final FormPK formPk = result.iterator().next().getPK();
Transaction.performInOne(() -> {
Expand All @@ -200,7 +200,7 @@ public void testDeleteForm() throws Exception {
}
return dao.deleteForm(formPk);
});
result = dao.findAllForms(DEFAULT_INSTANCE_ID);
result = dao.findAllForms(DEFAULT_INSTANCE_ID,ORDERBY_DEFAULT);
assertThat(result.size(), is(1));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import org.silverpeas.components.formsonline.model.FormsOnlineException;
import org.silverpeas.components.formsonline.model.FormsOnlineService;
import org.silverpeas.core.admin.service.OrganizationController;
import org.silverpeas.core.security.authorization.AccessControlOperation;
import org.silverpeas.core.security.authorization.ComponentAccessControl;
import org.silverpeas.core.security.authorization.ComponentAuthorization;
Expand Down Expand Up @@ -37,8 +38,9 @@ public <T> Stream<T> filter(final Collection<T> resources,
.filterAuthorizedByUser(componentIds, userId)
.collect(Collectors.toSet());
try {
String orderBy = "name asc";
final Set<String> formIds = FormsOnlineService.get()
.getAvailableFormsToSend(componentIds, userId).stream()
.getAvailableFormsToSend(componentIds, userId, orderBy).stream()
.map(f -> String.valueOf(f.getId()))
.collect(Collectors.toSet());
return resources.stream().filter(r -> formIds.contains(converter.apply(r).getLocalId()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,11 @@ public void init() {
@Override
public List<FormDetail> getAllForms(final String appId, final String userId,
final boolean withSendInfo) throws FormsOnlineException {
List<FormDetail> forms = getDAO().findAllForms(appId);
String orderBy = organizationController.getComponentParameterValue(appId, "displaySort");
orderBy = StringUtil.isDefined(orderBy) ? orderBy: "name asc";

List<FormDetail> forms = getDAO().findAllForms(appId, orderBy);

Map<Integer, Integer> numbersOfRequests = getDAO().getNumberOfRequestsByForm(appId);
for (FormDetail form : forms) {
Integer numberOfRequests = numbersOfRequests.get(form.getId());
Expand Down Expand Up @@ -294,10 +298,10 @@ public void unpublishForm(FormPK pk) throws FormsOnlineException {
}

@Override
public List<FormDetail> getAvailableFormsToSend(Collection<String> appIds, String userId)
public List<FormDetail> getAvailableFormsToSend(Collection<String> appIds, String userId, String orderBy)
throws FormsOnlineException {
String[] userGroupIds = organizationController.getAllGroupIdsOfUser(userId);
return getDAO().getUserAvailableForms(appIds, userId, userGroupIds);
return getDAO().getUserAvailableForms(appIds, userId, userGroupIds, orderBy);
}

@Override
Expand Down Expand Up @@ -416,9 +420,9 @@ public Map<String, Set<FormInstanceValidationType>> getValidatorFormIdsWithValid
final String[] userGroupIds = organizationController.getAllGroupIdsOfUser(validatorId);
final Map<String, Set<FormInstanceValidationType>> result = getDAO()
.getValidatorFormIdsWithValidationTypes(appId, validatorId, userGroupIds, formIds);
// get available form as boss
final List<FormDetail> forms = getDAO().findAllForms(appId);
final HierarchicalValidatorCacheManager hvManager = HierarchicalValidatorCacheManager.get();
String orderBy = organizationController.getComponentParameterValue(appId, "displaySort");
final List<FormDetail> forms = getDAO().findAllForms(appId, orderBy);
final HierarchicalValidatorCacheManager hvManager = new HierarchicalValidatorCacheManager();
for (FormDetail form : forms) {
if (form.isHierarchicalValidation() && (isEmpty(formIds) || formIds.contains(form.getPK().getId()))) {
final SilverpeasList<FormInstance> requests = getDAO().getAllRequests(form.getPK());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,10 @@ public interface FormsOnlineDAO {
/**
* Get all forms that has been created in given instance
* @param instanceId the instance id
* @param orderBy sort order method
* @return a List of FormDetail object
*/
List<FormDetail> findAllForms(String instanceId) throws FormsOnlineException;
List<FormDetail> findAllForms(String instanceId, String orderBy) throws FormsOnlineException;

/**
* Load forms from database with given instance Id and form id
Expand Down Expand Up @@ -137,7 +138,7 @@ List<String> getSendersAsUsers(FormPK pk)
* @throws FormsOnlineException
*/
List<FormDetail> getUserAvailableForms(Collection<String> componentIds, String userId,
String[] userGroupIds) throws FormsOnlineException;
String[] userGroupIds, String orderBy) throws FormsOnlineException;

/**
* Get all form instances that have been sent by given user (excepted the ones that have been
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,8 @@ public class FormsOnlineDAOJdbc implements FormsOnlineDAO {
private static final String SELECT_FROM = "SELECT * FROM ";
private static final String INSERT_INTO = "INSERT INTO ";
private static final String DELETE_FROM = "DELETE FROM ";

// Queries about Forms
private static final String QUERY_FIND_FORMS =
SELECT_FROM + FORMS_TABLENAME + " where instanceId = ?";
private static final String QUERY_LOAD_FORM =
SELECT_FROM + FORMS_TABLENAME + " where instanceId = ? and id = ?";
private static final String QUERY_INSERT_FORM = INSERT_INTO + FORMS_TABLENAME +
Expand Down Expand Up @@ -199,21 +198,24 @@ public FormDetail getForm(FormPK pk) throws FormsOnlineException {
}

@Override
public List<FormDetail> findAllForms(String instanceId) throws FormsOnlineException {
List<FormDetail> forms = new ArrayList<>();
try (final Connection con = getConnection();
final PreparedStatement stmt = con.prepareStatement(QUERY_FIND_FORMS)) {
stmt.setString(1, instanceId);
try (ResultSet rs = stmt.executeQuery()) {
while (rs.next()) {
FormDetail form = fetchFormDetail(rs);
forms.add(form);
}
}
public List<FormDetail> findAllForms(String instanceId, String orderBy) throws FormsOnlineException {
try {
final List<FormDetail> forms = new ArrayList<>();
final JdbcSqlQuery query = JdbcSqlQuery.createSelect("*")
.from(FORMS_TABLENAME)
// 1st criteria : correct instanceId
.where(INSTANCE_ID).in(instanceId)
.orderBy(orderBy);
query.execute(r -> {
forms.add(fetchFormDetail(r));
return null;
});
return forms;
} catch (SQLException se) {
throw new FormsOnlineException(failureOnGetting("all forms of instance", instanceId), se);
throw new FormsOnlineException(
failureOnGetting("Available forms of instance",
String.join(",", instanceId)), se);
}
return forms;
}

@Override
Expand Down Expand Up @@ -400,7 +402,7 @@ private void removeUserRights(Connection con, FormPK pk, String rightType) throw
*/
@Override
public List<FormDetail> getUserAvailableForms(final Collection<String> instanceIds,
final String userId, final String[] userGroupIds) throws FormsOnlineException {
final String userId, final String[] userGroupIds, String orderBy) throws FormsOnlineException {
try {
final List<FormDetail> forms = new ArrayList<>();
JdbcSqlQuery.executeBySplittingOn(instanceIds, (idBatch, ignore) -> {
Expand All @@ -416,6 +418,7 @@ public List<FormDetail> getUserAvailableForms(final Collection<String> instanceI
if (isNotEmpty(userGroupIds)) {
query.or("id in (select formId from " + GROUP_RIGHTS_TABLENAME + " where rightType='S' and groupId").in(userGroupIds).addSqlPart(")"); }
query.addSqlPart(")");
query.orderBy(orderBy);
query.execute(r -> {
forms.add(fetchFormDetail(r));
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ FormDetail saveForm(FormDetail form,

void unpublishForm(FormPK pk) throws FormsOnlineException;

List<FormDetail> getAvailableFormsToSend(Collection<String> appIds, String userId)
List<FormDetail> getAvailableFormsToSend(Collection<String> appIds, String userId, String orderBy)
throws FormsOnlineException;

RequestsByStatus getAllUserRequests(String appId, String userId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,10 @@ public void unpublishForm(String formId) throws FormsOnlineException {
}

public List<FormDetail> getAvailableFormsToSend() throws FormsOnlineException {
return getService().getAvailableFormsToSend(singleton(getComponentId()), getUserId());
String orderBy = getOrganisationController().getComponentParameterValue(getComponentId(), "displaySort");
orderBy = StringUtil.isDefined(orderBy) ? orderBy: "name asc";

return getService().getAvailableFormsToSend(singleton(getComponentId()), getUserId(), orderBy);
}

public void saveRequest(List<FileItem> items, boolean draft) throws FormsOnlineException {
Expand Down