@Override protected TopicDto newEntity() { TopicDto topic = new TopicDto(); topic.setApplicationId(applicationId); return topic; }
/** * Instantiates new topic. */ public Topic(TopicDto dto) { if (dto != null) { this.id = getLongId(dto); this.name = dto.getName(); this.description = dto.getDescription(); this.createdUsername = dto.getCreatedUsername(); this.createdTime = dto.getCreatedTime(); this.sequenceNumber = dto.getSecNum(); this.type = dto.getType(); Long appId = getLongId(dto.getApplicationId()); this.application = appId != null ? new Application(appId) : null; } }
@Override public TopicDto toDto() { TopicDto dto = createDto(); dto.setId(getStringId()); if (application != null) { dto.setApplicationId(application.getStringId()); } dto.setName(name); dto.setType(type); dto.setDescription(description); dto.setCreatedUsername(createdUsername); dto.setCreatedTime(createdTime); dto.setSecNum(sequenceNumber); return dto; }
protected TopicDto generateTopicDto(String appId, TopicTypeDto type) { TopicDto topic = new TopicDto(); topic.setName(TOPIC_NAME); if (isBlank(appId)) { appId = generateApplicationDto().getId(); } topic.setApplicationId(appId); if (type == null) { type = TopicTypeDto.MANDATORY; } topic.setType(type); return topicService.saveTopic(topic); }
@Test public void removeTopicByIdAddedToGroupTest() { TopicDto topic = generateTopicDto(null, null); EndpointGroupDto groupDto = generateEndpointGroupDto(topic.getApplicationId()); endpointService.addTopicToEndpointGroup(groupDto.getId(), topic.getId()); topicService.removeTopicById(topic.getId()); TopicDto found = topicService.findTopicById(topic.getId()); Assert.assertNull(found); }
@Override public TopicDto saveTopic(TopicDto topicDto) { validateSqlObject(topicDto, "Can't save topic. Invalid topic object"); if (StringUtils.isBlank(topicDto.getId())) { LOG.debug("Save new topic."); topicDto.setCreatedTime(System.currentTimeMillis()); Topic topic = topicDao.findTopicByAppIdAndName(topicDto.getApplicationId(), topicDto.getName()); if (topic != null) { throw new IllegalArgumentException("Topic with the same name already present!"); } } return getDto(topicDao.save(new Topic(topicDto))); }
@Override public TopicDto editTopic(TopicDto topic) throws KaaAdminServiceException { checkAuthority(KaaAuthorityDto.TENANT_DEVELOPER, KaaAuthorityDto.TENANT_USER); try { if (isEmpty(topic.getId())) { topic.setCreatedUsername(getCurrentUser().getUsername()); checkApplicationId(topic.getApplicationId()); } else { throw new KaaAdminServiceException( "Unable to edit existing topic!", ServiceErrorCode.INVALID_ARGUMENTS); } return controlService.editTopic(topic); } catch (Exception ex) { throw Utils.handleException(ex); } }
@Override public List<UpdateNotificationDto<EndpointGroupDto>> removeTopicById(String id) { validateId(id, "Can't remove topic. Invalid topic id " + id); TopicDto topic = findTopicById(id); List<UpdateNotificationDto<EndpointGroupDto>> notificationList = new LinkedList<>(); if (topic != null) { List<EndpointGroup> groups = endpointGroupDao.findEndpointGroupsByTopicIdAndAppId( topic.getApplicationId(), id); if (groups != null && !groups.isEmpty()) { for (EndpointGroup eg : groups) { notificationList.add(endpointService.removeTopicFromEndpointGroup(eg.getId().toString(), id)); } } topicDao.removeById(id); notificationDao.removeNotificationsByTopicId(id); } return notificationList; }
@Override protected void onSave() { entity.setName(detailsView.getName().getValue()); entity.setType( detailsView.getMandatory().getValue() ? TopicTypeDto.MANDATORY : TopicTypeDto.OPTIONAL); entity.setDescription(detailsView.getDescription().getValue()); }
@Override protected void onEntityRetrieved() { detailsView.getName().setValue(entity.getName()); detailsView.getMandatory().setValue(entity.getType() == TopicTypeDto.MANDATORY); detailsView.getDescription().setValue(entity.getDescription()); detailsView.getCreatedUsername().setValue(entity.getCreatedUsername()); detailsView.getCreatedDateTime() .setValue(Utils.millisecondsToDateTimeString(entity.getCreatedTime())); }
/** * Get all topic data transfer objects. * * @param topicIds the ids of topics * @return <code>List</code> of topics */ public static List<TopicDto> getTopicDtos(List<String> topicIds) { List<TopicDto> topics = Collections.emptyList(); if (topicIds != null && !topicIds.isEmpty()) { topics = new ArrayList<>(topicIds.size()); for (String id : topicIds) { if (id != null) { TopicDto topicDto = new TopicDto(); topicDto.setId(id); topics.add(topicDto); } } } return topics; }
@Override protected TopicDto createDto() { return new TopicDto(); }
@Override public String getValue(TopicDto item) { return item.getCreatedUsername(); } }, 80);
@Override public String getValue(TopicDto item) { return Utils.millisecondsToDateString(item.getCreatedTime()); } }, 80);
NotificationSchemaDto savedSchema = notificationService.saveNotificationSchema(notificationSchemaDto); TopicDto topicDto = new TopicDto(); topicDto.setApplicationId(app.getId()); topicDto.setName("New Topic"); topicDto.setType(TopicTypeDto.MANDATORY); dto.setTopicId(topicDto.getId()); dto.setBody("{\"notificationBody\":\"dummy\", \"systemNotificationParam1\":42, \"systemNotificationParam2\":43}".getBytes()); dto.setExpiredAt(new Date(System.currentTimeMillis() + TimeUnit.SECONDS.toMillis(10L)));
@Test public void removeTopicByIdTest() { TopicDto topic = generateTopicDto(null, null); topicService.removeTopicById(topic.getId()); TopicDto found = topicService.findTopicById(topic.getId()); Assert.assertNull(found); List<EndpointGroupDto> groups = endpointService.findEndpointGroupsByAppId(topic.getApplicationId()); Assert.assertFalse(groups.isEmpty()); }
@Override public TopicDto getTopic(String topicId) throws KaaAdminServiceException { checkAuthority(KaaAuthorityDto.TENANT_DEVELOPER, KaaAuthorityDto.TENANT_USER); try { TopicDto topic = controlService.getTopic(topicId); Utils.checkNotNull(topic); checkApplicationId(topic.getApplicationId()); return topic; } catch (Exception ex) { throw Utils.handleException(ex); } }