Package org.cyclos.impl.marketplace
Class AdServiceImpl
- java.lang.Object
-
- org.cyclos.impl.AbstractServerComponent
-
- org.cyclos.impl.AbstractNetworkedServerComponent
-
- org.cyclos.impl.BaseServiceImpl
-
- org.cyclos.impl.CRUDServiceImpl<BasicAd,QBasicAd,BasicAdDTO,AdDetailsData,AdDataParams>
-
- org.cyclos.impl.marketplace.AdServiceImpl
-
- All Implemented Interfaces:
CRUDServiceLocal<BasicAd,BasicAdDTO,AdDetailsData,AdDataParams>,AdServiceLocal,CRUDService<BasicAdDTO,AdDetailsData,AdDataParams>,CRUDWithConfirmationPasswordService<BasicAdDTO,AdDetailsData,AdDataParams>,AdService,Service
@Service public class AdServiceImpl extends CRUDServiceImpl<BasicAd,QBasicAd,BasicAdDTO,AdDetailsData,AdDataParams> implements AdServiceLocal
Service implementation class for Advertisements
-
-
Field Summary
Fields Modifier and Type Field Description protected AdAddressServiceLocaladAddressServiceprotected AdCategoryServiceLocaladCategoryServiceprotected AdCustomFieldServiceLocaladCustomFieldServiceprotected AdDeliveryMethodServiceLocaladDeliveryMethodServiceprotected UserAddressServiceLocaladdressServiceprotected AdImageServiceLocaladImageServiceprotected AdInterestServiceLocaladInterestServiceprotected AdQuestionServiceLocaladQuestionServiceprotected AdWebShopSettingServiceLocaladWebShopSettingServiceprotected CurrencyServiceLocalcurrencyServiceprotected CustomFieldValueHandlercustomFieldValueServiceprotected CustomOperationServiceLocalcustomOperationServiceprotected EntityLogServiceLocalentityLogServiceprotected ExportFormatServiceLocalexportFormatServiceprotected MessageCategoryServiceLocalmessageCategoryServiceprotected MessageServiceLocalmessageServiceprotected UserCustomFieldServiceLocaluserCustomFieldServiceprotected UserServiceLocaluserService-
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.marketplace.AdServiceLocal
ATTR_AD_TYPE, ATTR_USER
-
-
Constructor Summary
Constructors Constructor Description AdServiceImpl()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voidaddCustomNameValidations(Property name, BasicAdDTO namedDTO)This method may be overridden to add custom validations for the NAME property.booleanadRequiresAuthorization(BasicAd ad)Returns true if the ad requires authorization for publishing.voidapprove(@NotNull BasicAdVO adVO)Approves the publication of an advertisement in statusAdStatus.PENDING.booleancanViewAddresses(User adOwner)Returns if the given ad owner or a user manager can view addresses in an adbooleancanViewAuthorizationNotes(BasicAd ad)Returns true if the logged user can view the authorization notes of the given adbooleancanViewPendings(AdType adType, User owner, boolean brokeredSearch)Returns true if the logged user can view pending ads with the given restrictionsvoidcheckStatus(boolean guest, boolean ownAds, BasicAdQuery params, User owner)Check the statuses in the query params according to the relationship between the logged user and the ad owner.intdisableInCurrencies(User user, Collection<Currency> currencies)Disables all the ads for the given user which are related to the given currenciesprotected voiddoRemove(BasicAd ad, boolean flush)May be overridden in order to perform logical removing, instead of physical removing, or to remove some extra relationships as wellFileInfoexportAd(ExportFormatVO formatVO, BasicAdVO adVO)Exports the given advertisement to fileAdWebShopfindByOwnerAndNumber(User user, String adNumber)Returns an AdWebShop by product owner and number, or throwsEntityNotFoundExceptionif not foundAdSearchDatagetAdSearchData(AdType type, boolean overBrokeredUsers)Returns data for searching advertisementsIntegergetAdvertisementsCount(User owner, AdType type)Counts the number of ads filtering by status, for more details about the filters seeAdServiceLocal.checkStatus(boolean, boolean, BasicAdQuery, User)}Set<AdCategoryVO>getCategories(Long adId)Returns the categories for the given Ad idprotected AdDetailsDatagetData(BasicAd ad)Returns details data for the given entityprotected StringgetNameLabel(BasicAdDTO dto)protected Pair<DBQuery<?>,String>getUniqueNameQuery(BasicAdDTO dto)This method may be overridden to customize the default global unique validation for the name property.UserAdsSearchDatagetUserAdsSearchData(UserLocatorVO locator, AdType type)Returns data for searching advertisementsAdViewDatagetViewData(BasicAdVO adVO)Returns data for viewing details of an advertisementbooleanhasManageAccess(Date deletedDate, AdStatus status, AdStatus persistedStatus, AdType type, User owner)Returns true if the logged user has manage access to the ad with the given conditionsbooleanhasManageAccess(BasicAd ad)Returns true if the logged user has manage access for the given ad.booleanhasManageAccess(AdType type, User owner)Returns true if the logged user can manage ads of the given type and user.List<SitemapItemVO>listForSitemap()Returns the sitemap entries for all enabled advertisements in this networkBasicAdVOloadVO(BasicAdVO adVO)Loads a VO, by idBasicAdnewEntity(AdDataParams params)Should be implemented in order to instantiate a new entity based on the given context parametersprotected voidonAfterSave(BasicAd ad, BasicAd currentCopy, Object dataFromOnBeforeSave)May be overridden in order to perform custom logic after saving an entityprotected ObjectonBeforeSave(BasicAd ad, BasicAd currentCopy)May be overridden in order to perform custom logic before saving an entity.protected voidpreProcessCurrentCopy(BasicAdDTO dto, BasicAd currentCopy)This method is invoked before saving the entity and also, if the log is enabled, before removing.protected voidregisterNetworkMappings(NetworkPathRegistry networkPathRegistry)Needs to be overridden by subclasses to register the path up to the networkvoidreject(@NotNull BasicAdVO adVO, String comments)Rejects the publication of an advertisement in statusAdStatus.PENDING.voidremoveAll(User user)Removes all the advertisements for the given userprotected ExtensionPointAccessorresolveExtensionPointAccessor(CRUDOperation operation, BasicAd ad)Should be overridden by subclasses which have extension pointsprotected ValidatorresolveValidator(BasicAdDTO dto)Page<BasicAdVO>search(BasicAdQuery params)Searches for advertisements, according to the given query parametersvoidsetAsDraft(BasicAdVO adVO, String comments)Sets the ad back to draft status.voidsetHidden(BasicAdVO adVO, boolean hidden)Hides or unhides the ad according to given hidden parameter.protected org.apache.commons.collections4.BidiMap<Class<? extends BasicAd>,Class<? extends BasicAdDTO>>subClassMappings()Should be overridden by subclasses which handle entity / dto hierarchies.voidsubmitForAuthorization(@NotNull BasicAdVO adVO)Submits the given ad for authorization.BasicAdDTOtoDTO(BasicAd entity)Converts the given entity in a DTO, handling theCRUDServiceImpl.subClassMappings()mappings for subclasses-
Methods inherited from class org.cyclos.impl.CRUDServiceImpl
addCustomInternalNameValidations, checkConfirmationPassword, find, findAll, from, getConfirmationPasswordInput, getConfirmationPasswordInputForRemove, getData, getDataForNew, getDeviceConfirmationParams, getEntityClass, getEntityInternalNameKey, getExcludedPropertiesToDTO, getExcludedPropertiesToEntity, getUniqueInternalNameQuery, isEntityInternalNameRequired, isNameRequired, load, logEntity, onAfterRemove, onBeforeRemove, remove, remove, removeAll, removeAll, removeAllWithConfirmationPassword, removeWithConfirmationPassword, resolveDTOType, resolveEntityType, save, saveOrder, saveSkippingEntityLog, saveWithConfirmationPassword, shouldCheckConfirmationPassword, toEntity, 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, toEntity, validate
-
-
-
-
Field Detail
-
customFieldValueService
@Autowired protected CustomFieldValueHandler customFieldValueService
-
customOperationService
@Autowired protected CustomOperationServiceLocal customOperationService
-
adInterestService
@Autowired protected AdInterestServiceLocal adInterestService
-
messageService
@Autowired protected MessageServiceLocal messageService
-
messageCategoryService
@Autowired protected MessageCategoryServiceLocal messageCategoryService
-
currencyService
@Autowired protected CurrencyServiceLocal currencyService
-
adImageService
@Autowired protected AdImageServiceLocal adImageService
-
adAddressService
@Autowired protected AdAddressServiceLocal adAddressService
-
adQuestionService
@Autowired protected AdQuestionServiceLocal adQuestionService
-
adCustomFieldService
@Autowired protected AdCustomFieldServiceLocal adCustomFieldService
-
exportFormatService
@Autowired protected ExportFormatServiceLocal exportFormatService
-
adCategoryService
@Autowired protected AdCategoryServiceLocal adCategoryService
-
adDeliveryMethodService
@Autowired protected AdDeliveryMethodServiceLocal adDeliveryMethodService
-
userService
@Autowired protected UserServiceLocal userService
-
userCustomFieldService
@Autowired protected UserCustomFieldServiceLocal userCustomFieldService
-
adWebShopSettingService
@Autowired protected AdWebShopSettingServiceLocal adWebShopSettingService
-
addressService
@Autowired protected UserAddressServiceLocal addressService
-
entityLogService
@Autowired protected EntityLogServiceLocal entityLogService
-
-
Method Detail
-
adRequiresAuthorization
public boolean adRequiresAuthorization(BasicAd ad)
Description copied from interface:AdServiceLocalReturns true if the ad requires authorization for publishing.- Specified by:
adRequiresAuthorizationin interfaceAdServiceLocal
-
approve
public void approve(@NotNull @NotNull BasicAdVO adVO) throws FrameworkExceptionDescription copied from interface:AdServiceApproves the publication of an advertisement in statusAdStatus.PENDING. The new status will beAdStatus.ACTIVE.- Specified by:
approvein interfaceAdService- Throws:
FrameworkException
-
canViewAddresses
public boolean canViewAddresses(User adOwner)
Description copied from interface:AdServiceLocalReturns if the given ad owner or a user manager can view addresses in an ad- Specified by:
canViewAddressesin interfaceAdServiceLocal
-
canViewAuthorizationNotes
public boolean canViewAuthorizationNotes(BasicAd ad)
Description copied from interface:AdServiceLocalReturns true if the logged user can view the authorization notes of the given ad- Specified by:
canViewAuthorizationNotesin interfaceAdServiceLocal
-
canViewPendings
public boolean canViewPendings(AdType adType, User owner, boolean brokeredSearch)
Description copied from interface:AdServiceLocalReturns true if the logged user can view pending ads with the given restrictions- Specified by:
canViewPendingsin interfaceAdServiceLocal
-
checkStatus
public void checkStatus(boolean guest, boolean ownAds, BasicAdQuery params, User owner)Description copied from interface:AdServiceLocalCheck the statuses in the query params according to the relationship between the logged user and the ad owner. if no status is passed in the query params, all the allowed ones are setted.- Specified by:
checkStatusin interfaceAdServiceLocal
-
disableInCurrencies
public int disableInCurrencies(User user, Collection<Currency> currencies)
Description copied from interface:AdServiceLocalDisables all the ads for the given user which are related to the given currencies- Specified by:
disableInCurrenciesin interfaceAdServiceLocal
-
exportAd
public FileInfo exportAd(ExportFormatVO formatVO, BasicAdVO adVO) throws FrameworkException
Description copied from interface:AdServiceExports the given advertisement to file- Specified by:
exportAdin interfaceAdService- Throws:
FrameworkException
-
findByOwnerAndNumber
public AdWebShop findByOwnerAndNumber(User user, String adNumber)
Description copied from interface:AdServiceLocalReturns an AdWebShop by product owner and number, or throwsEntityNotFoundExceptionif not found- Specified by:
findByOwnerAndNumberin interfaceAdServiceLocal
-
getAdSearchData
public AdSearchData getAdSearchData(AdType type, boolean overBrokeredUsers)
Description copied from interface:AdServiceReturns data for searching advertisements- Specified by:
getAdSearchDatain interfaceAdService
-
getAdvertisementsCount
public Integer getAdvertisementsCount(User owner, AdType type)
Description copied from interface:AdServiceLocalCounts the number of ads filtering by status, for more details about the filters seeAdServiceLocal.checkStatus(boolean, boolean, BasicAdQuery, User)}- Specified by:
getAdvertisementsCountin interfaceAdServiceLocal
-
getCategories
public Set<AdCategoryVO> getCategories(Long adId)
Description copied from interface:AdServiceLocalReturns the categories for the given Ad id- Specified by:
getCategoriesin interfaceAdServiceLocal
-
getUserAdsSearchData
public UserAdsSearchData getUserAdsSearchData(UserLocatorVO locator, AdType type)
Description copied from interface:AdServiceReturns data for searching advertisements- Specified by:
getUserAdsSearchDatain interfaceAdService
-
getViewData
public AdViewData getViewData(BasicAdVO adVO) throws EntityNotFoundException
Description copied from interface:AdServiceReturns data for viewing details of an advertisement- Specified by:
getViewDatain interfaceAdService- Throws:
EntityNotFoundException
-
hasManageAccess
public boolean hasManageAccess(AdType type, User owner)
Description copied from interface:AdServiceLocalReturns true if the logged user can manage ads of the given type and user. Doesn't takes into account the authorization status of advertisements.- Specified by:
hasManageAccessin interfaceAdServiceLocal
-
hasManageAccess
public boolean hasManageAccess(BasicAd ad)
Description copied from interface:AdServiceLocalReturns true if the logged user has manage access for the given ad.- Specified by:
hasManageAccessin interfaceAdServiceLocal
-
hasManageAccess
public boolean hasManageAccess(Date deletedDate, AdStatus status, AdStatus persistedStatus, AdType type, User owner)
Description copied from interface:AdServiceLocalReturns true if the logged user has manage access to the ad with the given conditions- Specified by:
hasManageAccessin interfaceAdServiceLocal
-
listForSitemap
public List<SitemapItemVO> listForSitemap()
Description copied from interface:AdServiceLocalReturns the sitemap entries for all enabled advertisements in this network- Specified by:
listForSitemapin interfaceAdServiceLocal
-
loadVO
public BasicAdVO loadVO(BasicAdVO adVO) throws FrameworkException
Description copied from interface:AdServiceLoads a VO, by id- Specified by:
loadVOin interfaceAdService- Throws:
FrameworkException
-
newEntity
public BasicAd newEntity(AdDataParams 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<BasicAd,BasicAdDTO,AdDetailsData,AdDataParams>- Specified by:
newEntityin classCRUDServiceImpl<BasicAd,QBasicAd,BasicAdDTO,AdDetailsData,AdDataParams>
-
reject
public void reject(@NotNull @NotNull BasicAdVO adVO, String comments) throws FrameworkExceptionDescription copied from interface:AdServiceRejects the publication of an advertisement in statusAdStatus.PENDING. The new status will beAdStatus.DRAFT.- Specified by:
rejectin interfaceAdService- Throws:
FrameworkException
-
removeAll
public void removeAll(User user)
Description copied from interface:AdServiceLocalRemoves all the advertisements for the given user- Specified by:
removeAllin interfaceAdServiceLocal
-
search
public Page<BasicAdVO> search(BasicAdQuery params)
Description copied from interface:AdServiceSearches for advertisements, according to the given query parameters
-
setAsDraft
public void setAsDraft(BasicAdVO adVO, String comments)
Description copied from interface:AdServiceSets the ad back to draft status.- Specified by:
setAsDraftin interfaceAdService
-
setHidden
public void setHidden(BasicAdVO adVO, boolean hidden)
Description copied from interface:AdServiceHides or unhides the ad according to given hidden parameter.
-
submitForAuthorization
public void submitForAuthorization(@NotNull @NotNull BasicAdVO adVO)Description copied from interface:AdServiceSubmits the given ad for authorization. Only available if the logged user can manage the given ad and in case it isn't the owner it can't manage pending ads. NOTE: The main web doesn't use this method instead it saves the ad with theAdStatus.PENDINGstatus. This is used only by the REST services but we should refactor the marketplace module too to use actions instead of save the ad each time the status changes.- Specified by:
submitForAuthorizationin interfaceAdService
-
toDTO
public BasicAdDTO toDTO(BasicAd entity)
Description copied from class:CRUDServiceImplConverts the given entity in a DTO, handling theCRUDServiceImpl.subClassMappings()mappings for subclasses- Specified by:
toDTOin interfaceCRUDServiceLocal<BasicAd,BasicAdDTO,AdDetailsData,AdDataParams>- Overrides:
toDTOin classCRUDServiceImpl<BasicAd,QBasicAd,BasicAdDTO,AdDetailsData,AdDataParams>
-
addCustomNameValidations
protected void addCustomNameValidations(Property name, BasicAdDTO namedDTO)
Description copied from class:CRUDServiceImplThis method may be overridden to add custom validations for the NAME property.- Overrides:
addCustomNameValidationsin classCRUDServiceImpl<BasicAd,QBasicAd,BasicAdDTO,AdDetailsData,AdDataParams>
-
doRemove
protected void doRemove(BasicAd ad, 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<BasicAd,QBasicAd,BasicAdDTO,AdDetailsData,AdDataParams>
-
getData
protected AdDetailsData getData(BasicAd ad)
Description copied from class:CRUDServiceImplReturns details data for the given entity- Specified by:
getDatain classCRUDServiceImpl<BasicAd,QBasicAd,BasicAdDTO,AdDetailsData,AdDataParams>
-
getNameLabel
protected String getNameLabel(BasicAdDTO dto)
- Overrides:
getNameLabelin classCRUDServiceImpl<BasicAd,QBasicAd,BasicAdDTO,AdDetailsData,AdDataParams>
-
getUniqueNameQuery
protected Pair<DBQuery<?>,String> getUniqueNameQuery(BasicAdDTO dto)
Description copied from class:CRUDServiceImplThis method may be overridden to customize the default global unique validation for the name property. Also it must return a string with the context to be included in the key used for the lock (LockKey#LockType)- Overrides:
getUniqueNameQueryin classCRUDServiceImpl<BasicAd,QBasicAd,BasicAdDTO,AdDetailsData,AdDataParams>
-
onAfterSave
protected void onAfterSave(BasicAd ad, BasicAd currentCopy, Object dataFromOnBeforeSave)
Description copied from class:CRUDServiceImplMay be overridden in order to perform custom logic after saving an entity- Overrides:
onAfterSavein classCRUDServiceImpl<BasicAd,QBasicAd,BasicAdDTO,AdDetailsData,AdDataParams>
-
onBeforeSave
protected Object onBeforeSave(BasicAd ad, BasicAd 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<BasicAd,QBasicAd,BasicAdDTO,AdDetailsData,AdDataParams>
-
preProcessCurrentCopy
protected void preProcessCurrentCopy(BasicAdDTO dto, BasicAd currentCopy)
Description copied from class:CRUDServiceImplThis method is invoked before saving the entity and also, if the log is enabled, before removing. Subclasses can override it to fetch lazy relationships, etc as the current copy will be detached. In case of removing (i.e the log is enabled for this entity) the dto parameter will be null.- Overrides:
preProcessCurrentCopyin classCRUDServiceImpl<BasicAd,QBasicAd,BasicAdDTO,AdDetailsData,AdDataParams>
-
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, BasicAd ad)
Description copied from class:CRUDServiceImplShould be overridden by subclasses which have extension points- Overrides:
resolveExtensionPointAccessorin classCRUDServiceImpl<BasicAd,QBasicAd,BasicAdDTO,AdDetailsData,AdDataParams>
-
resolveValidator
protected Validator resolveValidator(BasicAdDTO dto)
- Specified by:
resolveValidatorin classCRUDServiceImpl<BasicAd,QBasicAd,BasicAdDTO,AdDetailsData,AdDataParams>
-
subClassMappings
protected org.apache.commons.collections4.BidiMap<Class<? extends BasicAd>,Class<? extends BasicAdDTO>> 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<BasicAd,QBasicAd,BasicAdDTO,AdDetailsData,AdDataParams>
-
-