@Transient @Override public RestTransformationStepVO apply(TransformationStep t) { RestTransformationStepVO r = new RestTransformationStepVO(); r.setType(IntegrationType.REST); r.setMethod((String) t.getAttributes() .get(RestTransformationStep.REST_ATTRIBUTE_METHOD)); r.setUsername((String) t.getAttributes() .get(RestTransformationStep.REST_USERNAME_ATTRIBUTE_NAME)); r.setPassword((String) t.getAttributes() .get(RestTransformationStep.REST_PASSWORD_ATTRIBUTE_NAME)); r.setUrl((String) t.getAttributes() .get(RestTransformationStep.REST_URL_ATTRIBUTE_NAME)); r.setHeaders((Map) t.getAttributes() .get(RestTransformationStep.REST_ATTRIBUTE_HEADERS)); return r; }
/** * Get granted authorities as collection of * SimpleGrantedAuthorities(roleName) for each role: * * TODO should be used by permission manager * * @return JAVADOC. */ @SuppressWarnings("unchecked") @Transient public Collection<?extends GrantedAuthority> getAuthorities() { Collection<Permission> permissions = getPermissions(); if (permissions == null) { return DEFAULT_AUTHORITIES; } return CollectionUtils.collect(permissions, new Transformer() { @Override public Object transform(Object arg0) { Permission permission = (Permission) arg0; BeanWrapper beanWrapper = new BeanWrapperImpl(permission.getRole()); String name = (String) beanWrapper.getPropertyValue("name"); return new SimpleGrantedAuthority(name); } }); }
@Transient public boolean hasAssignedBot(){ return participants.stream() .filter(Participant::isBot) .findFirst() .isPresent(); }
@Transient public boolean hasAssignedAgent(){ return participants.stream() .filter(Participant::isAgent) .findFirst() .isPresent(); }
@Transient public String getUserName(){ return this.participants.stream() .filter(Participant::isUser) .map(Participant::getName) .findFirst() .orElse("NOT ASSIGNED"); }
@Transient public String getAgentName(){ return this.participants.stream() .filter(Participant::isAgent) .map(Participant::getName) .findFirst() .orElse("NOT ASSIGNED"); }
@Transient public void setUserPhoneNumber(String phoneNumber){ this.phoneNumber = phoneNumber; Optional<Participant> user = findParticipantByType(ParticipantType.USER); if(user.isPresent()){ user.get().setPhoneNumber(phoneNumber); } }
@Transient public boolean isAnonymous(){ return this.participants.stream() .filter(Participant::isUser) .filter( p -> Participant.ANNONYMUS_USER.equals(p.getName()) ) .findFirst() .isPresent(); }
@Transient public Participant assignBot(){ if(hasAssignedBot()){ return getBot().get(); } Participant bot = new Participant(); bot.setType(ParticipantType.BOT); bot.setName("Bot"); bot.setId(UUID.randomUUID().toString()); participants.add(bot); return bot; }
@Transient public Participant toParticipant(){ Participant participant = new Participant(); participant.setId(this.getId()); participant.setName(this.getFullName()); participant.setType(ParticipantType.AGENT); participant.setPhoneNumber(this.getPhone()); return participant; }
@Transient public boolean isUserMessage(){ Participant participant = getParticipant(); if(participant != null && participant.isUser()){ return true; } return false; }
@Transient public boolean isBotMessage(){ Participant participant = getParticipant(); if(participant != null && participant.isBot()){ return true; } return false; }
@Transient public boolean isAgentMessage(){ Participant participant = getParticipant(); if(participant != null && participant.isAgent()){ return true; } return false; }
@Transient public String getParticipantName(){ if(conversation != null) return conversation.findParticipantById(participantId).get().getName(); return ""; }
@Transient public Participant getParticipant(){ if(conversation != null) return conversation.getParticipants().stream() .filter( p -> p.getId().equals(participantId)) .findFirst() .orElse( null ); return null; }
@Transient public Optional<String> getParticipantPhoneNumber(){ Participant participant = getParticipant(); if(participant != null){ return Optional.ofNullable(participant.getPhoneNumber()); } return Optional.empty(); }
@Transient @Override public RestTransformationVO apply(Transformation t) { RestTransformationVO r = new RestTransformationVO(); r.setId(t.getId()); r.setGuid(t.getGuid()); r.setName(t.getName()); r.setDescription(t.getDescription()); r.setSteps(new RestTransformationStepVO().apply(t.getSteps())); return r; }
/** * Serialize list of objects from DB to VO * @param t * @return List<R> */ @Transient default List<R> apply(List<T> t) { return t.parallelStream() .map(i -> apply(i)) .collect(Collectors.toList()); }
@Override public boolean matches(Field field) { return super.matches(field) && field.getAnnotation(Transient.class) == null; }
@JsonIgnore @Transient public void addRole(Role role){ this.roles.add(role); }
@Transient public Optional<Participant> findParticipantById(String id){ return participants.stream() .filter( p -> p.getId().equals(id)) .findFirst(); }
@Transient public Optional<Participant> findParticipantByType(ParticipantType type){ return participants.stream() .filter( p -> p.getType() == type) .findFirst(); }
@Transient public Optional<Participant> findParticipantByPhone(String phoneNumber){ return participants.stream() .filter( p -> phoneNumber.equals(p.getPhoneNumber()) ) .findFirst(); }
@Transient public boolean hasPhoneNumberAssigned(){ return StringUtils.hasText(this.phoneNumber); }
@Transient public void incrementNumberInquires(){ this.numberRequests++; }
@Transient public void incrementNameInquires(){ this.nameRequests++; }
@Transient public Optional<Participant> getBot(){ return this.participants.stream() .filter(Participant::isBot) .findFirst(); }
@Transient public Optional<Participant> getUser(){ return this.participants.stream() .filter(Participant::isUser) .findFirst(); }
@Transient public String getFullName(){ return this.firstName + " " + this.getLastName(); }
@Transient public boolean isBot(){ return this.type == ParticipantType.BOT; }
@Transient public boolean isUser(){ return this.type == ParticipantType.USER; }
@Transient public boolean isAgent(){ return this.type == ParticipantType.AGENT; }
@Override @Transient public boolean isNew() { return null == getId(); }
@Transient public Node getLeft() { return this.children == null? null : this.children[0]; }
@Transient public Node getRight() { return this.children == null? null : this.children[1]; }
@JsonIgnore @Override @Transient public String getId() { return getName(); }
@Transient public boolean isActive() { DateTime now = DateTime.now(); return (getFrom() != null) && (getTo() != null) && getFrom().isBefore(now) && getTo().isAfter(now); }
/** * @return the original timestamp */ @Transient public long getTimeStamp() { return timeStamp; }
/** * @return the time-stamp when this event happened */ @Transient public long getTimeStamp() { return timeStamp; }
@Transient public long getTimeStamp() { return timeStamp; }