All Downloads are FREE. Search and download functionalities are using the official Maven repository.
Please wait. This can take some minutes ...
Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance.
Project price only 1 $
You can buy this project and download/modify it how often you want.
pl.edu.icm.unity.engine.forms.RegistrationConfirmationSupport Maven / Gradle / Ivy
/*
* Copyright (c) 2016 ICM Uniwersytet Warszawski All rights reserved.
* See LICENCE.txt file for licensing information.
*/
package pl.edu.icm.unity.engine.forms;
import java.util.List;
import org.springframework.beans.factory.ObjectFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import pl.edu.icm.unity.base.attribute.Attribute;
import pl.edu.icm.unity.base.exceptions.EngineException;
import pl.edu.icm.unity.base.exceptions.InternalException;
import pl.edu.icm.unity.base.identity.IdentityParam;
import pl.edu.icm.unity.base.registration.BaseForm;
import pl.edu.icm.unity.base.registration.ConfirmationMode;
import pl.edu.icm.unity.base.registration.EnquiryForm;
import pl.edu.icm.unity.base.registration.EnquiryResponseState;
import pl.edu.icm.unity.base.registration.RegistrationForm;
import pl.edu.icm.unity.base.registration.RegistrationRequestState;
import pl.edu.icm.unity.base.registration.UserRequestState;
import pl.edu.icm.unity.base.translation.TranslationProfile;
import pl.edu.icm.unity.base.verifiable.VerifiableElement;
import pl.edu.icm.unity.engine.api.attributes.AttributeValueSyntax;
import pl.edu.icm.unity.engine.api.confirmation.EmailConfirmationManager;
import pl.edu.icm.unity.engine.api.confirmation.states.BaseEmailConfirmationState;
import pl.edu.icm.unity.engine.api.confirmation.states.EmailAttribiuteConfirmationState;
import pl.edu.icm.unity.engine.api.confirmation.states.EmailIdentityConfirmationState;
import pl.edu.icm.unity.engine.api.confirmation.states.RegistrationEmailConfirmationState.RequestType;
import pl.edu.icm.unity.engine.api.confirmation.states.RegistrationReqEmailAttribiuteConfirmationState;
import pl.edu.icm.unity.engine.api.confirmation.states.RegistrationReqEmailIdentityConfirmationState;
import pl.edu.icm.unity.engine.api.identity.IdentityTypesRegistry;
import pl.edu.icm.unity.engine.api.registration.FormAutomationSupport;
import pl.edu.icm.unity.engine.api.translation.form.RegistrationActionsRegistry;
import pl.edu.icm.unity.engine.attribute.AttributeTypeHelper;
import pl.edu.icm.unity.engine.group.GroupHelper;
import pl.edu.icm.unity.engine.translation.form.EnquiryTranslationProfile;
import pl.edu.icm.unity.engine.translation.form.FormAutomationSupportExt;
import pl.edu.icm.unity.engine.translation.form.RegistrationTranslationProfile;
/**
* Support class implementing sending of confirmation requests for verifiable identities and attributes.
* Cases when element is already confirmed are detected.
*
* @author K. Benedyczak
*/
@Component
public class RegistrationConfirmationSupport
{
public enum Phase
{
ON_SUBMIT(ConfirmationMode.ON_SUBMIT),
ON_ACCEPT(ConfirmationMode.ON_ACCEPT);
private ConfirmationMode supportedMode;
private Phase(ConfirmationMode supportedMode)
{
this.supportedMode = supportedMode;
}
}
@Autowired
private IdentityTypesRegistry identityTypesRegistry;
@Autowired
private EmailConfirmationManager confirmationManager;
@Autowired
private RegistrationActionsRegistry registrationTranslationActionsRegistry;
@Autowired
private AttributeTypeHelper atHelper;
@Autowired
private ObjectFactory formAutomationSupportFactory;
@Autowired
private GroupHelper groupHelper;
public void sendAttributeConfirmationRequest(RegistrationRequestState requestState,
Long entityId, RegistrationForm form, Phase phase) throws InternalException, EngineException
{
sendAttributeConfirmationRequest(RequestType.REGISTRATION, requestState, entityId, form, phase);
}
public void sendAttributeConfirmationRequest(EnquiryResponseState requestState,
EnquiryForm form, Long entityId, Phase phase) throws InternalException, EngineException
{
sendAttributeConfirmationRequest(RequestType.ENQUIRY, requestState, entityId, form, phase);
}
public void sendIdentityConfirmationRequest(RegistrationRequestState requestState,
Long entityId, RegistrationForm form, Phase phase) throws InternalException, EngineException
{
sendIdentityConfirmationRequest(RequestType.REGISTRATION, requestState, entityId, form, phase);
}
public void sendIdentityConfirmationRequest(EnquiryResponseState requestState,
EnquiryForm form, Long entityId, Phase phase) throws InternalException, EngineException
{
sendIdentityConfirmationRequest(RequestType.ENQUIRY, requestState, entityId, form, phase);
}
private void sendAttributeConfirmationRequest(RequestType type, UserRequestState> requestState,
Long entityId, BaseForm form, Phase phase) throws EngineException
{
List attributes = requestState.getRequest().getAttributes();
for (int i=0; i syntax = atHelper.getUnconfiguredSyntax(attr.getValueSyntax());
if (syntax.isEmailVerifiable())
{
for (String v : attr.getValues())
{
VerifiableElement val = (VerifiableElement) syntax.convertFromString(v);
if (val.isConfirmed())
continue;
BaseEmailConfirmationState state;
if (entityId == null)
{
state = new RegistrationReqEmailAttribiuteConfirmationState(
requestState.getRequestId(),
attr.getName(),
val.getValue(),
requestState.getRequest().getUserLocale(),
attr.getGroupPath(),
type);
} else
{
state = new EmailAttribiuteConfirmationState(
entityId,
attr.getName(),
val.getValue(),
requestState.getRequest().getUserLocale(),
attr.getGroupPath());
}
confirmationManager.sendConfirmationRequest(state);
}
}
}
}
private void sendIdentityConfirmationRequest(RequestType requestType, UserRequestState> requestState,
Long entityId, BaseForm form, Phase phase) throws EngineException
{
List identities = requestState.getRequest().getIdentities();
for (int i=0; i