/** * Create new instance of <code>CassandraEndpointUserConfiguration</code>. * * @param dto data transfer object contain data that * assign on fields of new instance */ public CassandraEndpointUserConfiguration(EndpointUserConfigurationDto dto) { this.userId = dto.getUserId(); this.appToken = dto.getAppToken(); this.schemaVersion = dto.getSchemaVersion(); this.body = dto.getBody(); }
@Override public EndpointUserConfigurationDto toDto() { EndpointUserConfigurationDto dto = new EndpointUserConfigurationDto(); dto.setAppToken(appToken); dto.setBody(body); dto.setSchemaVersion(schemaVersion); dto.setUserId(userId); return dto; } }
@Override public EndpointUserConfigurationDto saveUserConfiguration(EndpointUserConfigurationDto userConfig) { EndpointUserConfigurationDto userConfigurationDto = null; if (userConfig != null) { String userConfigBody = userConfig.getBody(); if (isNotBlank(userConfigBody)) { String appToken = userConfig.getAppToken(); ApplicationDto applicationDto = applicationService.findAppByApplicationToken(appToken); if (applicationDto != null) { int schemaVersion = userConfig.getSchemaVersion(); userConfig.setBody(configurationService.normalizeAccordingToOverrideConfigurationSchema(applicationDto.getId(), schemaVersion, userConfigBody)); userConfigurationDto = getDto(endpointUserConfigurationDao.save(userConfig)); } else { LOG.warn("Can't find application with token {} for endpoint user configuration.", appToken); throw new IncorrectParameterException("Can't find application for specified token."); } } else { LOG.warn("Invalid endpoint user configuration. Configuration body is empty"); throw new IncorrectParameterException("Configuration body is empty."); } } return userConfigurationDto; }
@Override protected void onSave() { entity.setUserId(detailsView.getUserId().getValue()); entity.setSchemaVersion(detailsView.getConfigurationSchemaInfo().getValue().getVersion()); }
@Override public void editUserConfiguration(EndpointUserConfigurationDto endpointUserConfiguration, String applicationId, RecordField configurationData) throws KaaAdminServiceException { checkAuthority(KaaAuthorityDto.TENANT_DEVELOPER, KaaAuthorityDto.TENANT_USER); try { ApplicationDto application = checkApplicationId(applicationId); endpointUserConfiguration.setAppToken(application.getApplicationToken()); GenericRecord record = FormAvroConverter.createGenericRecordFromRecordField( configurationData); GenericAvroConverter<GenericRecord> converter = new GenericAvroConverter<>( record.getSchema()); String body = converter.encodeToJson(record); endpointUserConfiguration.setBody(body); controlService.editUserConfiguration(endpointUserConfiguration); } catch (Exception ex) { throw Utils.handleException(ex); } }
@Test public void findUserConfigurationByExternalUIdAndAppTokenAndSchemaVersionNullTest() throws IOException { ApplicationDto appDto = generateApplicationDto(); EndpointUserDto userDto = generateEndpointUserDto(appDto.getTenantId()); EndpointUserConfigurationDto userConfigurationDto = generateEndpointUserConfigurationDto(userDto, appDto, null, readSchemaFileAsString(OVERRIDE_USER_DATA_JSON)); userConfigurationService.removeByUserIdAndAppTokenAndSchemaVersion(userDto.getId(), appDto.getApplicationToken(), userConfigurationDto.getSchemaVersion()); EndpointUserConfigurationDto endpointUserConfigurationDto = userConfigurationService.findUserConfigurationByExternalUIdAndAppTokenAndSchemaVersion( userDto.getExternalId(), appDto.getApplicationToken(), userConfigurationDto.getSchemaVersion(), appDto.getTenantId()); Assert.assertNull(endpointUserConfigurationDto); }
.getMessage(); json = endpointUserConfigurationDto.getBody();
@Override protected EndpointUserConfigurationDto newEntity() { return new EndpointUserConfigurationDto(); }
@Override public void editUserConfiguration(EndpointUserConfigurationDto endpointUserConfiguration) throws KaaAdminServiceException { checkAuthority(KaaAuthorityDto.TENANT_DEVELOPER, KaaAuthorityDto.TENANT_USER); try { checkApplicationToken(endpointUserConfiguration.getAppToken()); controlService.editUserConfiguration(endpointUserConfiguration); } catch (Exception ex) { throw Utils.handleException(ex); } }
@Test public void findUserConfigurationByExternalUIdAndAppTokenAndSchemaVersionTest() throws IOException { ApplicationDto appDto = generateApplicationDto(); EndpointUserDto userDto = generateEndpointUserDto(appDto.getTenantId()); EndpointUserConfigurationDto userConfigurationDto = generateEndpointUserConfigurationDto(userDto, appDto, null, readSchemaFileAsString(OVERRIDE_USER_DATA_JSON)); EndpointUserConfigurationDto endpointUserConfigurationDto = userConfigurationService.findUserConfigurationByExternalUIdAndAppTokenAndSchemaVersion( userDto.getExternalId(), appDto.getApplicationToken(), userConfigurationDto.getSchemaVersion(), appDto.getTenantId()); Assert.assertNotNull(endpointUserConfigurationDto); }
@Override public byte[] fetchUcfHash(String appToken, EndpointProfileDto profile) { if (profile.getEndpointUserId() == null || profile.getEndpointUserId().isEmpty()) { return null; } EndpointUserConfigurationDto ucfDto = userConfigurationService.findUserConfigurationByUserIdAndAppTokenAndSchemaVersion( profile.getEndpointUserId(), appToken, profile.getConfigurationVersion()); if (ucfDto != null) { return EndpointObjectHash.fromString(ucfDto.getBody()).getData(); } return null; }
@Override protected EndpointUserConfigurationDto newEntity() { return new EndpointUserConfigurationDto(); }
@Override public EndpointUserConfigurationDto toDto() { EndpointUserConfigurationDto dto = new EndpointUserConfigurationDto(); dto.setAppToken(appToken); dto.setBody(body); dto.setSchemaVersion(schemaVersion); dto.setUserId(userId); return dto; } }
/** * Create new instance of <code>MongoEndpointUserConfiguration</code>. * @param dto data transfer object contain data that * assign on fields of new instance */ public MongoEndpointUserConfiguration(EndpointUserConfigurationDto dto) { this.userId = dto.getUserId(); this.appToken = dto.getAppToken(); this.schemaVersion = dto.getSchemaVersion(); this.body = dto.getBody(); this.id = userId + ID_DELIMITER + appToken + ID_DELIMITER + schemaVersion; }
mergedConfiguration = mergeConfiguration(endpointId, userConfig.getBody(), latestConfigurationSchema, mergedConfiguration);
protected EndpointUserConfigurationDto generateEndpointUserConfigurationDto(EndpointUserDto endpointUser, ApplicationDto applicationDto, ConfigurationSchemaDto configurationSchema, String body, boolean isNullAppDto) { EndpointUserConfigurationDto configurationDto = new EndpointUserConfigurationDto(); configurationDto.setBody(body); if (endpointUser == null) { endpointUser = generateEndpointUserDto(null); } if (!isNullAppDto) { if (applicationDto == null) { applicationDto = generateApplicationDto(); } configurationDto.setAppToken(applicationDto.getApplicationToken()); } else { return userConfigurationService.saveUserConfiguration(configurationDto); } configurationDto.setUserId(endpointUser.getId()); if (configurationSchema == null) { configurationSchema = generateConfSchemaDto(null, applicationDto.getId(), 1).get(0); } configurationDto.setSchemaVersion(configurationSchema.getVersion()); return userConfigurationService.saveUserConfiguration(configurationDto); }
@Override public void editUserConfiguration(EndpointUserConfigurationDto configuration) throws ControlServiceException { ApplicationDto appDto = applicationService.findAppByApplicationToken( configuration.getAppToken()); EndpointUserDto userDto = endpointService.findEndpointUserByExternalIdAndTenantId( configuration.getUserId(), appDto.getTenantId()); if (userDto == null) { throw new NotFoundException("Specified user not found!"); } configuration.setUserId(userDto.getId()); configuration = userConfigurationService.saveUserConfiguration(configuration); EndpointObjectHash hash = EndpointObjectHash.fromString(configuration.getBody()); checkNeighbors(); OperationsNodeInfo server = resolve(configuration.getUserId()); if (server != null) { UserConfigurationUpdate msg = new UserConfigurationUpdate(appDto.getTenantId(), configuration.getUserId(), configuration.getAppToken(), configuration.getSchemaVersion(), hash.getDataBuf()); if (LOG.isTraceEnabled()) { LOG.trace("Sending message {} to [{}]", msg, Neighbors.getServerId( server.getConnectionInfo())); } neighbors.sendMessage(server.getConnectionInfo(), OperationsServiceMsg.fromUpdate(msg)); } else { LOG.warn("Can't find server for user [{}]", configuration.getUserId()); } }