Class SegmentServiceImpl
- java.lang.Object
-
- org.apache.unomi.services.impl.AbstractServiceImpl
-
- org.apache.unomi.services.impl.segments.SegmentServiceImpl
-
- All Implemented Interfaces:
EventListener,SegmentService,org.osgi.framework.BundleListener,org.osgi.framework.SynchronousBundleListener
public class SegmentServiceImpl extends AbstractServiceImpl implements SegmentService, org.osgi.framework.SynchronousBundleListener
-
-
Field Summary
-
Fields inherited from class org.apache.unomi.services.impl.AbstractServiceImpl
definitionsService, persistenceService
-
-
Constructor Summary
Constructors Constructor Description SegmentServiceImpl()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidbundleChanged(org.osgi.framework.BundleEvent event)voidcreateScoringDefinition(String scope, String scoringId, String name, String description)Creates a scoring with the specified scope, identifier, name and description.StringgetGeneratedPropertyKey(Condition condition, Condition parentCondition)Get generated property key for past event conditionPartialList<Profile>getMatchingIndividuals(String segmentID, int offset, int size, String sortBy)Retrieves a list of profiles matching the conditions defined by the segment identified by the specified identifier, ordered according to the specifiedsortByString and and paged: onlysizeof them are retrieved, starting with theoffset-th one.longgetMatchingIndividualsCount(String segmentID)Retrieves the number of profiles matching the conditions defined by the segment identified by the specified identifier.ScoringgetScoringDefinition(String scoringId)Retrieves the scoring identified by the specified identifier.DependentMetadatagetScoringDependentMetadata(String scoringId)Retrieves the list of Segment and Scoring metadata depending on the specified scoring.PartialList<Metadata>getScoringMetadatas(int offset, int size, String sortBy)Retrieves the set of all scoring metadata.PartialList<Metadata>getScoringMetadatas(Query query)Retrieves the set of scoring metadata for scorings matching the specified query.SegmentgetSegmentDefinition(String segmentId)Retrieves the segment identified by the specified identifier.DependentMetadatagetSegmentDependentMetadata(String segmentId)Retrieves the list of Segment and Scoring metadata depending on the specified segment.PartialList<Metadata>getSegmentMetadatas(int offset, int size, String sortBy)Retrieves segment metadatas, ordered according to the specifiedsortByString and and paged: onlysizeof them are retrieved, starting with theoffset-th one.PartialList<Metadata>getSegmentMetadatas(String scope, int offset, int size, String sortBy)Retrieves segment metadatas for segments in the specified scope, ordered according to the specifiedsortByString and and paged: onlysizeof them are retrieved, starting with theoffset-th one.PartialList<Metadata>getSegmentMetadatas(Query query)Retrieves the metadata for segments matching the specifiedQuery.List<Metadata>getSegmentMetadatasForProfile(Profile profile)Retrieves the list of segment metadata for the segments the specified profile is a member of.SegmentsAndScoresgetSegmentsAndScoresForProfile(Profile profile)Retrieves the segments and scores for the specified profile.BooleanisProfileInSegment(Profile profile, String segmentId)Determines whether the specified profile is part of the segment identified by the specified identifier.voidpostConstruct()voidpreDestroy()voidrecalculatePastEventConditions()This will recalculate the past event conditions from existing rules It will also recalculate date relative Segments and Scorings (when they contains date expression conditions for example) This operation can be heavy and take time, it will: - browse existing rules to extract the past event condition, - query the matching events for those conditions, - update the corresponding profiles - reevaluate segments/scorings linked to this rules to engaged/disengaged profiles after the occurrences have been updated - reevaluate segments/scoring that contains date expressions So use it carefully or execute this method in a dedicated thread.DependentMetadataremoveScoringDefinition(String scoringId, boolean validate)Removes the scoring definition identified by the specified identifier.DependentMetadataremoveSegmentDefinition(String segmentId, boolean validate)Removes the segment definition identified by the specified identifier.voidsetAggregateQueryBucketSize(int aggregateQueryBucketSize)voidsetBatchSegmentProfileUpdate(boolean batchSegmentProfileUpdate)voidsetBundleContext(org.osgi.framework.BundleContext bundleContext)voidsetDailyDateExprEvaluationHourUtc(int dailyDateExprEvaluationHourUtc)voidsetEventService(EventService eventService)voidsetMaximumIdsQueryCount(int maximumIdsQueryCount)voidsetMaxRetriesForUpdateProfileSegment(int maxRetriesForUpdateProfileSegment)voidsetPastEventsDisablePartitions(boolean pastEventsDisablePartitions)voidsetRulesService(RulesService rulesService)voidsetSchedulerService(SchedulerService schedulerService)voidsetScoringDefinition(Scoring scoring)Persists the specified scoring in the context server.voidsetSecondsDelayForRetryUpdateProfileSegment(long secondsDelayForRetryUpdateProfileSegment)voidsetSegmentDefinition(Segment segment)Persists the specified segment in the context server.voidsetSegmentRefreshInterval(long segmentRefreshInterval)voidsetSegmentUpdateBatchSize(int segmentUpdateBatchSize)voidsetSendProfileUpdateEventForSegmentUpdate(boolean sendProfileUpdateEventForSegmentUpdate)voidsetTaskExecutionPeriod(long taskExecutionPeriod)voidupdateAutoGeneratedRules(Metadata metadata, Condition condition)-
Methods inherited from class org.apache.unomi.services.impl.AbstractServiceImpl
getMetadatas, getMetadatas, setDefinitionsService, setPersistenceService
-
-
-
-
Method Detail
-
setBundleContext
public void setBundleContext(org.osgi.framework.BundleContext bundleContext)
-
setEventService
public void setEventService(EventService eventService)
-
setRulesService
public void setRulesService(RulesService rulesService)
-
setSchedulerService
public void setSchedulerService(SchedulerService schedulerService)
-
setSegmentUpdateBatchSize
public void setSegmentUpdateBatchSize(int segmentUpdateBatchSize)
-
setAggregateQueryBucketSize
public void setAggregateQueryBucketSize(int aggregateQueryBucketSize)
-
setMaximumIdsQueryCount
public void setMaximumIdsQueryCount(int maximumIdsQueryCount)
-
setPastEventsDisablePartitions
public void setPastEventsDisablePartitions(boolean pastEventsDisablePartitions)
-
setSegmentRefreshInterval
public void setSegmentRefreshInterval(long segmentRefreshInterval)
-
setMaxRetriesForUpdateProfileSegment
public void setMaxRetriesForUpdateProfileSegment(int maxRetriesForUpdateProfileSegment)
-
setSecondsDelayForRetryUpdateProfileSegment
public void setSecondsDelayForRetryUpdateProfileSegment(long secondsDelayForRetryUpdateProfileSegment)
-
setBatchSegmentProfileUpdate
public void setBatchSegmentProfileUpdate(boolean batchSegmentProfileUpdate)
-
setSendProfileUpdateEventForSegmentUpdate
public void setSendProfileUpdateEventForSegmentUpdate(boolean sendProfileUpdateEventForSegmentUpdate)
-
setDailyDateExprEvaluationHourUtc
public void setDailyDateExprEvaluationHourUtc(int dailyDateExprEvaluationHourUtc)
-
postConstruct
public void postConstruct() throws IOException- Throws:
IOException
-
preDestroy
public void preDestroy()
-
getSegmentMetadatas
public PartialList<Metadata> getSegmentMetadatas(int offset, int size, String sortBy)
Description copied from interface:SegmentServiceRetrieves segment metadatas, ordered according to the specifiedsortByString and and paged: onlysizeof them are retrieved, starting with theoffset-th one.- Specified by:
getSegmentMetadatasin interfaceSegmentService- Parameters:
offset- zero or a positive integer specifying the position of the first element in the total ordered collection of matching elementssize- a positive integer specifying how many matching elements should be retrieved or-1if all of them should be retrievedsortBy- an optional (nullif no sorting is required) String of comma (,) separated property names on which ordering should be performed, ordering elements according to the property order in the String, considering each in turn and moving on to the next one in case of equality of all preceding ones. Each property name is optionally followed by a column (:) and an order specifier:ascordesc.- Returns:
- a
PartialListof segment metadata
-
getSegmentMetadatas
public PartialList<Metadata> getSegmentMetadatas(String scope, int offset, int size, String sortBy)
Description copied from interface:SegmentServiceRetrieves segment metadatas for segments in the specified scope, ordered according to the specifiedsortByString and and paged: onlysizeof them are retrieved, starting with theoffset-th one. TODO: remove?- Specified by:
getSegmentMetadatasin interfaceSegmentService- Parameters:
scope- the scope for which we want to retrieve segment metadataoffset- zero or a positive integer specifying the position of the first element in the total ordered collection of matching elementssize- a positive integer specifying how many matching elements should be retrieved or-1if all of them should be retrievedsortBy- an optional (nullif no sorting is required) String of comma (,) separated property names on which ordering should be performed, ordering elements according to the property order in the String, considering each in turn and moving on to the next one in case of equality of all preceding ones. Each property name is optionally followed by a column (:) and an order specifier:ascordesc.- Returns:
- a
PartialListof segment metadata
-
getSegmentMetadatas
public PartialList<Metadata> getSegmentMetadatas(Query query)
Description copied from interface:SegmentServiceRetrieves the metadata for segments matching the specifiedQuery.- Specified by:
getSegmentMetadatasin interfaceSegmentService- Parameters:
query- the query that the segments must match for their metadata to be retrieved- Returns:
- a
PartialListof segment metadata
-
getSegmentDefinition
public Segment getSegmentDefinition(String segmentId)
Description copied from interface:SegmentServiceRetrieves the segment identified by the specified identifier.- Specified by:
getSegmentDefinitionin interfaceSegmentService- Parameters:
segmentId- the identifier of the segment to be retrieved- Returns:
- the segment identified by the specified identifier or
nullif no such segment exists
-
setSegmentDefinition
public void setSegmentDefinition(Segment segment)
Description copied from interface:SegmentServicePersists the specified segment in the context server.- Specified by:
setSegmentDefinitionin interfaceSegmentService- Parameters:
segment- the segment to be persisted
-
getSegmentDependentMetadata
public DependentMetadata getSegmentDependentMetadata(String segmentId)
Description copied from interface:SegmentServiceRetrieves the list of Segment and Scoring metadata depending on the specified segment. A segment or scoring is depending on a segment if it includes a profileSegmentCondition with a test on this segment.- Specified by:
getSegmentDependentMetadatain interfaceSegmentService- Parameters:
segmentId- the segment identifier- Returns:
- a list of Segment/Scoring Metadata depending on the specified segment
-
removeSegmentDefinition
public DependentMetadata removeSegmentDefinition(String segmentId, boolean validate)
Description copied from interface:SegmentServiceRemoves the segment definition identified by the specified identifier. We can specify that we want the operation to be validated beforehand so that we can know if any other segment that might use the segment we're trying to delete as a condition might be impacted. Ifvalidateis set tofalse, no validation is performed. If set totrue, we will first check if any segment or scoring depends on the segment we're trying to delete and if so we will not delete the segment but rather return the list of the metadata of the impacted items. If no dependents are found, then we properly delete the segment.- Specified by:
removeSegmentDefinitionin interfaceSegmentService- Parameters:
segmentId- the identifier of the segment we want to deletevalidate- whether or not to perform validation- Returns:
- a list of impacted segment metadata if any or an empty list if none were found or validation was skipped
-
getMatchingIndividuals
public PartialList<Profile> getMatchingIndividuals(String segmentID, int offset, int size, String sortBy)
Description copied from interface:SegmentServiceRetrieves a list of profiles matching the conditions defined by the segment identified by the specified identifier, ordered according to the specifiedsortByString and and paged: onlysizeof them are retrieved, starting with theoffset-th one.- Specified by:
getMatchingIndividualsin interfaceSegmentService- Parameters:
segmentID- the identifier of the segment for which we want to retrieve matching profilesoffset- zero or a positive integer specifying the position of the first element in the total ordered collection of matching elementssize- a positive integer specifying how many matching elements should be retrieved or-1if all of them should be retrievedsortBy- an optional (nullif no sorting is required) String of comma (,) separated property names on which ordering should be performed, ordering elements according to the property order in the String, considering each in turn and moving on to the next one in case of equality of all preceding ones. Each property name is optionally followed by a column (:) and an order specifier:ascordesc.- Returns:
- a
PartialListof profiles matching the specified segment
-
getMatchingIndividualsCount
public long getMatchingIndividualsCount(String segmentID)
Description copied from interface:SegmentServiceRetrieves the number of profiles matching the conditions defined by the segment identified by the specified identifier.- Specified by:
getMatchingIndividualsCountin interfaceSegmentService- Parameters:
segmentID- the identifier of the segment for which we want to retrieve matching profiles- Returns:
- the number of profiles matching the conditions defined by the segment identified by the specified identifier
-
isProfileInSegment
public Boolean isProfileInSegment(Profile profile, String segmentId)
Description copied from interface:SegmentServiceDetermines whether the specified profile is part of the segment identified by the specified identifier.- Specified by:
isProfileInSegmentin interfaceSegmentService- Parameters:
profile- the profile we want to checksegmentId- the identifier of the segment against which we want to check the profile- Returns:
trueif the specified profile is in the specified segment,falseotherwise
-
getSegmentsAndScoresForProfile
public SegmentsAndScores getSegmentsAndScoresForProfile(Profile profile)
Description copied from interface:SegmentServiceRetrieves the segments and scores for the specified profile.- Specified by:
getSegmentsAndScoresForProfilein interfaceSegmentService- Parameters:
profile- the profile for which we want to retrieve segments and scores- Returns:
- a
SegmentsAndScoresinstance encapsulating the segments and scores for the specified profile
-
getSegmentMetadatasForProfile
public List<Metadata> getSegmentMetadatasForProfile(Profile profile)
Description copied from interface:SegmentServiceRetrieves the list of segment metadata for the segments the specified profile is a member of.- Specified by:
getSegmentMetadatasForProfilein interfaceSegmentService- Parameters:
profile- the profile for which we want to retrieve the segment metadata- Returns:
- the (possibly empty) list of segment metadata for the segments the specified profile is a member of
-
getScoringMetadatas
public PartialList<Metadata> getScoringMetadatas(int offset, int size, String sortBy)
Description copied from interface:SegmentServiceRetrieves the set of all scoring metadata.- Specified by:
getScoringMetadatasin interfaceSegmentService- Parameters:
offset- the offsetsize- the sizesortBy- sort by- Returns:
- the set of all scoring metadata
-
getScoringMetadatas
public PartialList<Metadata> getScoringMetadatas(Query query)
Description copied from interface:SegmentServiceRetrieves the set of scoring metadata for scorings matching the specified query.- Specified by:
getScoringMetadatasin interfaceSegmentService- Parameters:
query- the query the scorings must match for their metadata to be retrieved- Returns:
- the set of scoring metadata for scorings matching the specified query
-
getScoringDefinition
public Scoring getScoringDefinition(String scoringId)
Description copied from interface:SegmentServiceRetrieves the scoring identified by the specified identifier.- Specified by:
getScoringDefinitionin interfaceSegmentService- Parameters:
scoringId- the identifier of the scoring to be retrieved- Returns:
- the scoring identified by the specified identifier or
nullif no such scoring exists
-
setScoringDefinition
public void setScoringDefinition(Scoring scoring)
Description copied from interface:SegmentServicePersists the specified scoring in the context server.- Specified by:
setScoringDefinitionin interfaceSegmentService- Parameters:
scoring- the scoring to be persisted
-
createScoringDefinition
public void createScoringDefinition(String scope, String scoringId, String name, String description)
Description copied from interface:SegmentServiceCreates a scoring with the specified scope, identifier, name and description.- Specified by:
createScoringDefinitionin interfaceSegmentService- Parameters:
scope- the scope for the new scoringscoringId- the identifier for the new scoringname- the name of the new scoringdescription- the description of the new scoring- See Also:
Item's description for a discussion of scope
-
getScoringDependentMetadata
public DependentMetadata getScoringDependentMetadata(String scoringId)
Description copied from interface:SegmentServiceRetrieves the list of Segment and Scoring metadata depending on the specified scoring. A segment or scoring is depending on a segment if it includes a scoringCondition with a test on this scoring.- Specified by:
getScoringDependentMetadatain interfaceSegmentService- Parameters:
scoringId- the segment identifier- Returns:
- a list of Segment/Scoring Metadata depending on the specified scoring
-
removeScoringDefinition
public DependentMetadata removeScoringDefinition(String scoringId, boolean validate)
Description copied from interface:SegmentServiceRemoves the scoring definition identified by the specified identifier. We can specify that we want the operation to be validated beforehand so that we can know if any other segment that might use the segment we're trying to delete as a condition might be impacted. Ifvalidateis set tofalse, no validation is performed. If set totrue, we will first check if any segment or scoring depends on the scoring we're trying to delete and if so we will not delete the scoring but rather return the list of the metadata of the impacted items. If no dependents are found, then we properly delete the scoring.- Specified by:
removeScoringDefinitionin interfaceSegmentService- Parameters:
scoringId- the identifier of the scoring we want to deletevalidate- whether or not to perform validation- Returns:
- a list of impacted items metadata if any or an empty list if none were found or validation was skipped
-
updateAutoGeneratedRules
public void updateAutoGeneratedRules(Metadata metadata, Condition condition)
-
getGeneratedPropertyKey
public String getGeneratedPropertyKey(Condition condition, Condition parentCondition)
Description copied from interface:SegmentServiceGet generated property key for past event condition- Specified by:
getGeneratedPropertyKeyin interfaceSegmentService- Parameters:
condition- The event conditionparentCondition- The past event condition- Returns:
- a String representing the condition and parent condition uniquelly
-
recalculatePastEventConditions
public void recalculatePastEventConditions()
Description copied from interface:SegmentServiceThis will recalculate the past event conditions from existing rules It will also recalculate date relative Segments and Scorings (when they contains date expression conditions for example) This operation can be heavy and take time, it will: - browse existing rules to extract the past event condition, - query the matching events for those conditions, - update the corresponding profiles - reevaluate segments/scorings linked to this rules to engaged/disengaged profiles after the occurrences have been updated - reevaluate segments/scoring that contains date expressions So use it carefully or execute this method in a dedicated thread.- Specified by:
recalculatePastEventConditionsin interfaceSegmentService
-
bundleChanged
public void bundleChanged(org.osgi.framework.BundleEvent event)
- Specified by:
bundleChangedin interfaceorg.osgi.framework.BundleListener
-
setTaskExecutionPeriod
public void setTaskExecutionPeriod(long taskExecutionPeriod)
-
-