@Override public void setCampaignEvent(CampaignEvent event) { persistenceService.save(event); }
private Set<ActionType> getActionTypesBy(String fieldName, String fieldValue) { Set<ActionType> actionTypes = new LinkedHashSet<ActionType>(); List<ActionType> directActionTypes = persistenceService.query(fieldName, fieldValue,null, ActionType.class); actionTypes.addAll(directActionTypes); return actionTypes; }
public Persona savePersona(Persona profile) { if (persistenceService.load(profile.getItemId(), Persona.class) == null) { Session session = new PersonaSession(UUID.randomUUID().toString(), profile, new Date()); persistenceService.save(profile); persistenceService.save(session); } else { persistenceService.save(profile); } return persistenceService.load(profile.getItemId(), Persona.class); }
public PartialList<Session> getProfileSessions(String profileId, String query, int offset, int size, String sortBy) { if (StringUtils.isNotBlank(query)) { return persistenceService.queryFullText("profileId", profileId, query, sortBy, Session.class, offset, size); } else { return persistenceService.query("profileId", profileId, sortBy, Session.class, offset, size); } }
public PersonaWithSessions loadPersonaWithSessions(String personaId) { Persona persona = persistenceService.load(personaId, Persona.class); if (persona == null) { return null; } List<PersonaSession> sessions = persistenceService.query("profileId", persona.getItemId(), "timeStamp:desc", PersonaSession.class); return new PersonaWithSessions(persona, sessions); }
@Override public void delete(String listId) { Condition query = new Condition(definitionsService.getConditionType("profilePropertyCondition")); query.setParameter("propertyName", "systemProperties.lists"); query.setParameter("comparisonOperator", "equals"); query.setParameter("propertyValue", listId); List<Profile> profiles = persistenceService.query(query, null, Profile.class); Map<String, Object> profileProps; for (Profile p : profiles) { profileProps = p.getSystemProperties(); if(profileProps != null && profileProps.get("lists") != null) { int index = ((List) profileProps.get("lists")).indexOf(listId); if(index != -1){ ((List) profileProps.get("lists")).remove(index); persistenceService.update(p.getItemId(), null, Profile.class, "systemProperties", profileProps); } } } persistenceService.remove(listId, UserList.class); } }
@Override public PartialList<CampaignEvent> getEvents(Query query) { if(query.isForceRefresh()){ persistenceService.refresh(); } definitionsService.resolveConditionType(query.getCondition()); return persistenceService.query(query.getCondition(), query.getSortby(), CampaignEvent.class, query.getOffset(), query.getLimit()); }
@Override public SFDCConfiguration loadConfiguration() { if (persistenceService == null) { return null; } SFDCConfiguration sfdcConfiguration = persistenceService.load("sfdcConfiguration", SFDCConfiguration.class); return sfdcConfiguration; }
PartialList<Profile> profilesToRemove = persistenceService.query(profilesToRemoveCondition, null, Profile.class, 0, segmentUpdateBatchSize, "10m"); PartialList<Profile> profilesToAdd = persistenceService.query(profilesToAddCondition, null, Profile.class, 0, segmentUpdateBatchSize, "10m"); for (Profile profileToAdd : profilesToAdd.getList()) { profileToAdd.getSegments().add(segment.getItemId()); persistenceService.update(profileToAdd.getItemId(), null, Profile.class, "segments", profileToAdd.getSegments()); Event profileUpdated = new Event("profileUpdated", null, profileToAdd, null, null, profileToAdd, new Date()); profileUpdated.setPersistent(false); profilesToAdd = persistenceService.continueScrollQuery(Profile.class, profilesToAdd.getScrollIdentifier(), profilesToAdd.getScrollTimeValidity()); if (profilesToAdd == null || profilesToAdd.getList().size() == 0) { break; for (Profile profileToRemove : profilesToRemove.getList()) { profileToRemove.getSegments().remove(segment.getItemId()); persistenceService.update(profileToRemove.getItemId(), null, Profile.class, "segments", profileToRemove.getSegments()); Event profileUpdated = new Event("profileUpdated", null, profileToRemove, null, null, profileToRemove, new Date()); profileUpdated.setPersistent(false); profilesToRemove = persistenceService.continueScrollQuery(Profile.class, profilesToRemove.getScrollIdentifier(), profilesToRemove.getScrollTimeValidity()); if (profilesToRemove == null || profilesToRemove.getList().size() == 0) { break; PartialList<Profile> profilesToRemove = persistenceService.query(segmentCondition, null, Profile.class, 0, 200, "10m"); while (profilesToRemove.getList().size() > 0) { for (Profile profileToRemove : profilesToRemove.getList()) { profileToRemove.getSegments().remove(segment.getItemId()); persistenceService.update(profileToRemove.getItemId(), null, Profile.class, "segments", profileToRemove.getSegments()); updatedProfileCount++;
@Override public Boolean anonymizeBrowsingData(String profileId) { Profile profile = profileService.load(profileId); if (profile == null) { return false; } List<Session> sessions = profileService.getProfileSessions(profileId, null, 0, -1, null).getList(); if (sessions.isEmpty()) { return false; } for (Session session : sessions) { Profile newProfile = getAnonymousProfile(session.getProfile()); session.setProfile(newProfile); persistenceService.save(session); List<Event> events = eventService.searchEvents(session.getItemId(), new String[0], null, 0, -1, null).getList(); for (Event event : events) { persistenceService.update(event.getItemId(), event.getTimeStamp(), Event.class, "profileId", newProfile.getItemId()); } } return true; }
@Override public boolean execute() { try { for (Profile profile : profiles) { String profileId = profile.getItemId(); if (!StringUtils.equals(profileId, masterProfileId)) { List<Session> sessions = persistenceService.query("profileId", profileId, null, Session.class); if (masterProfileId.equals(profileId) && !sessions.contains(currentSession)) { sessions.add(currentSession); } for (Session session : sessions) { persistenceService.update(session.getItemId(), session.getTimeStamp(), Session.class, "profileId", anonymousBrowsing ? null : masterProfileId); } List<Event> events = persistenceService.query("profileId", profileId, null, Event.class); for (Event event : events) { persistenceService.update(event.getItemId(), event.getTimeStamp(), Event.class, "profileId", anonymousBrowsing ? null : masterProfileId); } // we must mark all the profiles that we merged into the master as merged with the master, and they will // be deleted upon next load profile.setMergedWith(masterProfileId); persistenceService.update(profile.getItemId(), null, Profile.class, "mergedWith", masterProfileId); } } } catch (Exception e) { logger.error("unable to execute callback action, profile and session will not be saved", e); return false; } return true; } });
public Set<Metadata> getGoalMetadatas() { Set<Metadata> descriptions = new HashSet<Metadata>(); for (Goal definition : persistenceService.getAllItems(Goal.class, 0, 50, null).getList()) { descriptions.add(definition.getMetadata()); } return descriptions; }
private void clearAutoGeneratedRules(List<Rule> rules, String idWithScope) { for (Rule previousRule : rules) { previousRule.getLinkedItems().remove(idWithScope); if (previousRule.getLinkedItems().isEmpty()) { // todo remove profile properties ? persistenceService.remove(previousRule.getItemId(), Rule.class); } else { persistenceService.update(previousRule.getItemId(), null, Rule.class, "linkedItems", previousRule.getLinkedItems()); } } }
Map<String, Double> m = persistenceService.getSingleValuesMetrics(andCondition, new String[]{"card"}, "profileId.keyword", Event.ITEM_TYPE); long card = m.get("_card").longValue(); Map<String, Long> eventCountByProfile = persistenceService.aggregateWithOptimizedQuery(andCondition, new TermsAggregate("profileId", i, numParts), Event.ITEM_TYPE); for (Map.Entry<String, Long> entry : eventCountByProfile.entrySet()) { String profileId = entry.getKey(); systemProperties.put("pastEvents", pastEventCounts); try { persistenceService.update(profileId, null, Profile.class, "systemProperties", systemProperties); } catch (Exception e) { logger.error("Error updating profile {} past event system properties", profileId, e);
public void removeActionType(String id) { persistenceService.remove(id, ActionType.class); actionTypeById.remove(id); }
Map<String, Long> eventCountByProfile = persistenceService.aggregateWithOptimizedQuery(andCondition, new TermsAggregate("profileId"), Event.ITEM_TYPE); for (Map.Entry<String, Long> entry : eventCountByProfile.entrySet()) { String profileId = entry.getKey(); systemProperties.put("pastEvents", pastEventCounts); try { persistenceService.update(profileId, null, Profile.class, "systemProperties", systemProperties); } catch (Exception e) { logger.error("Error updating profile {} past event system properties", profileId, e);
Map<String, Double> m = persistenceService.getSingleValuesMetrics(eventCondition, new String[]{"card"}, "profileId.keyword", Event.ITEM_TYPE); long card = m.get("_card").longValue(); int numParts = (int) (card / aggregateQueryBucketSize) + 2; for (int i = 0; i < numParts; i++) { Map<String, Long> eventCountByProfile = persistenceService.aggregateWithOptimizedQuery(eventCondition, new TermsAggregate("profileId", i, numParts), Event.ITEM_TYPE); int j = 0; if (eventCountByProfile != null) {
all = persistenceService.aggregateWithOptimizedQuery(condition, aggregate, Session.ITEM_TYPE); match = persistenceService.aggregateWithOptimizedQuery(condition, aggregate, Session.ITEM_TYPE); } else { list.add(goalStartCondition); all = new HashMap<String, Long>(); all.put("_filtered", persistenceService.queryCount(condition, Session.ITEM_TYPE)); match.put("_filtered", persistenceService.queryCount(condition, Session.ITEM_TYPE));
public Set<String> getEventTypeIds() { Map<String, Long> dynamicEventTypeIds = persistenceService.aggregateWithOptimizedQuery(null, new TermsAggregate("eventType"), Event.ITEM_TYPE); Set<String> eventTypeIds = new LinkedHashSet<String>(predefinedEventTypeIds); eventTypeIds.addAll(dynamicEventTypeIds.keySet()); return eventTypeIds; }
public void delete(String profileId, boolean persona) { if (persona) { persistenceService.remove(profileId, Persona.class); } else { Condition mergeCondition = new Condition(definitionsService.getConditionType("profilePropertyCondition")); mergeCondition.setParameter("propertyName", "mergedWith"); mergeCondition.setParameter("comparisonOperator", "equals"); mergeCondition.setParameter("propertyValue", profileId); persistenceService.removeByQuery(mergeCondition, Profile.class); persistenceService.remove(profileId, Profile.class); } }