Package org.cyclos.impl.users
Class PhoneServiceImpl
- java.lang.Object
-
- org.cyclos.impl.AbstractServerComponent
-
- org.cyclos.impl.AbstractNetworkedServerComponent
-
- org.cyclos.impl.BaseServiceImpl
-
- org.cyclos.impl.CRUDServiceImpl<Phone,QPhone,PhoneDTO,PhoneData,PhoneDataParams>
-
- org.cyclos.impl.users.PhoneServiceImpl
-
- All Implemented Interfaces:
CRUDServiceLocal<Phone,PhoneDTO,PhoneData,PhoneDataParams>,PhoneServiceLocal,CRUDService<PhoneDTO,PhoneData,PhoneDataParams>,CRUDWithConfirmationPasswordService<PhoneDTO,PhoneData,PhoneDataParams>,Service,PhoneService
@Service public class PhoneServiceImpl extends CRUDServiceImpl<Phone,QPhone,PhoneDTO,PhoneData,PhoneDataParams> implements PhoneServiceLocal
Implementation forPhoneService
-
-
Field Summary
-
Fields inherited from class org.cyclos.impl.CRUDServiceImpl
$, ATTR_CURRENT_COPY, cacheHandler, dtoClass, entityClass, extensionPointService, idPath, internalNamePath, namePath, ownerEntityIdPath, ownerEntityPath, ownerEntityPropertyName, passwordHandler, richTextHandler, withConfirmationPassword
-
Fields inherited from class org.cyclos.impl.AbstractNetworkedServerComponent
authHandler, conversionHandler, customFieldValueHandler, entityManagerHandler, groupsHandler, productsHandler, restBeanPropertyMapping, userLocatorHandler
-
Fields inherited from class org.cyclos.impl.AbstractServerComponent
accountHandler, configurationHandler, dataTranslationHandler, notificationHandler, transactionHandler, translationHandler
-
Fields inherited from interface org.cyclos.impl.users.PhoneServiceLocal
MAX_EXTENSION_LENGTH
-
-
Constructor Summary
Constructors Constructor Description PhoneServiceImpl()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voiddisableForSms(Long id, String confirmationPassword)Disables the given mobile phone to operate via SMSprotected voiddoRemove(Phone phone, boolean flush)May be overridden in order to perform logical removing, instead of physical removing, or to remove some extra relationships as wellvoidenableForSms(Long id)Enables the given mobile phone to operate via SMSPasswordInputDTOgetConfirmationPasswordInputForDisableSms(Long id)Returns data for the confirmation password needed to disable a phone by smsprotected PhoneDatagetData(Phone phone)Returns details data for the given entityPhonegetDefaultPhone(BasicUser user)Returns the default phone for this userPhonegetDefaultPhone(PhoneNature type, User user)Returns the default phone (landline or mobile) for the given user, or null if none foundprotected CreateDeviceConfirmationParamsgetDeviceConfirmationParams(PhoneDTO dto, Phone entity, CRUDOperation operation)If the confirmation password must be checked then subclasses must overwrite this method to return a no-nullCreateDeviceConfirmationParamsobject.StringgetExampleNumber(PhoneNature nature)Returns an example number for the given phone naturePhoneListDatagetPhoneListData(BasicUser user)Returns data containing all phones belonging to the given userPhoneListDatagetPhoneListData(UserLocatorVO locator)Returns data containing all phones belonging to the given userValidatorgetValidator(PhoneDTO dto, BasicUser user)Returns the validator for the given phone and owner uservoidinitialize()booleanisVerificationCodeSentAndNotExpired(MobilePhone mobile)Returns whether there is a valid verification code sent for the given mobile phoneList<Phone>listByUser(BasicUser user, PhoneNature nature)Returns the visible phones of the given user filtered by nature if not null.List<MobilePhone>listEnabledPhonesForSmsNotification(BasicUser user, boolean includeOperators)Returns all phones that should be used for SMS notifications.PhoneVOloadByNumber(String number)Returns a mobile phone by number, making sure it is visiblePhoneloadByRawNumber(User user, String rawNumber)Loads a given user's number by its raw numbervoidmarkVerified(MobilePhone phone)Marks a phone as verified WARN: This method doesn't keep trace of failed actionsPhonenewEntity(PhoneDataParams params)Should be implemented in order to instantiate a new entity based on the given context parametersStringnormalizeNumber(ConfigurationAccessor configuration, String rawNumber)Normalizes a phone number for the given configuration, returning null when not a valid numberprotected voidonAfterRemove(Phone phone)May be overridden in order to perform custom logic after removing an entityprotected voidonAfterSave(Phone phone, Phone currentCopy, Object dataFromOnBeforeSave)May be overridden in order to perform custom logic after saving an entityprotected voidonBeforeRemove(Phone phone)May be overridden in order to perform custom logic before removing an entityprotected ObjectonBeforeSave(Phone phone, Phone currentCopy)May be overridden in order to perform custom logic before saving an entity.protected voidregisterNetworkMappings(NetworkPathRegistry networkPathRegistry)Needs to be overridden by subclasses to register the path up to the networkvoidremoveAll(BasicUser basicUser)Removes all phones of the given userprotected ExtensionPointAccessorresolveExtensionPointAccessor(CRUDOperation operation, Phone phone)Should be overridden by subclasses which have extension pointsprotected ValidatorresolveValidator(PhoneDTO dto)StringsendVerificationCode(Long id)Sends a verification code to a mobile phone via SMS.protected booleanshouldCheckConfirmationPassword(Phone phone, CRUDOperation operation)Controls whether confirmation password should be checked for the given entity and operation.protected org.apache.commons.collections4.BidiMap<Class<? extends Phone>,Class<? extends PhoneDTO>>subClassMappings()Should be overridden by subclasses which handle entity / dto hierarchies.PhonetoEntity(PhoneDTO dto)Converts the given DTO in an entity, handling theCRUDServiceImpl.subClassMappings()mappings for subclassesCodeVerificationStatusverify(Long id, String verificationCode)Verifies a mobile phone with a code received via SMS.voidverifyAndEnableForSms(MobilePhone phone)Marks the given phone as verified and enabled for SMS-
Methods inherited from class org.cyclos.impl.CRUDServiceImpl
addCustomInternalNameValidations, addCustomNameValidations, checkConfirmationPassword, find, findAll, from, getConfirmationPasswordInput, getConfirmationPasswordInputForRemove, getData, getDataForNew, getEntityClass, getEntityInternalNameKey, getExcludedPropertiesToDTO, getExcludedPropertiesToEntity, getNameLabel, getUniqueInternalNameQuery, getUniqueNameQuery, isEntityInternalNameRequired, isNameRequired, load, logEntity, preProcessCurrentCopy, remove, remove, removeAll, removeAll, removeAllWithConfirmationPassword, removeWithConfirmationPassword, resolveDTOType, resolveEntityType, save, saveOrder, saveSkippingEntityLog, saveWithConfirmationPassword, toDTO, validate
-
Methods inherited from class org.cyclos.impl.BaseServiceImpl
initializeNetworkMappings
-
Methods inherited from class org.cyclos.impl.AbstractNetworkedServerComponent
canManage, checkManagesUser, checkPermission, checkRelatesToUser, checkValue, clearAlreadyValidated, getBaseEntityManagerHandler, getConfiguration, getLoggedBasicUser, getLoggedUser, getProducts, getTranslatedName, getTranslatedValue, hasPermission, hasValue, inSameNetwork, inSameNetworkOrGlobal, isAdmin, isAlreadyValidated, isBroker, isGlobalAdmin, isGlobalAdminInNetwork, isGuest, isLoggedIn, isMember, isMemberOnly, isNetworkAdmin, isOperator, isRelatedToUser, isSystem, isUserManager, isUserManagerOf, message, message, permission, permission, permissionOptionalValue, permissionOptionalValue, toDate, toDateTime, validate
-
Methods inherited from class org.cyclos.impl.AbstractServerComponent
dataTranslationProxy, delete, detach, find, flush, from, getApplicationContext, getFormatter, getFormatter, getFormatter, getLogger, getRemoteAddress, getSessionData, mailContentBuilder, message, message, persist, processBatch, processBatch, refresh, remove, selectFrom, subQuery, update
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.cyclos.services.CRUDService
getData, getDataForNew, load, remove, removeAll, save
-
Methods inherited from interface org.cyclos.impl.CRUDServiceLocal
find, findAll, getEntityClass, remove, removeAll, saveEntity, saveSkippingEntityLog, toDTO, validate
-
Methods inherited from interface org.cyclos.services.CRUDWithConfirmationPasswordService
getConfirmationPasswordInputForRemove, removeAllWithConfirmationPassword, removeWithConfirmationPassword, saveWithConfirmationPassword
-
-
-
-
Method Detail
-
disableForSms
public void disableForSms(Long id, String confirmationPassword) throws FrameworkException
Description copied from interface:PhoneServiceDisables the given mobile phone to operate via SMS- Specified by:
disableForSmsin interfacePhoneService- Throws:
FrameworkException
-
enableForSms
public void enableForSms(Long id) throws FrameworkException
Description copied from interface:PhoneServiceEnables the given mobile phone to operate via SMS- Specified by:
enableForSmsin interfacePhoneService- Throws:
FrameworkException
-
getConfirmationPasswordInputForDisableSms
public PasswordInputDTO getConfirmationPasswordInputForDisableSms(Long id) throws FrameworkException
Description copied from interface:PhoneServiceReturns data for the confirmation password needed to disable a phone by sms- Specified by:
getConfirmationPasswordInputForDisableSmsin interfacePhoneService- Throws:
FrameworkException
-
getDefaultPhone
public Phone getDefaultPhone(BasicUser user)
Description copied from interface:PhoneServiceLocalReturns the default phone for this user- Specified by:
getDefaultPhonein interfacePhoneServiceLocal
-
getDefaultPhone
public Phone getDefaultPhone(PhoneNature type, User user)
Description copied from interface:PhoneServiceLocalReturns the default phone (landline or mobile) for the given user, or null if none found- Specified by:
getDefaultPhonein interfacePhoneServiceLocal
-
getExampleNumber
public String getExampleNumber(PhoneNature nature) throws FrameworkException
Description copied from interface:PhoneServiceLocalReturns an example number for the given phone nature- Specified by:
getExampleNumberin interfacePhoneServiceLocal- Throws:
FrameworkException
-
getPhoneListData
public PhoneListData getPhoneListData(BasicUser user)
Description copied from interface:PhoneServiceLocalReturns data containing all phones belonging to the given user- Specified by:
getPhoneListDatain interfacePhoneServiceLocal
-
getPhoneListData
public PhoneListData getPhoneListData(UserLocatorVO locator)
Description copied from interface:PhoneServiceReturns data containing all phones belonging to the given user- Specified by:
getPhoneListDatain interfacePhoneService
-
getValidator
public Validator getValidator(PhoneDTO dto, BasicUser user)
Description copied from interface:PhoneServiceLocalReturns the validator for the given phone and owner user- Specified by:
getValidatorin interfacePhoneServiceLocal
-
initialize
@PostConstruct public void initialize()
-
isVerificationCodeSentAndNotExpired
public boolean isVerificationCodeSentAndNotExpired(MobilePhone mobile)
Description copied from interface:PhoneServiceLocalReturns whether there is a valid verification code sent for the given mobile phone- Specified by:
isVerificationCodeSentAndNotExpiredin interfacePhoneServiceLocal
-
listByUser
public List<Phone> listByUser(BasicUser user, PhoneNature nature)
Description copied from interface:PhoneServiceLocalReturns the visible phones of the given user filtered by nature if not null. If the current user manages the given user, hidden phones are returned- Specified by:
listByUserin interfacePhoneServiceLocal
-
listEnabledPhonesForSmsNotification
public List<MobilePhone> listEnabledPhonesForSmsNotification(BasicUser user, boolean includeOperators)
Description copied from interface:PhoneServiceLocalReturns all phones that should be used for SMS notifications. If the includeOperators flag is true, also includes any alias-operator phones which are enabled for SMS.- Specified by:
listEnabledPhonesForSmsNotificationin interfacePhoneServiceLocal
-
loadByNumber
public PhoneVO loadByNumber(String number) throws FrameworkException
Description copied from interface:PhoneServiceReturns a mobile phone by number, making sure it is visible- Specified by:
loadByNumberin interfacePhoneService- Throws:
FrameworkException
-
loadByRawNumber
public Phone loadByRawNumber(User user, String rawNumber)
Description copied from interface:PhoneServiceLocalLoads a given user's number by its raw number- Specified by:
loadByRawNumberin interfacePhoneServiceLocal
-
markVerified
public void markVerified(MobilePhone phone)
Description copied from interface:PhoneServiceLocalMarks a phone as verified WARN: This method doesn't keep trace of failed actions- Specified by:
markVerifiedin interfacePhoneServiceLocal
-
newEntity
public Phone newEntity(PhoneDataParams params)
Description copied from class:CRUDServiceImplShould be implemented in order to instantiate a new entity based on the given context parameters- Specified by:
newEntityin interfaceCRUDServiceLocal<Phone,PhoneDTO,PhoneData,PhoneDataParams>- Specified by:
newEntityin classCRUDServiceImpl<Phone,QPhone,PhoneDTO,PhoneData,PhoneDataParams>
-
normalizeNumber
public String normalizeNumber(ConfigurationAccessor configuration, String rawNumber) throws FrameworkException
Description copied from interface:PhoneServiceLocalNormalizes a phone number for the given configuration, returning null when not a valid number- Specified by:
normalizeNumberin interfacePhoneServiceLocal- Throws:
FrameworkException
-
removeAll
public void removeAll(BasicUser basicUser)
Description copied from interface:PhoneServiceLocalRemoves all phones of the given user- Specified by:
removeAllin interfacePhoneServiceLocal
-
sendVerificationCode
public String sendVerificationCode(Long id) throws FrameworkException, SmsSendingException
Description copied from interface:PhoneServiceSends a verification code to a mobile phone via SMS. The phone number is returned.- Specified by:
sendVerificationCodein interfacePhoneService- Throws:
SmsSendingException- If the SMS message couldn't be sendIllegalActionException- If the mobile phone is already verifiedFrameworkException
-
toEntity
public Phone toEntity(PhoneDTO dto)
Description copied from class:CRUDServiceImplConverts the given DTO in an entity, handling theCRUDServiceImpl.subClassMappings()mappings for subclasses- Specified by:
toEntityin interfaceCRUDServiceLocal<Phone,PhoneDTO,PhoneData,PhoneDataParams>- Overrides:
toEntityin classCRUDServiceImpl<Phone,QPhone,PhoneDTO,PhoneData,PhoneDataParams>
-
verify
public CodeVerificationStatus verify(Long id, String verificationCode) throws FrameworkException
Description copied from interface:PhoneServiceVerifies a mobile phone with a code received via SMS.- Specified by:
verifyin interfacePhoneService- Throws:
FrameworkException
-
verifyAndEnableForSms
public void verifyAndEnableForSms(MobilePhone phone) throws FrameworkException
Description copied from interface:PhoneServiceLocalMarks the given phone as verified and enabled for SMS- Specified by:
verifyAndEnableForSmsin interfacePhoneServiceLocal- Throws:
FrameworkException
-
doRemove
protected void doRemove(Phone phone, boolean flush)
Description copied from class:CRUDServiceImplMay be overridden in order to perform logical removing, instead of physical removing, or to remove some extra relationships as well- Overrides:
doRemovein classCRUDServiceImpl<Phone,QPhone,PhoneDTO,PhoneData,PhoneDataParams>
-
getData
protected PhoneData getData(Phone phone)
Description copied from class:CRUDServiceImplReturns details data for the given entity- Specified by:
getDatain classCRUDServiceImpl<Phone,QPhone,PhoneDTO,PhoneData,PhoneDataParams>
-
getDeviceConfirmationParams
protected CreateDeviceConfirmationParams getDeviceConfirmationParams(PhoneDTO dto, Phone entity, CRUDOperation operation)
Description copied from class:CRUDServiceImplIf the confirmation password must be checked then subclasses must overwrite this method to return a no-nullCreateDeviceConfirmationParamsobject. This object is required to validate the confirmation when the operation was confirmed with a device.- Overrides:
getDeviceConfirmationParamsin classCRUDServiceImpl<Phone,QPhone,PhoneDTO,PhoneData,PhoneDataParams>- Parameters:
dto- , it can be null, subclasses must take it into account. E.g: to disable a mobile phone for SMS, the confirmation password must be check and for this case there is no DTO instance.entity- never null, represents the current value (i.e before apply the dto).
-
onAfterRemove
protected void onAfterRemove(Phone phone)
Description copied from class:CRUDServiceImplMay be overridden in order to perform custom logic after removing an entity- Overrides:
onAfterRemovein classCRUDServiceImpl<Phone,QPhone,PhoneDTO,PhoneData,PhoneDataParams>
-
onAfterSave
protected void onAfterSave(Phone phone, Phone currentCopy, Object dataFromOnBeforeSave)
Description copied from class:CRUDServiceImplMay be overridden in order to perform custom logic after saving an entity- Overrides:
onAfterSavein classCRUDServiceImpl<Phone,QPhone,PhoneDTO,PhoneData,PhoneDataParams>
-
onBeforeRemove
protected void onBeforeRemove(Phone phone)
Description copied from class:CRUDServiceImplMay be overridden in order to perform custom logic before removing an entity- Overrides:
onBeforeRemovein classCRUDServiceImpl<Phone,QPhone,PhoneDTO,PhoneData,PhoneDataParams>
-
onBeforeSave
protected Object onBeforeSave(Phone phone, Phone currentCopy)
Description copied from class:CRUDServiceImplMay be overridden in order to perform custom logic before saving an entity. Any returned value will be passed to theCRUDServiceImpl.onAfterSave(BaseEntity, BaseEntity, Object)method- Overrides:
onBeforeSavein classCRUDServiceImpl<Phone,QPhone,PhoneDTO,PhoneData,PhoneDataParams>
-
registerNetworkMappings
protected void registerNetworkMappings(NetworkPathRegistry networkPathRegistry)
Description copied from class:BaseServiceImplNeeds to be overridden by subclasses to register the path up to the network- Specified by:
registerNetworkMappingsin classBaseServiceImpl
-
resolveExtensionPointAccessor
protected ExtensionPointAccessor resolveExtensionPointAccessor(CRUDOperation operation, Phone phone)
Description copied from class:CRUDServiceImplShould be overridden by subclasses which have extension points- Overrides:
resolveExtensionPointAccessorin classCRUDServiceImpl<Phone,QPhone,PhoneDTO,PhoneData,PhoneDataParams>
-
resolveValidator
protected Validator resolveValidator(PhoneDTO dto)
- Specified by:
resolveValidatorin classCRUDServiceImpl<Phone,QPhone,PhoneDTO,PhoneData,PhoneDataParams>
-
shouldCheckConfirmationPassword
protected boolean shouldCheckConfirmationPassword(Phone phone, CRUDOperation operation)
Description copied from class:CRUDServiceImplControls whether confirmation password should be checked for the given entity and operation. By default returns true if this service indirectly implementsCRUDWithConfirmationPasswordService(for example, if the remote service interface extends it).- Overrides:
shouldCheckConfirmationPasswordin classCRUDServiceImpl<Phone,QPhone,PhoneDTO,PhoneData,PhoneDataParams>
-
subClassMappings
protected org.apache.commons.collections4.BidiMap<Class<? extends Phone>,Class<? extends PhoneDTO>> subClassMappings()
Description copied from class:CRUDServiceImplShould be overridden by subclasses which handle entity / dto hierarchies. The map key should be the entity class, while the map value, the DTO class- Overrides:
subClassMappingsin classCRUDServiceImpl<Phone,QPhone,PhoneDTO,PhoneData,PhoneDataParams>
-
-