@Override public void init(EndpointProfileDto profile, String profileSchemaBody, String serverProfileSchemaBody) { GenericAvroConverter<GenericRecord> endpointProfileConverter = new GenericAvroConverter<>( new Schema.Parser().parse(profileSchemaBody)); GenericAvroConverter<GenericRecord> serverProfileConverter = new GenericAvroConverter<>( new Schema.Parser().parse(serverProfileSchemaBody)); this.epKey = Base64Util.encode(profile.getEndpointKeyHash()); try { if (profile.getServerProfileBody() != null) { serverProfileGenericRecord = serverProfileConverter.decodeJson( profile.getServerProfileBody()); } if (profile.getClientProfileBody() != null) { clientProfileGenericRecord = endpointProfileConverter.decodeJson( profile.getClientProfileBody()); } } catch (IOException ioe) { LOG.error("Error decoding avro object from Json string", ioe); } }
json = profile.getClientProfileBody(); } else { json = profile.getServerProfileBody();
private EndpointProfileDataDto convert(EndpointProfileDto profileDto) { return new EndpointProfileDataDto( profileDto.getId(), endpointKey, profileDto.getClientProfileVersion(), profileDto.getClientProfileBody(), profileDto.getServerProfileVersion(), profileDto.getServerProfileBody()); }
@Override public List<SchemaInfoDto> getServerProfileSchemaInfosByEndpointKey(String endpointKeyHash) throws KaaAdminServiceException { checkAuthority(KaaAuthorityDto.TENANT_DEVELOPER, KaaAuthorityDto.TENANT_USER); try { EndpointProfileDto endpointProfile = getEndpointProfileByKeyHash(endpointKeyHash); List<ServerProfileSchemaDto> serverProfileSchemas = controlService.getServerProfileSchemasByApplicationId( endpointProfile.getApplicationId()); List<SchemaInfoDto> schemaInfos = new ArrayList<>(serverProfileSchemas.size()); for (ServerProfileSchemaDto serverProfileSchema : serverProfileSchemas) { SchemaInfoDto schemaInfo = new SchemaInfoDto(serverProfileSchema); String body = null; if (schemaInfo.getVersion() == endpointProfile.getServerProfileVersion()) { body = endpointProfile.getServerProfileBody(); } RecordField schemaForm = createRecordFieldFromCtlSchemaAndBody( serverProfileSchema.getCtlSchemaId(), body); schemaInfo.setSchemaName(serverProfileSchema.getName()); schemaInfo.setSchemaForm(schemaForm); schemaInfos.add(schemaInfo); } Collections.sort(schemaInfos, Collections.reverseOrder()); return schemaInfos; } catch (Exception ex) { throw Utils.handleException(ex); } }
@Override public EndpointProfileBodyDto findBodyByKeyHash(byte[] endpointKeyHash) { LOG.debug("Find endpoint profile body by endpoint key hash [{}] ", endpointKeyHash); EndpointProfileBodyDto endpointProfileBodyDto = null; Query query = Query.query(where(EP_ENDPOINT_KEY_HASH).is(endpointKeyHash)); query.fields() .include(DaoConstants.PROFILE) .include(EP_SERVER_PROFILE_PROPERTY) .include(EP_APPLICATION_ID) .include(EP_PROFILE_VERSION) .include(EP_SERVER_PROFILE_VERSION_PROPERTY) .include(EP_USE_RAW_SCHEMA); EndpointProfileDto pf = mongoTemplate.findOne(query, getDocumentClass()).toDto(); if (pf != null) { endpointProfileBodyDto = new EndpointProfileBodyDto( endpointKeyHash, pf.getClientProfileBody(), pf.getServerProfileBody(), pf.getClientProfileVersion(), pf.getServerProfileVersion(), pf.getApplicationId()); } LOG.debug("[{}] Found client-side endpoint profile body {} with client-side endpoint " + "profile version {} and server-side endpoint profile body {} " + "with server-side endpoint profile version {} and application id {}", endpointKeyHash, pf.getClientProfileBody(), pf.getServerProfileBody(), pf.getClientProfileVersion(), pf.getServerProfileVersion(), pf.getApplicationId()); return endpointProfileBodyDto; }
byte[] keyHash = endpointProfileDto.getEndpointKeyHash(); validateHash(keyHash, "Incorrect key hash for endpoint profile."); if (endpointProfileDto.getServerProfileBody() == null) { ServerProfileSchemaDto serverProfileSchemaDto = serverProfileService
ep.getEndpointKeyHash(), ep.getClientProfileBody(), ep.getServerProfileBody(), ep.getClientProfileVersion(), ep.getServerProfileVersion(),
@Test public void testFindBodyByKeyHash() throws Exception { EndpointProfileDto expected = generateEndpointProfileWithEndpointGroupId(null); EndpointProfileBodyDto found = endpointProfileDao.findBodyByKeyHash(expected.getEndpointKeyHash()); Assert.assertFalse(found.getClientSideProfile().isEmpty()); Assert.assertFalse(found.getServerSideProfile().isEmpty()); Assert.assertEquals(expected.getClientProfileBody(), found.getClientSideProfile()); Assert.assertEquals(expected.getServerProfileBody(), found.getServerSideProfile()); }
@Test public void testSaveServerProfile() throws IOException { ServerProfileSchemaDto schemaDto = generateServerProfileSchema(null, null); EndpointProfileDto ep = generateEndpointProfileDtoWithSchemaVersion(schemaDto.getApplicationId(), schemaDto.getVersion(), null); EndpointProfileDto updated = serverProfileService.saveServerProfile(ep.getEndpointKeyHash(), schemaDto.getVersion(), readSchemaFileAsString(TEST_PROFILE_BODY_PATH)); Assert.assertArrayEquals(ep.getEndpointKeyHash(), updated.getEndpointKeyHash()); Assert.assertNotEquals(ep.getServerProfileBody(), updated.getServerProfileBody()); Assert.assertEquals(ep.getServerProfileVersion(), updated.getServerProfileVersion()); }
@Test public void findBodyByKeyHashTest() { EndpointProfileDto endpointProfile = generateEndpointProfileDto(null, null); Assert.assertNotNull(endpointProfile); EndpointProfileBodyDto found = endpointProfileDao.findBodyByKeyHash(endpointProfile.getEndpointKeyHash()); Assert.assertNotNull(found); Assert.assertEquals(endpointProfile.getClientProfileBody(), found.getClientSideProfile()); Assert.assertEquals(endpointProfile.getServerProfileBody(), found.getServerSideProfile()); }
endpointProfileView.setServerProfileRecord(createRecordFieldFromCtlSchemaAndBody( serverProfileSchema.getCtlSchemaId(), endpointProfile.getServerProfileBody()));
this.serverHash = dto.getServerHash(); this.sdkToken = dto.getSdkToken(); this.serverProfile = dto.getServerProfileBody(); this.useConfigurationRawSchema = dto.isUseConfigurationRawSchema(); this.version = dto.getVersion();
this.sdkToken = dto.getSdkToken(); this.serverProfile = MongoDaoUtil.encodeReservedCharacteres( (DBObject) JSON.parse(dto.getServerProfileBody())); this.useConfigurationRawSchema = dto.isUseConfigurationRawSchema(); this.version = dto.getVersion();