Skip to content

Commit

Permalink
Fix code style
Browse files Browse the repository at this point in the history
  • Loading branch information
Kirill380 committed Oct 5, 2016
1 parent 14bc620 commit caff6c5
Show file tree
Hide file tree
Showing 14 changed files with 140 additions and 57 deletions.
Expand Up @@ -120,6 +120,12 @@ private static String toUrlSafe(String endpointProfileKeyHash) {
return Base64.encodeBase64URLSafeString(Base64.decodeBase64(endpointProfileKeyHash)); return Base64.encodeBase64URLSafeString(Base64.decodeBase64(endpointProfileKeyHash));
} }


/**
* Read file from disk and return it binary format represented as ByteArrayResource.
*
* @param resource the name of file resource
* @throws IOException the io exception
*/
public static ByteArrayResource getFileResource(final String resource) throws IOException { public static ByteArrayResource getFileResource(final String resource) throws IOException {
byte[] data = FileUtils.readResourceBytes(resource); byte[] data = FileUtils.readResourceBytes(resource);
ByteArrayResource bar = new ByteArrayResource(data) { ByteArrayResource bar = new ByteArrayResource(data) {
Expand All @@ -131,6 +137,12 @@ public String getFilename() {
return bar; return bar;
} }



/**
* Represented string resource as ByteArrayResource. The resource body encoded in UTF-8.
*
* @throws IOException the io exception
*/
public static ByteArrayResource getStringResource(final String resourceName, public static ByteArrayResource getStringResource(final String resourceName,
final String resourceBody) throws IOException { final String resourceBody) throws IOException {
byte[] data = resourceBody.getBytes("UTF-8"); byte[] data = resourceBody.getBytes("UTF-8");
Expand All @@ -143,6 +155,8 @@ public String getFilename() {
return bar; return bar;
} }




public EndpointProfilesPageDto getEndpointProfileByEndpointGroupId(PageLinkDto pageLink) public EndpointProfilesPageDto getEndpointProfileByEndpointGroupId(PageLinkDto pageLink)
throws Exception { throws Exception {
String endpointGroupId = pageLink.getEndpointGroupId(); String endpointGroupId = pageLink.getEndpointGroupId();
Expand Down Expand Up @@ -1097,7 +1111,13 @@ public List<EndpointProfileDto> getEndpointProfilesByUserExternalId(
new ParameterizedTypeReference<List<EndpointProfileDto>>() {}); new ParameterizedTypeReference<List<EndpointProfileDto>>() {});
return response.getBody(); return response.getBody();
} }

/**
* Provides security credentials, allowing an endpoint that uses them to
* interact with the specified application.
*
* @param applicationToken the application token to allow interaction with
* @param credentialsBody the security credentials to save
*/
public CredentialsDto provisionCredentials(String applicationToken, byte[] credentialsBody) { public CredentialsDto provisionCredentials(String applicationToken, byte[] credentialsBody) {
MultiValueMap<String, Object> parameters = new LinkedMultiValueMap<>(); MultiValueMap<String, Object> parameters = new LinkedMultiValueMap<>();
parameters.add("applicationToken", applicationToken); parameters.add("applicationToken", applicationToken);
Expand All @@ -1106,6 +1126,14 @@ public CredentialsDto provisionCredentials(String applicationToken, byte[] crede
parameters, CredentialsDto.class); parameters, CredentialsDto.class);
} }


/**
* Binds credentials to the specified server-side endpoint profile.
*
* @param applicationToken the application token
* @param credentialsId the id of the credentials to bind
* @param serverProfileVersion the server-side endpoint profile version
* @param serverProfileBody the server-side endpoint profile body
*/
public void provisionRegistration(String applicationToken, String credentialsId, public void provisionRegistration(String applicationToken, String credentialsId,
Integer serverProfileVersion, String serverProfileBody) { Integer serverProfileVersion, String serverProfileBody) {
MultiValueMap<String, Object> parameters = new LinkedMultiValueMap<>(); MultiValueMap<String, Object> parameters = new LinkedMultiValueMap<>();
Expand All @@ -1116,20 +1144,46 @@ public void provisionRegistration(String applicationToken, String credentialsId,
this.restTemplate.postForLocation(restTemplate.getUrl() + "provisionRegistration", parameters); this.restTemplate.postForLocation(restTemplate.getUrl() + "provisionRegistration", parameters);
} }


/**
* Provides the status for given credentials.
*
* @param applicationToken the application token
* @param credentialsId the id of the credentials
* @return credentials status
*/
public CredentialsStatus getCredentialsStatus(String applicationToken, String credentialsId) { public CredentialsStatus getCredentialsStatus(String applicationToken, String credentialsId) {
return this.restTemplate.getForObject( return this.restTemplate.getForObject(
restTemplate.getUrl() + "credentialsStatus?applicationToken={applicationToken}" restTemplate.getUrl() + "credentialsStatus?applicationToken={applicationToken}"
+ "&credentialsId={credentialsId}", + "&credentialsId={credentialsId}",
CredentialsStatus.class, applicationToken, credentialsId); CredentialsStatus.class, applicationToken, credentialsId);
} }


/**
* Revokes security credentials from the corresponding credentials storage.
* Also launches an asynchronous process to terminate all active sessions of
* the endpoint that uses these credentials.
*
* @param applicationToken the application token
* @param credentialsId the id of the credentials
*/
public void revokeCredentials(String applicationToken, String credentialsId) { public void revokeCredentials(String applicationToken, String credentialsId) {
MultiValueMap<String, Object> parameters = new LinkedMultiValueMap<>(); MultiValueMap<String, Object> parameters = new LinkedMultiValueMap<>();
parameters.add("applicationToken", applicationToken); parameters.add("applicationToken", applicationToken);
parameters.add("credentialsId", credentialsId); parameters.add("credentialsId", credentialsId);
this.restTemplate.postForLocation(restTemplate.getUrl() + "revokeCredentials", parameters); this.restTemplate.postForLocation(restTemplate.getUrl() + "revokeCredentials", parameters);
} }


/**
* Used if credentials stored in external storage and Kaa server can't directly revoke them but
* can be notified about security credentials revocation by external system.
*
* <p>If an endpoint is already registered with the specified credentials, this API
* call launches an asynchronous process to terminate all active sessions of
* the corresponding endpoint.</p>
*
* @param applicationToken the application token
* @param credentialsId the id of the credentials
*/
public void onCredentialsRevoked(String applicationToken, String credentialsId) { public void onCredentialsRevoked(String applicationToken, String credentialsId) {
MultiValueMap<String, Object> parameters = new LinkedMultiValueMap<>(); MultiValueMap<String, Object> parameters = new LinkedMultiValueMap<>();
parameters.add("applicationToken", applicationToken); parameters.add("applicationToken", applicationToken);
Expand Down
Expand Up @@ -181,6 +181,12 @@ private void setNewRequestFactory(int index) {
} }
} }


/**
* Login to Kaa server.
*
* @param username user name
* @param password password
*/
public void login(String username, String password) { public void login(String username, String password) {
this.username = username; this.username = username;
this.password = password; this.password = password;
Expand Down
Expand Up @@ -27,6 +27,9 @@ public class KaaRecordEvent implements Event {
private Map<String, String> headers; private Map<String, String> headers;
private byte[] body; private byte[] body;


/**
* Create a new instance of KaaRecordEvent.
*/
public KaaRecordEvent(RecordHeader recordHeader, Map<String, String> headers, byte[] body) { public KaaRecordEvent(RecordHeader recordHeader, Map<String, String> headers, byte[] body) {
this.recordHeader = recordHeader; this.recordHeader = recordHeader;
this.headers = headers; this.headers = headers;
Expand Down
Expand Up @@ -25,6 +25,12 @@ public class KaaSinkKey implements EventConstants {
private final String applicationToken; private final String applicationToken;
private final int schemaVersion; private final int schemaVersion;


/**
* Create a new instance of KaaSinkKey.
*
* @param applicationToken the application token
* @param schemaVersion the schema version
*/
public KaaSinkKey(String applicationToken, int schemaVersion) { public KaaSinkKey(String applicationToken, int schemaVersion) {
super(); super();
this.applicationToken = applicationToken; this.applicationToken = applicationToken;
Expand Down
Expand Up @@ -120,7 +120,7 @@ public CredentialsStatus getCredentialsStatus(
} }


/** /**
* Binds credentials to the server-side endpoint profile specified. * Binds credentials to the specified server-side endpoint profile.
* *
* @param applicationToken The application Token * @param applicationToken The application Token
* @param credentialsId The ID of the credentials to bind * @param credentialsId The ID of the credentials to bind
Expand Down
Expand Up @@ -30,14 +30,9 @@


import java.util.Map; import java.util.Map;


/**
* The Class SyncContext.
*/
public class SyncContext { public class SyncContext {


/**
* The response.
*/
private final ServerSync response; private final ServerSync response;


private String endpointKey; private String endpointKey;
Expand All @@ -50,19 +45,12 @@ public class SyncContext {


private AppSeqNumber appSeqNumber; private AppSeqNumber appSeqNumber;


/**
* The subscription states.
*/
private Map<String, Integer> subscriptionStates; private Map<String, Integer> subscriptionStates;


/**
* The system nf version.
*/
private int systemNfVersion; private int systemNfVersion;


/**
* The user nf version.
*/
private int userNfVersion; private int userNfVersion;


/** /**
Expand All @@ -75,6 +63,12 @@ public SyncContext(ServerSync response) {
this.response = response; this.response = response;
} }


/**
* Factory method that create instance where the response status set to FAILURE.
*
* @param requestId the request id
* @return the sync context
*/
public static SyncContext failure(Integer requestId) { public static SyncContext failure(Integer requestId) {
ServerSync response = new ServerSync(); ServerSync response = new ServerSync();
response.setRequestId(requestId); response.setRequestId(requestId);
Expand Down Expand Up @@ -105,7 +99,7 @@ public void setSubscriptionStates(Map<String, Integer> subscriptionStates) {
} }


/** /**
* Gets the system nf version. * Gets the system notification version.
* *
* @return the system nf version * @return the system nf version
*/ */
Expand All @@ -114,7 +108,7 @@ public int getSystemNfVersion() {
} }


/** /**
* Gets the user nf version. * Gets the user notification version.
* *
* @return the user nf version * @return the user nf version
*/ */
Expand All @@ -126,7 +120,12 @@ public EndpointProfileDto getEndpointProfile() {
return endpointProfile; return endpointProfile;
} }


public void setEndpointProfile(EndpointProfileDto profile) { /**
* Sets system and user notification versions.
*
* @param profile the profile
*/
public void setNotificationVersion(EndpointProfileDto profile) {
this.endpointProfile = profile; this.endpointProfile = profile;
if (profile != null) { if (profile != null) {
this.systemNfVersion = profile.getSystemNfVersion(); this.systemNfVersion = profile.getSystemNfVersion();
Expand Down
Expand Up @@ -299,7 +299,7 @@ public SyncContext syncClientProfile(SyncContext context, ProfileClientSync prof
profile = syncProfileState( profile = syncProfileState(
metaData.getApplicationToken(), context.getEndpointKey(), profile, false); metaData.getApplicationToken(), context.getEndpointKey(), profile, false);


context.setEndpointProfile(profile); context.setNotificationVersion(profile);


return context; return context;
} }
Expand Down Expand Up @@ -450,7 +450,7 @@ public SyncContext syncUseConfigurationRawSchema(SyncContext context,
profile = profileService.updateProfile(metaData, endpointKeyHash, useConfigurationRawSchema); profile = profileService.updateProfile(metaData, endpointKeyHash, useConfigurationRawSchema);
profile = syncProfileState( profile = syncProfileState(
metaData.getApplicationToken(), context.getEndpointKey(), profile, false); metaData.getApplicationToken(), context.getEndpointKey(), profile, false);
context.setEndpointProfile(profile); context.setNotificationVersion(profile);
} }
return context; return context;
} }
Expand All @@ -471,7 +471,7 @@ public SyncContext syncNotification(SyncContext context, NotificationClientSync
profile.setSubscriptions(new ArrayList<>(notificationResponse.getSubscriptionSet())); profile.setSubscriptions(new ArrayList<>(notificationResponse.getSubscriptionSet()));
return profile; return profile;
}; };
context.setEndpointProfile(profileService.updateProfile( context.setNotificationVersion(profileService.updateProfile(
updateFunction.apply(profileDto), (storedProfile, newProfile) -> { updateFunction.apply(profileDto), (storedProfile, newProfile) -> {
return updateFunction.apply(storedProfile); return updateFunction.apply(storedProfile);
})); }));
Expand All @@ -491,7 +491,7 @@ public SyncContext syncProfileServerHash(SyncContext context) {
context.getEndpointKey(), profile.getServerHash(), context.getEndpointKey(), profile.getServerHash(),
operationServerHash); operationServerHash);
profile.setServerHash(operationServerHash); profile.setServerHash(operationServerHash);
context.setEndpointProfile(profileService.updateProfile(profile, context.setNotificationVersion(profileService.updateProfile(profile,
(storedProfile, newProfile) -> storedProfile)); (storedProfile, newProfile) -> storedProfile));
} }
return context; return context;
Expand Down
Expand Up @@ -45,9 +45,7 @@
import javax.annotation.PostConstruct; import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy; import javax.annotation.PreDestroy;


/**
* The Class DefaultAkkaService.
*/
@Service @Service
public class DefaultAkkaService implements AkkaService { public class DefaultAkkaService implements AkkaService {


Expand All @@ -58,18 +56,12 @@ public class DefaultAkkaService implements AkkaService {
public static final String LOG_DISPATCHER_NAME = "log-dispatcher"; public static final String LOG_DISPATCHER_NAME = "log-dispatcher";
public static final String VERIFIER_DISPATCHER_NAME = "verifier-dispatcher"; public static final String VERIFIER_DISPATCHER_NAME = "verifier-dispatcher";
public static final String TOPIC_DISPATCHER_NAME = "topic-dispatcher"; public static final String TOPIC_DISPATCHER_NAME = "topic-dispatcher";
/**
* The Constant EPS.
*/
public static final String EPS = "EPS"; public static final String EPS = "EPS";
private static final String IO_ROUTER_ACTOR_NAME = "ioRouter"; private static final String IO_ROUTER_ACTOR_NAME = "ioRouter";
/**
* The Constant LOG.
*/
private static final Logger LOG = LoggerFactory.getLogger(DefaultAkkaService.class); private static final Logger LOG = LoggerFactory.getLogger(DefaultAkkaService.class);
/**
* The akka.
*/
private ActorSystem akka; private ActorSystem akka;


/** /**
Expand Down Expand Up @@ -170,6 +162,10 @@ public void onNotification(Notification notification) {
} }
} }



/**
* Remove all event listeners, stop ioRouter and opsActor actors and terminate actor system.
*/
@PreDestroy @PreDestroy
public void preDestroy() { public void preDestroy() {
context.getEventService().removeListener(eventListener); context.getEventService().removeListener(eventListener);
Expand Down Expand Up @@ -213,6 +209,12 @@ public class StatusListenerThread extends Thread {


private volatile boolean stopped = false; private volatile boolean stopped = false;


/**
* Create a new instance of StatusListenerThread.
*
* @param listener the akka status listener
* @param statusUpdateFrequency the status of update frequency
*/
public StatusListenerThread(AkkaStatusListener listener, long statusUpdateFrequency) { public StatusListenerThread(AkkaStatusListener listener, long statusUpdateFrequency) {
super(); super();
this.listener = listener; this.listener = listener;
Expand Down
Expand Up @@ -101,16 +101,14 @@
public class LocalEndpointActorMessageProcessor public class LocalEndpointActorMessageProcessor
extends AbstractEndpointActorMessageProcessor<LocalEndpointActorState> { extends AbstractEndpointActorMessageProcessor<LocalEndpointActorState> {


/**
* The Constant LOG.
*/
private static final Logger LOG = LoggerFactory.getLogger( private static final Logger LOG = LoggerFactory.getLogger(
LocalEndpointActorMessageProcessor.class); LocalEndpointActorMessageProcessor.class);


private final Map<Integer, LogDeliveryMessage> logUploadResponseMap; private final Map<Integer, LogDeliveryMessage> logUploadResponseMap;


private final Map<UUID, UserVerificationResponseMessage> userAttachResponseMap; private final Map<UUID, UserVerificationResponseMessage> userAttachResponseMap;



public LocalEndpointActorMessageProcessor(AkkaContext context, public LocalEndpointActorMessageProcessor(AkkaContext context,
String appToken, String appToken,
EndpointObjectHash key, EndpointObjectHash key,
Expand Down Expand Up @@ -323,7 +321,7 @@ private SyncContext sync(ClientSync request) throws GetDeltaException {
return SyncContext.failure(request.getRequestId()); return SyncContext.failure(request.getRequestId());
} }
SyncContext context = new SyncContext(new ServerSync()); SyncContext context = new SyncContext(new ServerSync());
context.setEndpointProfile(state.getProfile()); context.setNotificationVersion(state.getProfile());
context.setRequestId(request.getRequestId()); context.setRequestId(request.getRequestId());
context.setStatus(SyncStatus.SUCCESS); context.setStatus(SyncStatus.SUCCESS);
context.setEndpointKey(endpointKey); context.setEndpointKey(endpointKey);
Expand Down
Expand Up @@ -57,7 +57,7 @@ public class EncDecActor extends UntypedActor {
* Instantiates a new enc dec actor. * Instantiates a new enc dec actor.
* *
* @param epsActor the eps actor * @param epsActor the eps actor
* @param context the context * @param context the akka context
* @param platformProtocols the platform protocols * @param platformProtocols the platform protocols
*/ */
public EncDecActor(ActorRef epsActor, AkkaContext context, Set<String> platformProtocols) { public EncDecActor(ActorRef epsActor, AkkaContext context, Set<String> platformProtocols) {
Expand Down
Expand Up @@ -148,6 +148,11 @@ void encodeAndReply(SessionResponse message) {
} }
} }



/**
* Forward message to OperationsServerActor.
*
*/
public void forward(ActorContext context, SessionAware message) { public void forward(ActorContext context, SessionAware message) {
if (isSdkTokenValid(message.getSessionInfo().getSdkToken())) { if (isSdkTokenValid(message.getSessionInfo().getSdkToken())) {
LOG.debug("Forwarding session aware message: {}", message); LOG.debug("Forwarding session aware message: {}", message);
Expand Down
10 changes: 10 additions & 0 deletions server/node/src/main/java/org/spring4gwt/server/RpcHelper.java
Expand Up @@ -44,6 +44,16 @@ public static String invokeAndEncodeResponse(Object target,
AbstractSerializationStream.DEFAULT_FLAGS); AbstractSerializationStream.DEFAULT_FLAGS);
} }


/**
* Invoke the method on targeted object and encode received response.
*
* @param target the target object
* @param serviceMethod the service method
* @param args the args of method
* @param serializationPolicy the serialization policy
* @param flags the flags
* @throws SerializationException the serialization exception
*/
public static String invokeAndEncodeResponse(Object target, Method serviceMethod, Object[] args, public static String invokeAndEncodeResponse(Object target, Method serviceMethod, Object[] args,
SerializationPolicy serializationPolicy, SerializationPolicy serializationPolicy,
int flags) throws SerializationException { int flags) throws SerializationException {
Expand Down

0 comments on commit caff6c5

Please sign in to comment.