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

Lut 26831 : simplify get response from backup #300

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 18 additions & 40 deletions src/java/fr/paris/lutece/plugins/forms/service/FormService.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,51 +33,18 @@
*/
package fr.paris.lutece.plugins.forms.service;

import java.util.List;
import java.util.stream.Collectors;

import javax.inject.Inject;
import javax.servlet.http.HttpServletRequest;

import org.apache.commons.collections.CollectionUtils;
import org.springframework.transaction.annotation.Transactional;

import fr.paris.lutece.api.user.User;
import fr.paris.lutece.plugins.forms.business.Form;
import fr.paris.lutece.plugins.forms.business.FormDisplay;
import fr.paris.lutece.plugins.forms.business.FormHome;
import fr.paris.lutece.plugins.forms.business.FormMessageHome;
import fr.paris.lutece.plugins.forms.business.FormQuestionResponse;
import fr.paris.lutece.plugins.forms.business.FormQuestionResponseHome;
import fr.paris.lutece.plugins.forms.business.FormResponse;
import fr.paris.lutece.plugins.forms.business.FormResponseHome;
import fr.paris.lutece.plugins.forms.business.FormResponseStep;
import fr.paris.lutece.plugins.forms.business.FormResponseStepHome;
import fr.paris.lutece.plugins.forms.business.Question;
import fr.paris.lutece.plugins.forms.business.Step;
import fr.paris.lutece.plugins.forms.business.StepHome;
import fr.paris.lutece.plugins.forms.business.*;
import fr.paris.lutece.plugins.forms.business.export.FormExportConfigHome;
import fr.paris.lutece.plugins.forms.exception.MaxFormResponseException;
import fr.paris.lutece.plugins.forms.service.workflow.IFormWorkflowService;
import fr.paris.lutece.plugins.forms.util.FormsConstants;
import fr.paris.lutece.plugins.forms.util.FormsResponseUtils;
import fr.paris.lutece.plugins.forms.web.CompositeGroupDisplay;
import fr.paris.lutece.plugins.forms.web.CompositeQuestionDisplay;
import fr.paris.lutece.plugins.forms.web.FormResponseManager;
import fr.paris.lutece.plugins.forms.web.ICompositeDisplay;
import fr.paris.lutece.plugins.forms.web.StepDisplayTree;
import fr.paris.lutece.plugins.forms.web.*;
import fr.paris.lutece.plugins.forms.web.admin.MultiviewFormResponseDetailsJspBean;
import fr.paris.lutece.plugins.forms.web.entrytype.IEntryDataService;
import fr.paris.lutece.plugins.genericattributes.business.Entry;
import fr.paris.lutece.plugins.genericattributes.business.EntryHome;
import fr.paris.lutece.plugins.genericattributes.business.FieldHome;
import fr.paris.lutece.plugins.genericattributes.business.Response;
import fr.paris.lutece.plugins.genericattributes.business.ResponseHome;
import fr.paris.lutece.plugins.genericattributes.service.entrytype.AbstractEntryTypeFile;
import fr.paris.lutece.plugins.genericattributes.service.entrytype.AbstractEntryTypeGalleryImage;
import fr.paris.lutece.plugins.genericattributes.service.entrytype.AbstractEntryTypeImage;
import fr.paris.lutece.plugins.genericattributes.service.entrytype.EntryTypeServiceManager;
import fr.paris.lutece.plugins.genericattributes.service.entrytype.IEntryTypeService;
import fr.paris.lutece.plugins.genericattributes.business.*;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why include the importation of all classes from the business and entrytype package?

import fr.paris.lutece.plugins.genericattributes.service.entrytype.*;
import fr.paris.lutece.plugins.genericattributes.util.GenericAttributesUtils;
import fr.paris.lutece.portal.business.event.ResourceEvent;
import fr.paris.lutece.portal.business.file.FileHome;
Expand All @@ -88,6 +55,13 @@
import fr.paris.lutece.portal.service.spring.SpringContextService;
import fr.paris.lutece.portal.service.workgroup.AdminWorkgroupService;
import fr.paris.lutece.util.sql.TransactionManager;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.transaction.annotation.Transactional;

import javax.inject.Inject;
import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.stream.Collectors;

/**
* This is the service class related to the form
Expand Down Expand Up @@ -465,16 +439,20 @@ private boolean canUserAccessFile( HttpServletRequest request, int nIdForm )
* The form
* @param strUserGuid
* The user guid
* @param formResponseManager
*
* @return the created {@code FormResponseManager} object
*/
public FormResponseManager createFormResponseManagerFromBackUp( Form form, String strUserGuid )
public FormResponseManager createFormResponseManagerFromBackUp( Form form, String strUserGuid, FormResponseManager formResponseManager )
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have you conducted an assessment of potential regressions resulting from the modification of method signatures?

{
FormResponseManager formResponseManager = null;
List<FormResponse> listFormResponse = FormResponseHome.getFormResponseByGuidAndForm( strUserGuid, form.getId( ), true );
if ( CollectionUtils.isNotEmpty( listFormResponse ) )
{
formResponseManager = new FormResponseManager( listFormResponse.get( 0 ) );
formResponseManager.setIsResponseLoadedFromBackup(true);
}
else if ( formResponseManager != null && CollectionUtils.isEmpty( listFormResponse ) )
{
return formResponseManager;
}
else
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,8 @@ public final class FormsConstants
public static final String SEPARATOR_UNDERSCORE = "_";
public static final String SEPARATOR_SEMICOLON = ";";
public static final String END_OF_LINE = "\n";
public static final String FO_LOGIN_PAGE_PARAMETERS = "forms.frontOffice.loginPage.parameters";



/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,18 +33,18 @@
*/
package fr.paris.lutece.plugins.forms.web;

import java.sql.Timestamp;
import java.time.LocalDateTime;
import java.util.*;
import java.util.stream.Collectors;
import fr.paris.lutece.plugins.forms.business.*;
import fr.paris.lutece.portal.service.util.AppLogService;
import org.apache.commons.collections.CollectionUtils;

import fr.paris.lutece.plugins.forms.service.EntryServiceManager;
import fr.paris.lutece.plugins.forms.util.FormsConstants;
import fr.paris.lutece.plugins.forms.validation.IValidator;
import fr.paris.lutece.plugins.genericattributes.business.GenericAttributeError;
import fr.paris.lutece.portal.service.util.AppLogService;
import org.apache.commons.collections.CollectionUtils;

import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

/**
*
Expand All @@ -55,8 +55,6 @@ public class FormResponseManager
{
private final List<Step> _listValidatedStep;
private final FormResponse _formResponse;
private boolean _bIsResponseLoadedFromBackup = false;
private boolean _isBackupResponseAlreadyInitiated = false;
/**
* Constructor
*
Expand Down Expand Up @@ -153,35 +151,11 @@ public Timestamp getFormResponseUpdateDate()
}
return updateDate;
}

public void setFormResponseUpdateDate(Timestamp updateDate)
{
FormResponse formResponse = getFormResponse();
formResponse.setUpdate(updateDate);
}
/**
* Give a boolean indicating that indicates if view (getViewStep) has been initialized from backup
* So with _isBackupResponseAlreadyInitiated and _bIsResponseLoadedFromBackup we can deduce if it's the first time the getViewStep is loaded with the backup response
*
* @return a boolean indicating that indicates if view has been initialized from backup
*/
public Boolean getIsBackupResponseAlreadyInitiated() {
return _isBackupResponseAlreadyInitiated;
}
public void setBackupResponseAlreadyInitiated(Boolean isBackupResponseAlreadyInitiated) {
_isBackupResponseAlreadyInitiated = isBackupResponseAlreadyInitiated;
}
/**
* Gives a boolean indicating if the response is loaded from backup
*
* @return a boolean indicating if the response is loaded from backup
*/
public Boolean getIsResponseLoadedFromBackup () {
return _bIsResponseLoadedFromBackup;
}
public void setIsResponseLoadedFromBackup (Boolean bIsResponseLoadedFromBackup) {
_bIsResponseLoadedFromBackup = bIsResponseLoadedFromBackup;
}

/**
* Initializes the steps order
Expand Down
Loading