pl.edu.icm.unity.engine.confirmation.facilities.RegistrationReqEmailAttributeFacility Maven / Gradle / Ivy
/*
* Copyright (c) 2013 ICM Uniwersytet Warszawski All rights reserved.
* See LICENCE.txt file for licensing information.
*/
package pl.edu.icm.unity.engine.confirmation.facilities;
import java.util.Collection;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationEventPublisher;
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.message.MessageSource;
import pl.edu.icm.unity.base.registration.EnquiryResponseState;
import pl.edu.icm.unity.base.registration.RegistrationRequestState;
import pl.edu.icm.unity.base.registration.UserRequestState;
import pl.edu.icm.unity.engine.api.attributes.AttributeValueSyntax;
import pl.edu.icm.unity.engine.api.confirmation.EmailConfirmationRedirectURLBuilder.ConfirmedElementType;
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.attribute.AttributeTypeHelper;
import pl.edu.icm.unity.store.api.generic.EnquiryFormDB;
import pl.edu.icm.unity.store.api.generic.EnquiryResponseDB;
import pl.edu.icm.unity.store.api.generic.RegistrationFormDB;
import pl.edu.icm.unity.store.api.generic.RegistrationRequestDB;
import pl.edu.icm.unity.base.tx.Transactional;
import pl.edu.icm.unity.store.api.tx.TxManager;
/**
* Attribute from registration request confirmation facility.
*
* @author P. Piernik
*
*/
@Component
public class RegistrationReqEmailAttributeFacility extends RegistrationEmailFacility
{
public static final String NAME = "registrationRequestVerificator";
private AttributeTypeHelper atHelper;
@Autowired
public RegistrationReqEmailAttributeFacility(RegistrationRequestDB requestDB, EnquiryResponseDB enquiryResponsesDB,
RegistrationFormDB formsDB, EnquiryFormDB enquiresDB,
ApplicationEventPublisher publisher,
AttributeTypeHelper atHelper,
TxManager txMan, MessageSource msg)
{
super(requestDB, enquiryResponsesDB, formsDB, enquiresDB, publisher, txMan, msg);
this.atHelper = atHelper;
}
@Override
public String getName()
{
return RegistrationReqEmailAttribiuteConfirmationState.FACILITY_ID;
}
@Override
public String getDescription()
{
return "Confirms attributes from registration request with verifiable values";
}
@Override
protected boolean confirmElements(UserRequestState> reqState,
RegistrationReqEmailAttribiuteConfirmationState attrState)
{
Collection confirmedList = confirmAttributes(reqState.getRequest().getAttributes(),
attrState.getType(), attrState.getGroup(), attrState.getValue(), atHelper);
return (confirmedList.size() > 0);
}
@Override
@Transactional
public void processAfterSendRequest(String state) throws EngineException
{
RegistrationReqEmailAttribiuteConfirmationState attrState =
new RegistrationReqEmailAttribiuteConfirmationState(state);
String requestId = attrState.getRequestId();
UserRequestState> reqState = attrState.getRequestType() == RequestType.REGISTRATION ?
requestDB.get(requestId) : enquiryResponsesDB.get(requestId);
for (Attribute attr : reqState.getRequest().getAttributes())
{
if (attr == null)
continue;
AttributeValueSyntax> syntax = atHelper.getUnconfiguredSyntax(attr.getValueSyntax());
if (syntax.isEmailVerifiable())
updateConfirmationForAttributeValues(attr.getValues(), syntax, attrState.getValue());
}
if (attrState.getRequestType() == RequestType.REGISTRATION)
requestDB.update((RegistrationRequestState) reqState);
else
enquiryResponsesDB.update((EnquiryResponseState) reqState);
}
@Override
public RegistrationReqEmailAttribiuteConfirmationState parseState(String state)
{
return new RegistrationReqEmailAttribiuteConfirmationState(state);
}
@Override
protected ConfirmedElementType getConfirmedElementType(
RegistrationReqEmailAttribiuteConfirmationState state)
{
return ConfirmedElementType.attribute;
}
}