Mahesh Poojary Huawei
Committed by Ray Milkey

[ONOS-3114] flowclassifierid

Change-Id: I731278516c4375dc036726058b8969a767be84ca
......@@ -15,6 +15,8 @@
*/
package org.onosproject.vtnrsc;
import static com.google.common.base.Preconditions.checkNotNull;
import com.google.common.base.MoreObjects;
import java.util.UUID;
......@@ -33,6 +35,7 @@ public final class FlowClassifierId {
* @param flowClassifierId flow classifier id.
*/
private FlowClassifierId(final UUID flowClassifierId) {
checkNotNull(flowClassifierId, "Flow classifier id can not be null");
this.flowClassifierId = flowClassifierId;
}
......@@ -42,7 +45,7 @@ public final class FlowClassifierId {
* @param flowClassifierId flow classifier id
* @return new flow classifier id
*/
public static FlowClassifierId flowClassifierId(final UUID flowClassifierId) {
public static FlowClassifierId of(final UUID flowClassifierId) {
return new FlowClassifierId(flowClassifierId);
}
......@@ -52,7 +55,7 @@ public final class FlowClassifierId {
* @param flowClassifierId flow classifier id
* @return new flow classifier id
*/
public static FlowClassifierId flowClassifierId(final String flowClassifierId) {
public static FlowClassifierId of(final String flowClassifierId) {
return new FlowClassifierId(UUID.fromString(flowClassifierId));
}
......
......@@ -32,11 +32,11 @@ import java.util.UUID;
public class FlowClassifierIdTest {
final FlowClassifierId flowClassifierId1 = FlowClassifierId
.flowClassifierId("78dcd363-fc23-aeb6-f44b-56dc5e2fb3ae");
.of("78dcd363-fc23-aeb6-f44b-56dc5e2fb3ae");
final FlowClassifierId sameAsFlowClassifierId1 = FlowClassifierId
.flowClassifierId("78dcd363-fc23-aeb6-f44b-56dc5e2fb3ae");
.of("78dcd363-fc23-aeb6-f44b-56dc5e2fb3ae");
final FlowClassifierId flowClassifierId2 = FlowClassifierId
.flowClassifierId("dace4513-24fc-4fae-af4b-321c5e2eb3d1");
.of("dace4513-24fc-4fae-af4b-321c5e2eb3d1");
/**
* Checks that the FlowClassifierId class is immutable.
......@@ -61,7 +61,7 @@ public class FlowClassifierIdTest {
@Test
public void testConstruction() {
final String flowClassifierIdValue = "dace4513-24fc-4fae-af4b-321c5e2eb3d1";
final FlowClassifierId flowClassifierId = FlowClassifierId.flowClassifierId(flowClassifierIdValue);
final FlowClassifierId flowClassifierId = FlowClassifierId.of(flowClassifierIdValue);
assertThat(flowClassifierId, is(notNullValue()));
assertThat(flowClassifierId.value(), is(UUID.fromString(flowClassifierIdValue)));
}
......
......@@ -82,11 +82,11 @@ public class FlowClassifierWebResource extends AbstractWebResource {
@Produces(MediaType.APPLICATION_JSON)
public Response getFlowClassifier(@PathParam("flow_id") String id) {
if (!service.hasFlowClassifier(FlowClassifierId.flowClassifierId(UUID.fromString(id)))) {
if (!service.hasFlowClassifier(FlowClassifierId.of(UUID.fromString(id)))) {
return Response.status(NOT_FOUND).entity(FLOW_CLASSIFIER_NOT_FOUND).build();
}
FlowClassifier flowClassifier = nullIsNotFound(
service.getFlowClassifier(FlowClassifierId.flowClassifierId(UUID.fromString(id))),
service.getFlowClassifier(FlowClassifierId.of(UUID.fromString(id))),
FLOW_CLASSIFIER_NOT_FOUND);
ObjectNode result = new ObjectMapper().createObjectNode();
......@@ -182,7 +182,7 @@ public class FlowClassifierWebResource extends AbstractWebResource {
@DELETE
public Response deleteFlowClassifier(@PathParam("flow_id") String id) throws IOException {
try {
FlowClassifierId flowClassifierId = FlowClassifierId.flowClassifierId(UUID.fromString(id));
FlowClassifierId flowClassifierId = FlowClassifierId.of(UUID.fromString(id));
service.removeFlowClassifier(flowClassifierId);
return Response.status(201).entity("SUCCESS").build();
} catch (Exception e) {
......
......@@ -62,7 +62,7 @@ public final class FlowClassifierCodec extends JsonCodec<FlowClassifier> {
String flowClassifierId = nullIsIllegal(json.get(FLOW_CLASSIFIER_ID),
FLOW_CLASSIFIER_ID + MISSING_MEMBER_MESSAGE).asText();
resultBuilder.setFlowClassifierId(FlowClassifierId.flowClassifierId(UUID.fromString(flowClassifierId)));
resultBuilder.setFlowClassifierId(FlowClassifierId.of(UUID.fromString(flowClassifierId)));
String tenantId = nullIsIllegal(json.get(TENANT_ID), TENANT_ID + MISSING_MEMBER_MESSAGE).asText();
resultBuilder.setTenantId(TenantId.tenantId(tenantId));
......@@ -131,4 +131,4 @@ public final class FlowClassifierCodec extends JsonCodec<FlowClassifier> {
.put("DST_PORT", flowClassifier.dstPort().toString());
return result;
}
}
\ No newline at end of file
}
......
......@@ -83,7 +83,7 @@ public final class PortChainCodec extends JsonCodec<PortChain> {
arrayNode = (ArrayNode) json.path(FLOW_CLASSIFIERS);
if (arrayNode != null) {
List<FlowClassifierId> list = Lists.newArrayList();
arrayNode.forEach(i -> list.add(FlowClassifierId.flowClassifierId(UUID.fromString(i.asText()))));
arrayNode.forEach(i -> list.add(FlowClassifierId.of(UUID.fromString(i.asText()))));
resultBuilder.setFlowClassifiers(list);
}
......