@Override protected GenericModel<TenantDto> newInstance(Long id) { return new Tenant(id); }
@Override public TenantDto saveTenant(TenantDto tenantDto) { LOG.trace("Try to save tenant object: {}", tenantDto); TenantDto tenant = null; if (isValidSqlObject(tenantDto)) { Tenant checkTenant = tenantDao.findByName(tenantDto.getName()); if (checkTenant == null || checkTenant.getId().toString().equals(tenantDto.getId())) { tenant = getDto(tenantDao.save(new Tenant(tenantDto))); } else { throw new IncorrectParameterException("Can't save tenant with same name"); } } return tenant; }
@Override public TenantDto toDto() { TenantDto dto = createDto(); dto.setId(getStringId()); dto.setName(name); return dto; }
@Override @Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class) public CtlSchemaMetaInfo save(CtlSchemaMetaInfo object) { String tenantId = object.getTenant() != null ? object.getTenant().getStringId() : null; String applicationId = object.getApplication() != null ? object.getApplication().getStringId() : null; LOG.debug("Try to save or find meta info with fqn [{}], tenantId [{}] and applicationId [{}]", object.getFqn(), tenantId, applicationId); CtlSchemaMetaInfo uniqueMetaInfo = findByFqnTenantIdAndApplicationId( object.getFqn(), tenantId, applicationId); if (uniqueMetaInfo == null) { uniqueMetaInfo = super.save(object, true); LOG.debug("Save result: {}", uniqueMetaInfo); } else { LOG.debug("Search result: {}", uniqueMetaInfo); } return uniqueMetaInfo; }
@Test public void saveUserTest() { Tenant tenant = generateTenant(); User user = generateUser(tenant, null); user = userDao.save(user); List<User> users = userDao.findByTenantIdAndAuthority(tenant.getId().toString(), KaaAuthorityDto.KAA_ADMIN.name()); LOG.debug("---> List users {} ", Arrays.toString(users.toArray())); Assert.assertEquals(user, users.get(0)); }
@Override public int hashCode() { final int prime = 31; int result = 1; result = prime * result + ((applicationToken == null) ? 0 : applicationToken.hashCode()); result = prime * result + ((id == null) ? 0 : id.hashCode()); result = prime * result + ((name == null) ? 0 : name.hashCode()); result = prime * result + sequenceNumber; result = prime * result + ((tenant == null) ? 0 : tenant.hashCode()); return result; }
return false; } else if (!tenant.equals(other.tenant)) { return false;
@Override public CtlSchemaMetaInfoDto toDto() { CtlSchemaMetaInfoDto ctlSchemaMetaInfoDto = createDto(); ctlSchemaMetaInfoDto.setId(getStringId()); ctlSchemaMetaInfoDto.setFqn(fqn); ctlSchemaMetaInfoDto.setApplicationId(application != null ? application.getStringId() : null); ctlSchemaMetaInfoDto.setTenantId(tenant != null ? tenant.getStringId() : null); return ctlSchemaMetaInfoDto; }
@Test public void testFindByTenantId() { Tenant ten = generateTenant(); Application app = generateApplication(ten); List<Application> found = applicationDao.findByTenantId(ten.getId().toString()); Assert.assertEquals(app, found.get(0)); }
@Override public int hashCode() { final int prime = 31; int result = 1; result = prime * result + ((application == null) ? 0 : application.hashCode()); result = prime * result + ((fqn == null) ? 0 : fqn.hashCode()); result = prime * result + ((tenant == null) ? 0 : tenant.hashCode()); return result; }
return false; } else if (!tenant.equals(other.tenant)) { return false;
@Override public LogAppenderDto toDto() { LogAppenderDto dto = super.toDto(); dto.setId(getStringId()); if (application != null) { dto.setApplicationToken(application.getApplicationToken()); dto.setTenantId(application.getTenant().getStringId()); } dto.setMinLogSchemaVersion(minLogSchemaVersion); dto.setMaxLogSchemaVersion(maxLogSchemaVersion); dto.setConfirmDelivery(confirmDelivery); dto.setHeaderStructure(headerStructure != null ? new ArrayList<>(headerStructure) : new ArrayList<>()); return dto; }
/** * 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; }
@Test public void testFindByTenantIdAndFqn() { EventClassFamily classFamily = generateEventClassFamily(null, 1).get(0); Tenant tenant = classFamily.getTenant(); List<EventClass> events = generateEventClass(tenant, classFamily, 3); EventClass ec = events.get(0); List<EventClass> found = eventClassDao.findByTenantIdAndFqn(tenant.getId().toString(), ec.getFqn()); Assert.assertEquals(ec, found.get(0)); }
@Override public int hashCode() { final int prime = 45; int result = 1; result = prime * result + ((id == null) ? 0 : id.hashCode()); result = prime * result + ((username == null) ? 0 : username.hashCode()); result = prime * result + ((externalUid == null) ? 0 : externalUid.hashCode()); result = prime * result + ((tenant == null) ? 0 : tenant.hashCode()); result = prime * result + ((authority == null) ? 0 : authority.hashCode()); return result; }
return false; } else if (!tenant.equals(other.tenant)) { return false;
@Override public ApplicationDto toDto() { ApplicationDto dto = createDto(); dto.setId(getStringId()); dto.setApplicationToken(applicationToken); dto.setName(name); dto.setSequenceNumber(sequenceNumber); if (tenant != null) { dto.setTenantId(tenant.getStringId()); } dto.setCredentialsServiceName(credentialsServiceName); return dto; } }
/** * 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; }