protected Application generateApplication(Tenant tenant) { LOG.debug("Generate application..."); if (tenant == null) { tenant = generateTenant(); } Application app = new Application(); app.setName("Test app name" + UUID.randomUUID().toString()); app.setTenant(tenant); app.setApplicationToken(UUID.randomUUID().toString()); app.setSequenceNumber(RANDOM.nextInt()); app = applicationDao.save(app); LOG.debug("Generated application {}", app); return app; }
/** * Get id of application. * * @return id, return null if application hasn't id */ public String getApplicationId() { Long id = null; if (application != null) { id = application.getId(); } return id != null ? String.valueOf(id) : null; }
@Override public Application getNextSeqNumber(String id) { Application app = findById(id); if (app != null) { app.incrementSequenceNumber(); save(app); LOG.debug("Incremented application sequence number to {}", app.getSequenceNumber()); } return app; }
@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; } }
public String getApplicationId() { return application != null ? application.getStringId() : null; }
@Override protected GenericModel<ApplicationDto> newInstance(Long id) { return new Application(id); }
@Test public void findByAppIdAndSchemaVersion() { Application app = generateApplication(null); EndpointProfileSchema schema = generateProfSchema(app, 1).get(0); ServerProfileSchemaDto srvSchema = generateServerProfileSchema(app.getStringId(), app.getTenant().getStringId(), 101); generateFilter(schema, new ServerProfileSchema(srvSchema), null, 2, UpdateStatus.ACTIVE); List<ProfileFilter> filters = generateFilterWithoutSchemaGeneration(schema, new ServerProfileSchema(srvSchema), null, 1, UpdateStatus.ACTIVE); filters.addAll(generateFilterWithoutSchemaGeneration(null, new ServerProfileSchema(srvSchema), null, 1, UpdateStatus.ACTIVE)); filters.addAll(generateFilterWithoutSchemaGeneration(schema, null, null, 1, UpdateStatus.ACTIVE)); List<ProfileFilter> found = profileFilterDao.findByAppIdAndSchemaVersionsCombination(app.getStringId(), schema.getVersion(), srvSchema.getVersion()); Assert.assertEquals(filters, found); }
@Test public void testGetNextSeqNumber() { Tenant ten = generateTenant(); Application app = generateApplication(ten); int sequenceNumber = app.getSequenceNumber(); app = applicationDao.getNextSeqNumber(app.getId().toString()); Assert.assertNotEquals(sequenceNumber, app.getSequenceNumber()); }
@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; }
if (checkApplication != null && !Objects.equals(checkApplication.getStringId(), applicationDto.getId())) { throw new IncorrectParameterException( return getDto(applicationDao.save(new Application(applicationDto))); applicationDto.setApplicationToken(appToken); Application application = new Application(applicationDto); appDto = getDto(applicationDao.save(application));
@Override public SdkProfileDto toDto() { SdkProfileDto dto = this.createDto(); dto.setId(this.getStringId()); dto.setToken(this.token); if (this.application != null) { dto.setApplicationId(this.application.getStringId()); dto.setApplicationToken(this.application.getApplicationToken()); } dto.setName(this.name); dto.setConfigurationSchemaVersion(this.configurationSchemaVersion); dto.setProfileSchemaVersion(this.profileSchemaVersion); dto.setNotificationSchemaVersion(this.notificationSchemaVersion); dto.setLogSchemaVersion(this.logSchemaVersion); if (this.aefMapIds != null) { dto.setAefMapIds(new ArrayList<String>(this.aefMapIds.size())); for (String id : this.aefMapIds) { dto.getAefMapIds().add(id); } } dto.setDefaultVerifierToken(this.defaultVerifierToken); dto.setCreatedUsername(this.createdUsername); dto.setCreatedTime(this.createdTime); dto.setEndpointCount(this.endpointCount); return dto; }
protected List<ConfigurationSchema> generateConfSchema(Application app, int count) { List<ConfigurationSchema> schemas = Collections.emptyList(); try { if (app == null) { app = generateApplication(null); } CtlSchema ctlSchema = generateCTLSchema(DEFAULT_FQN, 1, app.getTenant(), null); ConfigurationSchema schema; schemas = new ArrayList<>(count); for (int i = 0; i < count; i++) { schema = new ConfigurationSchema(); schema.setApplication(app); schema.setCreatedUsername("Test User"); schema.setCtlSchema(ctlSchema); schema.setVersion(i + 1); schema.setName("Test Name"); schema = configurationSchemaDao.save(schema); Assert.assertNotNull(schema); schemas.add(schema); } } catch (Exception ex) { LOG.error("Can't generate configuration schemas {}", ex); Assert.fail("Can't generate configuration schemas." + ex.getMessage()); } return schemas; }
@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 (!application.equals(other.application)) { return false;
@Test public void testFindByApplicationToken() { Tenant ten = generateTenant(); Application app = generateApplication(ten); String token = app.getApplicationToken(); Application found = applicationDao.findByApplicationToken(token); Assert.assertEquals(app, found); }
@Override public HistoryDto saveHistory(HistoryDto historyDto) { HistoryDto savedDto = null; if (isValidSqlObject(historyDto)) { LOG.debug("History dto object is valid. Saving history..."); String applicationId = historyDto.getApplicationId(); if (isValidSqlId(applicationId)) { Application application = applicationDao.getNextSeqNumber(applicationId); if (application != null) { int sequenceNumber = application.getSequenceNumber(); historyDto.setSequenceNumber(sequenceNumber); historyDto.setLastModifyTime(System.currentTimeMillis()); History savedHistory = historyDao.persist(new History(historyDto)); savedDto = savedHistory != null ? savedHistory.toDto() : null; } else { LOG.debug("Can't get sequence number for application id [{}] .", applicationId); } } else { LOG.debug("Incorrect application id, can't save history."); } } else { LOG.info("Invalid HistoryDto object. Can't save object."); } return savedDto; }
@Test public void testFindByNameAndTenantId() { Tenant ten = generateTenant(); Application app = generateApplication(ten); String name = app.getName(); Application found = applicationDao.findByNameAndTenantId(name, ten.getId().toString()); Assert.assertEquals(app, found); }
public String getApplicationId() { return application != null ? application.getStringId() : null; }
/** * 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; }
protected List<ProfileFilter> generateFilter(Application app, EndpointProfileSchema schema, ServerProfileSchema srvSchema, EndpointGroup group, int count, UpdateStatus status) { if (schema == null) { schema = generateProfSchema(app, 1).get(0); } if (srvSchema == null) { srvSchema = new ServerProfileSchema(generateServerProfileSchema(app.getStringId(), app.getTenant().getStringId())); } if (group == null) { group = generateEndpointGroup(app, null); } List<ProfileFilter> filters = new ArrayList<>(); for (int i = 0; i < count; i++) { ProfileFilter dto = new ProfileFilter(); dto.setId(null); dto.setStatus(status != null ? status : UpdateStatus.INACTIVE); dto.setEndpointGroup(group); dto.setEndpointProfileSchema(schema); dto.setServerProfileSchema(srvSchema); dto.setSequenceNumber(i); dto.setApplication(app); ProfileFilter saved = profileFilterDao.save(dto); Assert.assertNotNull(saved); filters.add(saved); } return filters; }