public DependentMetadata removeScoringDefinition(String scoringId, boolean validate) { Set<Segment> impactedSegments = getScoringDependentSegments(scoringId); Set<Scoring> impactedScorings = getScoringDependentScorings(scoringId); if (!validate || (impactedSegments.isEmpty() && impactedScorings.isEmpty())) { // update profiles updateExistingProfilesForRemovedScoring(scoringId); // update impacted segments for (Segment segment : impactedSegments) { Condition updatedCondition = updateScoringDependentCondition(segment.getCondition(), scoringId); segment.setCondition(updatedCondition); if (updatedCondition == null) { clearAutoGeneratedRules( persistenceService.query( "linkedItems", segment.getMetadata().getId(), null, Rule.class), segment.getMetadata().getId()); segment.getMetadata().setEnabled(false); } setSegmentDefinition(segment); } // update impacted scorings for (Scoring scoring : impactedScorings) { List<ScoringElement> updatedScoringElements = new ArrayList<>(); for (ScoringElement scoringElement : scoring.getElements()) { Condition updatedCondition = updateScoringDependentCondition(scoringElement.getCondition(), scoringId); if (updatedCondition != null) { scoringElement.setCondition(updatedCondition); updatedScoringElements.add(scoringElement); } } scoring.setElements(updatedScoringElements); if (updatedScoringElements.isEmpty()) { clearAutoGeneratedRules( persistenceService.query( "linkedItems", scoring.getMetadata().getId(), null, Rule.class), scoring.getMetadata().getId()); scoring.getMetadata().setEnabled(false); } setScoringDefinition(scoring); } persistenceService.remove(scoringId, Scoring.class); List<Rule> previousRules = persistenceService.query("linkedItems", scoringId, null, Rule.class); clearAutoGeneratedRules(previousRules, scoringId); } List<Metadata> segments = new LinkedList<>(); List<Metadata> scorings = new LinkedList<>(); for (Segment definition : impactedSegments) { segments.add(definition.getMetadata()); } for (Scoring definition : impactedScorings) { scorings.add(definition.getMetadata()); } return new DependentMetadata(segments, scorings); }
public DependentMetadata removeSegmentDefinition(String segmentId, boolean validate) { Set<Segment> impactedSegments = getSegmentDependentSegments(segmentId); Set<Scoring> impactedScorings = getSegmentDependentScorings(segmentId); if (!validate || (impactedSegments.isEmpty() && impactedScorings.isEmpty())) { // update profiles Condition segmentCondition = new Condition(); segmentCondition.setConditionType( definitionsService.getConditionType("profilePropertyCondition")); segmentCondition.setParameter("propertyName", "segments"); segmentCondition.setParameter("comparisonOperator", "equals"); segmentCondition.setParameter("propertyValue", segmentId); List<Profile> previousProfiles = persistenceService.query(segmentCondition, null, Profile.class); for (Profile profileToRemove : previousProfiles) { profileToRemove.getSegments().remove(segmentId); persistenceService.update( profileToRemove.getItemId(), null, Profile.class, "segments", profileToRemove.getSegments()); } // update impacted segments for (Segment segment : impactedSegments) { Condition updatedCondition = updateSegmentDependentCondition(segment.getCondition(), segmentId); segment.setCondition(updatedCondition); if (updatedCondition == null) { clearAutoGeneratedRules( persistenceService.query( "linkedItems", segment.getMetadata().getId(), null, Rule.class), segment.getMetadata().getId()); segment.getMetadata().setEnabled(false); } setSegmentDefinition(segment); } // update impacted scorings for (Scoring scoring : impactedScorings) { List<ScoringElement> updatedScoringElements = new ArrayList<>(); for (ScoringElement scoringElement : scoring.getElements()) { Condition updatedCondition = updateSegmentDependentCondition(scoringElement.getCondition(), segmentId); if (updatedCondition != null) { scoringElement.setCondition(updatedCondition); updatedScoringElements.add(scoringElement); } } scoring.setElements(updatedScoringElements); if (updatedScoringElements.isEmpty()) { clearAutoGeneratedRules( persistenceService.query( "linkedItems", scoring.getMetadata().getId(), null, Rule.class), scoring.getMetadata().getId()); scoring.getMetadata().setEnabled(false); } setScoringDefinition(scoring); } persistenceService.remove(segmentId, Segment.class); List<Rule> previousRules = persistenceService.query("linkedItems", segmentId, null, Rule.class); clearAutoGeneratedRules(previousRules, segmentId); } List<Metadata> segments = new LinkedList<>(); List<Metadata> scorings = new LinkedList<>(); for (Segment definition : impactedSegments) { segments.add(definition.getMetadata()); } for (Scoring definition : impactedScorings) { scorings.add(definition.getMetadata()); } return new DependentMetadata(segments, scorings); }