Navigation Menu

Skip to content

Commit

Permalink
KAA-343: Updated java sdk generation and added notification deseriali…
Browse files Browse the repository at this point in the history
…zer template.
  • Loading branch information
Igor Khanenko committed Feb 10, 2015
1 parent 2dd77a9 commit 7451408
Show file tree
Hide file tree
Showing 5 changed files with 87 additions and 132 deletions.
Expand Up @@ -120,6 +120,12 @@ public class JavaSdkGenerator extends SdkGenerator {
/** The Constant EVENT_CLASS_FAMILY_VERSION_PROPERTY. */ /** The Constant EVENT_CLASS_FAMILY_VERSION_PROPERTY. */
private static final String EVENT_CLASS_FAMILY_VERSION_PROPERTY = "event_cf_version"; private static final String EVENT_CLASS_FAMILY_VERSION_PROPERTY = "event_cf_version";


/** The Constant NOTIFICATION_LISTENER_SOURCE_TEMPLATE. */
private static final String NOTIFICATION_LISTENER_SOURCE_TEMPLATE = "sdk/java/nf/NotificationListener.java.template";

/** The Constant NOTIFICATION_DESERIALIZER_SOURCE_TEMPLATE. */
private static final String NOTIFICATION_DESERIALIZER_SOURCE_TEMPLATE = "sdk/java/nf/NotificationDeserializer.java.template";

/** The Constant PROFILE_CONTAINER_SOURCE_TEMPLATE. */ /** The Constant PROFILE_CONTAINER_SOURCE_TEMPLATE. */
private static final String PROFILE_CONTAINER_SOURCE_TEMPLATE = "sdk/java/profile/ProfileContainer.java.template"; private static final String PROFILE_CONTAINER_SOURCE_TEMPLATE = "sdk/java/profile/ProfileContainer.java.template";


Expand All @@ -129,9 +135,6 @@ public class JavaSdkGenerator extends SdkGenerator {
/** The Constant DEFAULT_PROFILE_SERIALIZER_SOURCE_TEMPLATE. */ /** The Constant DEFAULT_PROFILE_SERIALIZER_SOURCE_TEMPLATE. */
private static final String DEFAULT_PROFILE_SERIALIZER_SOURCE_TEMPLATE = "sdk/java/profile/DefaultProfileSerializer.java.template"; private static final String DEFAULT_PROFILE_SERIALIZER_SOURCE_TEMPLATE = "sdk/java/profile/DefaultProfileSerializer.java.template";


/** The Constant ABSTRACT_NOTIFICATION_LISTENER_SOURCE_TEMPLATE. */
private static final String ABSTRACT_NOTIFICATION_LISTENER_SOURCE_TEMPLATE = "sdk/java/AbstractNotificationListener.java.template";

/** The Constant LOG_RECORD_SOURCE_TEMPLATE. */ /** The Constant LOG_RECORD_SOURCE_TEMPLATE. */
private static final String LOG_RECORD_SOURCE_TEMPLATE = "sdk/java/log/LogRecord.java.template"; private static final String LOG_RECORD_SOURCE_TEMPLATE = "sdk/java/log/LogRecord.java.template";


Expand All @@ -150,8 +153,11 @@ public class JavaSdkGenerator extends SdkGenerator {
/** The Constant ABSTRACT_PROFILE_CONTAINER. */ /** The Constant ABSTRACT_PROFILE_CONTAINER. */
private static final String PROFILE_SERIALIZER = "ProfileSerializer"; private static final String PROFILE_SERIALIZER = "ProfileSerializer";


/** The Constant ABSTRACT_NOTIFICATION_LISTENER. */ /** The Constant NOTIFICATION_LISTENER. */
private static final String ABSTRACT_NOTIFICATION_LISTENER = "AbstractNotificationListener"; private static final String NOTIFICATION_LISTENER = "NotificationListener";

/** The Constant NOTIFICATION_DESERIALIZER. */
private static final String NOTIFICATION_DESERIALIZER = "NotificationDeserializer";


/** The Constant USER_VERIFIER_CONSTANTS. */ /** The Constant USER_VERIFIER_CONSTANTS. */
private static final String USER_VERIFIER_CONSTANTS = "UserVerifierConstants"; private static final String USER_VERIFIER_CONSTANTS = "UserVerifierConstants";
Expand Down Expand Up @@ -257,14 +263,26 @@ public Sdk generateSdk(String buildVersion, List<BootstrapNodeInfo> bootstrapNod
javaSources.add(profileSerializerClassBean); javaSources.add(profileSerializerClassBean);


Schema notificationSchema = new Schema.Parser().parse(notificationSchemaBody); Schema notificationSchema = new Schema.Parser().parse(notificationSchemaBody);
String notificationClassName = profileSchema.getName();
String notificationClassPackage = profileSchema.getNamespace();

javaSources.addAll(generateSchemaSources(notificationSchema)); javaSources.addAll(generateSchemaSources(notificationSchema));
String notificationListenerTemplate = readResource(ABSTRACT_NOTIFICATION_LISTENER_SOURCE_TEMPLATE); String notificationListenerTemplate = readResource(NOTIFICATION_LISTENER_SOURCE_TEMPLATE);
String notificationListenerSource = notificationListenerTemplate.replaceAll(NOTIFICATION_CLASS_PACKAGE_VAR, String notificationListenerSource = notificationListenerTemplate.replaceAll(NOTIFICATION_CLASS_PACKAGE_VAR,
notificationSchema.getNamespace()).replaceAll(NOTIFICATION_CLASS_VAR, notificationSchema.getName()); notificationClassPackage).replaceAll(NOTIFICATION_CLASS_VAR, notificationClassName);


JavaDynamicBean notificationListenerClassBean = new JavaDynamicBean(ABSTRACT_NOTIFICATION_LISTENER, notificationListenerSource); JavaDynamicBean notificationListenerClassBean = new JavaDynamicBean(NOTIFICATION_LISTENER, notificationListenerSource);
javaSources.add(notificationListenerClassBean); javaSources.add(notificationListenerClassBean);


javaSources.addAll(generateSchemaSources(notificationSchema));
String notificationDeserializerSourceTemplate = readResource(NOTIFICATION_DESERIALIZER_SOURCE_TEMPLATE);
String notificationDeserializerSource = notificationDeserializerSourceTemplate.replaceAll(NOTIFICATION_CLASS_PACKAGE_VAR,
notificationClassPackage).replaceAll(NOTIFICATION_CLASS_VAR, notificationClassName);

JavaDynamicBean notificationDeserializerClassBean = new JavaDynamicBean(NOTIFICATION_LISTENER, notificationDeserializerSource);
javaSources.add(notificationDeserializerClassBean);


Schema logSchema = new Schema.Parser().parse(logSchemaBody); Schema logSchema = new Schema.Parser().parse(logSchemaBody);
javaSources.addAll(generateSchemaSources(logSchema)); javaSources.addAll(generateSchemaSources(logSchema));
String logRecordTemplate = readResource(LOG_RECORD_SOURCE_TEMPLATE); String logRecordTemplate = readResource(LOG_RECORD_SOURCE_TEMPLATE);
Expand Down

This file was deleted.

This file was deleted.

@@ -0,0 +1,23 @@
package org.kaaproject.kaa.client.notification;

import java.io.IOException;
import org.kaaproject.kaa.common.avro.AvroByteArrayConverter;
import ${notification_class_package}.${notification_class};

/**
* This class deserialize binary data to notification object.
*
* This implementation is auto-generated. Please modify corresponding template file.
*
* @author Andrew Shvayka
*
*/
public class NotificationDeserializer {

private final AvroByteArrayConverter<${notification_class}> converter = new AvroByteArrayConverter<${notification_class}>(${notification_class}.class);

${notification_class} fromByteArray(byte[] data) throws IOException{
return converter.fromByteArray(data);
}

}
@@ -0,0 +1,38 @@
/*
* Copyright 2014 CyberVision, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.kaaproject.kaa.client.notification;

import ${notification_class_package}.${notification_class};

/**
* The listener to notifications.
*
* @author Andrew Shvayka
*
*/
public interface NotificationListener {

/**
* Called on each new notification.
*
* @param topicId the topic's id.
* @param notification the notification object.
*
*/
void onNotification(String topicId, ${notification_class} notification);

}

0 comments on commit 7451408

Please sign in to comment.