Skip to content

Commit

Permalink
Simplifying the policy definition flow and some clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
anuchandy committed Mar 21, 2017
1 parent 784ee29 commit 38a0b7a
Show file tree
Hide file tree
Showing 36 changed files with 399 additions and 257 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -62,33 +62,55 @@ public interface AuthorizationRule<RuleT extends AuthorizationRule> extends
*/
interface DefinitionStages {
/**
* The stage of the rule definition allowing to specify an access rights.
* The stage of the rule definition allowing to enable listen policy.
*
* @param <T> the next stage
*/
interface WithAccessRight<T> {
interface WithListen<T> {
/**
* Specifies the access rights.
*
* @param rights the access rights
* @return the next stage
*/
T withAccessRight(AccessRights rights);
T withListen();
}

/**
* The stage of the rule definition allowing to specify multiple access rights.
* The stage of the rule definition allowing to enable send policy.
*
* @param <T> the next stage
*/
interface WithAccessRights<T> {
interface WithSend<T> {
/**
* Specifies the access rights.
*
* @param rights the access rights
* @return the next stage
*/
T withAccessRights(AccessRights... rights);
T withSend();
}

/**
* The stage of the rule definition allowing to enable manage policy.
*
* @param <T> the next stage
*/
interface WithManage<T> {
/**
* @return the next stage
*/
T withManage();
}

/**
* The stage of the rule definition allowing to enable send or manage policy.
*
* @param <T> the next stage
*/
interface WithSendOrManage<T> extends WithSend<T>, WithManage<T> {
}

/**
* The stage of the rule definition allowing to enable listen, send or manage policy.
*
* @param <T> the next stage
*/
interface WithListenOrSendOrManage<T> extends WithListen<T>, WithSendOrManage<T> {
}
}

Expand All @@ -98,32 +120,55 @@ interface WithAccessRights<T> {
*/
interface UpdateStages {
/**
* The stage of the rule definition allowing to add or remove access rights.
* The stage of the rule definition allowing to enable listen policy.
*
* @param <T> the next stage
*/
interface WithAccessRight<T> {
interface WithListen<T> {
/**
* Specifies the access rights.
*
* @param rights the access rights
* @return the next stage
*/
T withAccessRight(AccessRights rights);
T withListen();
}

/**
* The stage of the rule definition allowing to enable send policy.
*
* @param <T> the next stage
*/
interface WithSend<T> {
/**
* Specifies the access rights.
*
* @param rights the access rights
* @return the next stage
*/
T withAccessRights(AccessRights... rights);
T withSend();
}

/**
* The stage of the rule update allowing to enable manage policy.
*
* @param <T> the next stage
*/
interface WithManage<T> {
/**
* Removes the access rights.
*
* @param rights the access rights
* @return the next stage
*/
T withoutAccessRight(AccessRights rights);
T withManage();
}

/**
* The stage of the rule update allowing to enable send or manage policy.
*
* @param <T> the next stage
*/
interface WithSendOrManage<T> extends WithSend<T>, WithManage<T> {
}

/**
* The stage of the rule update allowing to enable listen, send or manage policy.
*
* @param <T> the next stage
*/
interface WithListenOrSendOrManage<T> extends WithListen<T>, WithSendOrManage<T> {
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/**
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for
* license information.
*/

package com.microsoft.azure.management.servicebus;

import com.microsoft.azure.management.servicebus.implementation.CheckNameAvailabilityResultInner;

/**
* The {@link com.microsoft.azure.management.servicebus.Namespaces#checkNameAvailability} action result.
*/
public class CheckNameAvailabilityResult {
private CheckNameAvailabilityResultInner inner;
/**
* Creates an instance of the check name availability result object.
*
* @param inner the inner object
*/
public CheckNameAvailabilityResult(CheckNameAvailabilityResultInner inner) {
this.inner = inner;
}
/**
* @return a boolean value that indicates whether the name is available for
* you to use. If true, the name is available. If false, the name has
* already been taken or invalid and cannot be used.
*/
public boolean isAvailable() {
return inner.nameAvailable();
}
/**
* @return the reason that a namespace name could not be used. The
* Reason element is only returned if NameAvailable is false. Possible
* values include: 'AccountNameInvalid', 'AlreadyExists'.
*/
public UnavailableReason reason() {
return inner.reason();
}
/**
* @return an error message explaining the Reason value in more detail
*/
public String message() {
return inner.message();
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -131,13 +131,26 @@ interface WithTopic {
*/
interface WithAuthorizationRule {
/**
* Creates an authorization rule for the service bus namespace.
* Creates a send authorization rule for the service bus namespace.
*
* @param name rule name
* @param rights rule rights
* @return next stage of the service bus namespace definition
*/
WithCreate withNewAuthorizationRule(String name, AccessRights... rights);
WithCreate withNewSendRule(String name);
/**
* Creates a listen authorization rule for the service bus namespace.
*
* @param name rule name
* @return next stage of the service bus namespace definition
*/
WithCreate withNewListenRule(String name);
/**
* Creates a manage authorization rule for the service bus namespace.
*
* @param name rule name
* @return next stage of the service bus namespace definition
*/
WithCreate withNewManageRule(String name);
}

/**
Expand Down Expand Up @@ -234,14 +247,26 @@ interface WithTopic {
*/
interface WithAuthorizationRule {
/**
* Creates an authorization rule for the service bus namespace.
* Creates a send authorization rule for the service bus namespace.
*
* @param name rule name
* @param rights rule rights
* @return next stage of the service bus namespace update
*/
Update withNewAuthorizationRule(String name, AccessRights... rights);

Update withNewSendRule(String name);
/**
* Creates a listen authorization rule for the service bus namespace.
*
* @param name rule name
* @return next stage of the service bus namespace update
*/
Update withNewListenRule(String name);
/**
* Creates a manage authorization rule for the service bus namespace.
*
* @param name rule name
* @return next stage of the service bus namespace update
*/
Update withNewManageRule(String name);
/**
* Removes an authorization rule from the service bus namespace.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ interface DefinitionStages {
/**
* The first stage of namespace authorization rule definition.
*/
interface Blank extends AuthorizationRule.DefinitionStages.WithAccessRight<WithCreate> {
interface Blank extends AuthorizationRule.DefinitionStages.WithListenOrSendOrManage<WithCreate> {
}

/**
Expand All @@ -53,7 +53,7 @@ interface Definition extends
*/
interface Update extends
Appliable<NamespaceAuthorizationRule>,
AuthorizationRule.UpdateStages.WithAccessRight<Update> {
AuthorizationRule.UpdateStages.WithListenOrSendOrManage<Update> {
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
package com.microsoft.azure.management.servicebus;

import com.microsoft.azure.management.apigeneration.Fluent;
import com.microsoft.azure.management.resources.fluentcore.arm.models.HasParent;
import com.microsoft.azure.management.resources.fluentcore.collection.SupportsCreating;
import com.microsoft.azure.management.resources.fluentcore.model.HasInner;
import com.microsoft.azure.management.servicebus.implementation.NamespacesInner;
Expand All @@ -19,6 +18,5 @@
public interface NamespaceAuthorizationRules extends
AuthorizationRules<NamespaceAuthorizationRule>,
SupportsCreating<NamespaceAuthorizationRule.DefinitionStages.Blank>,
HasParent<Namespace>,
HasInner<NamespacesInner> {
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@
import com.microsoft.azure.management.resources.fluentcore.model.HasInner;
import com.microsoft.azure.management.servicebus.implementation.NamespacesInner;
import com.microsoft.azure.management.servicebus.implementation.ServiceBusManager;
import com.microsoft.rest.ServiceCallback;
import com.microsoft.rest.ServiceFuture;
import rx.Observable;

/**
* Entry point to service bus namespace API in Azure.
Expand All @@ -34,4 +37,28 @@ public interface Namespaces extends
SupportsDeletingByGroup,
HasManager<ServiceBusManager>,
HasInner<NamespacesInner> {
/**
* Checks that namespace name is valid and is not in use.
*
* @param name the account name to check
* @return whether the name is available and other info if not
*/
CheckNameAvailabilityResult checkNameAvailability(String name);

/**
* Checks that namespace name is valid and is not in use asynchronously.
*
* @param name the namespace name to check
* @return whether the name is available and other info if not
*/
Observable<CheckNameAvailabilityResult> checkNameAvailabilityAsync(String name);

/**
* Checks that namespace name is valid and is not in use asynchronously.
*
* @param name the namespace name to check
* @param callback the callback to call on success or failure
* @return a handle to cancel the request
*/
ServiceFuture<CheckNameAvailabilityResult> checkNameAvailabilityAsync(String name, ServiceCallback<CheckNameAvailabilityResult> callback);
}
Loading

0 comments on commit 38a0b7a

Please sign in to comment.