@Override public TopicListEntryDto toDto() { List<TopicDto> topicDtos = ModelUtils.getTopicDtos(topicIds); return new TopicListEntryDto(simpleHash, hash, topicDtos); } }
private Criterion buildEqIdCriterion(String reference, String id) { Criterion criterion; if (isBlank(id)) { criterion = Restrictions.isNull(reference); } else { criterion = Restrictions.eq(reference, ModelUtils.getLongId(id)); } return criterion; } }
/** * Get string id. * * @param hasId the object that has id * @return id */ public static String getStringId(GenericModel<?> hasId) { String stringId = null; if (hasId != null) { Long id = hasId.getId(); stringId = getStringId(id); } return stringId; }
/** * Instantiates the Configuration. */ public Configuration(ConfigurationDto dto) { super(dto); if (dto != null) { Long schemaId = getLongId(dto.getSchemaId()); this.configurationSchema = schemaId != null ? new ConfigurationSchema(schemaId) : null; this.configurationBody = stringToBinary(dto.getBody()); this.schemaVersion = dto.getSchemaVersion(); } }
@Override public ConfigurationDto toDto() { ConfigurationDto dto = super.toDto(); dto.setBody(binaryToString(configurationBody)); dto.setSchemaId(ModelUtils.getStringId(configurationSchema.getId())); dto.setSchemaVersion(schemaVersion); dto.setProtocolSchema(configurationSchema != null ? configurationSchema.getProtocolSchema() : null); return dto; }
/** * Create instance of <code>EndpointGroup</code>. * * @param dto data transfer object */ public EndpointGroup(EndpointGroupDto dto) { if (dto != null) { this.id = getLongId(dto); this.name = dto.getName(); this.sequenceNumber = dto.getSequenceNumber(); this.weight = dto.getWeight(); this.description = dto.getDescription(); this.createdUsername = dto.getCreatedUsername(); this.createdTime = dto.getCreatedTime(); Long appId = getLongId(dto.getApplicationId()); this.application = appId != null ? new Application(appId) : null; this.topics = getTopic(dto.getTopics()); } }
@Override @Transactional public TopicListEntryDto findTopicListEntryByHash(byte[] hash) { LOG.debug("Looking for a topic list entry by hash: [{}]", hash); TopicListEntry topicListEntry = topicListEntryDao.findByHash(hash); List<TopicDto> foundTopics = ModelUtils.convertDtoList(topicDao.findTopicsByIds( topicListEntry.getTopicIds())); TopicListEntryDto topicListEntryDto = getDto(topicListEntry); topicListEntryDto.setTopics(foundTopics); return topicListEntryDto; }
@Override public EndpointGroupDto toDto() { EndpointGroupDto dto = createDto(); dto.setId(getStringId()); dto.setDescription(description); dto.setCreatedUsername(createdUsername); dto.setCreatedTime(createdTime); if (application != null) { dto.setApplicationId(application.getStringId()); } dto.setName(name); dto.setSequenceNumber(sequenceNumber); dto.setWeight(weight); dto.setTopics(getTopicIds(topics)); return dto; }
/** * Create new instance of tenant. * * @param dto data transfer object that used for creating new instance, * it hold id and name of new instance */ public Tenant(TenantDto dto) { if (dto != null) { this.id = getLongId(dto); this.name = dto.getName(); } }
@Override public TopicListEntryDto toDto() { List<TopicDto> topicDtos = ModelUtils.getTopicDtos(topicIds); return new TopicListEntryDto(simpleHash, getBytes(hash), topicDtos); } }
/** * Get topic ids. * * @param topics the topic set * @return ids <code>List</code> */ public static List<String> getTopicIds(Set<Topic> topics) { List<String> ids = Collections.emptyList(); if (topics != null && !topics.isEmpty()) { ids = new ArrayList<>(); for (Topic topic : topics) { String id = getStringId(topic.getId()); if (id != null) { ids.add(id); } } } return ids; }
/** * Update fields <code>tenant</code> and <code>application</code>, * create new instances by using ids in parameters. * @param tenantId is tenant id * @param applicationId is application id */ public void updateScope(String tenantId, String applicationId) { Long tenId = getLongId(tenantId); this.tenant = tenId != null ? new Tenant(tenId) : null; Long appId = getLongId(applicationId); this.application = appId != null ? new Application(appId) : null; }
@Override public ChangeDto toDto() { ChangeDto changeDto = createDto(); changeDto.setId(getStringId()); changeDto.setType(type); changeDto.setConfigurationId(ModelUtils.getStringId(configurationId)); changeDto.setCfVersion(configurationVersion); changeDto.setEndpointGroupId(ModelUtils.getStringId(groupId)); changeDto.setProfileFilterId(ModelUtils.getStringId(profileFilterId)); changeDto.setTopicId(ModelUtils.getStringId(topicId)); return changeDto; }
@Override public List<ServerProfileSchema> findByAppId(String appId) { List<ServerProfileSchema> schemas = Collections.emptyList(); LOG.debug("Searching server profile schemas by application id [{}] ", appId); if (isNotBlank(appId)) { schemas = findListByCriterion(Restrictions.eq(APPLICATION_REFERENCE, getLongId(appId))); } if (LOG.isTraceEnabled()) { LOG.trace("[{}] Search result: {}.", appId, Arrays.toString(schemas.toArray())); } else { LOG.debug("[{}] Search result: {}.", appId, schemas.size()); } return schemas; }
@Override public UserDto toDto() { UserDto dto = createDto(); dto.setId(getStringId()); dto.setUsername(username); dto.setExternalUid(externalUid); dto.setTenantId(ModelUtils.getStringId(tenant)); dto.setAuthority(authority); return dto; }
/** * Get Long id from object with id. * * @param hasId the object with id * @return id */ public static Long getLongId(HasId hasId) { Long longId = null; if (hasId != null) { String id = hasId.getId(); longId = getLongId(id); } return longId; }
protected abstract GenericModel<T> newInstance(Long id);
/** * Create new instance of CTL schema meta info. * @param fqn is full qualified name * @param tenantId is tenant id, it used for creating * <code>Tenant</code> with corresponding id and * set it on field <code>tenant</code> * @param applicationId is application id, it used for creating * <code>Application</code> with corresponding id and * set it on field <code>application</code> */ public CtlSchemaMetaInfo(String fqn, String tenantId, String applicationId) { this.fqn = fqn; Long tenId = getLongId(tenantId); this.tenant = tenId != null ? new Tenant(tenId) : null; Long appId = getLongId(applicationId); this.application = appId != null ? new Application(appId) : null; }
@Override public void removeByAppId(String appId) { if (isNotBlank(appId)) { List<ServerProfileSchema> schemaList = findListByCriterion(Restrictions.eq( APPLICATION_REFERENCE, getLongId(appId))); removeList(schemaList); } LOG.debug("Removed server profile schemas by application id [{}]", appId); } }
/** * Get topics by ids. * * @param topicIds the List of ids * @return set of topics */ public static Set<Topic> getTopic(List<String> topicIds) { Set<Topic> topics = Collections.emptySet(); if (topicIds != null && !topicIds.isEmpty()) { topics = new HashSet<>(); for (String id : topicIds) { Long lid = getLongId(id); if (lid != null) { topics.add(new Topic(lid)); } } } return topics; }