Fix checkstyle warnings for services package
[openflowplugin.git] / openflowplugin-impl / src / main / java / org / opendaylight / openflowplugin / impl / services / singlelayer / SingleLayerFlowService.java
1 /*
2  * Copyright (c) 2017 Pantheon Technologies s.r.o. and others.  All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8
9 package org.opendaylight.openflowplugin.impl.services.singlelayer;
10
11 import org.opendaylight.openflowplugin.api.openflow.device.DeviceContext;
12 import org.opendaylight.openflowplugin.api.openflow.device.RequestContextStack;
13 import org.opendaylight.openflowplugin.api.openflow.device.Xid;
14 import org.opendaylight.openflowplugin.impl.services.AbstractSilentErrorService;
15 import org.opendaylight.openflowplugin.impl.services.util.ServiceException;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.AddFlowInput;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.RemoveFlowInput;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.flow.update.OriginalFlow;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.flow.update.UpdatedFlow;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.Flow;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.FlowMessageBuilder;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.FlowModCommand;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.OfHeader;
24 import org.opendaylight.yangtools.yang.binding.DataContainer;
25 import org.opendaylight.yangtools.yang.binding.DataObject;
26
27 public final class SingleLayerFlowService<O extends DataObject> extends AbstractSilentErrorService<Flow, O> {
28     public SingleLayerFlowService(final RequestContextStack requestContextStack,
29                                   final DeviceContext deviceContext,
30                                   final Class<O> clazz) {
31         super(requestContextStack, deviceContext, clazz);
32     }
33
34     @Override
35     protected OfHeader buildRequest(final Xid xid, final Flow input) throws ServiceException {
36         final FlowMessageBuilder flowMessageBuilder = new FlowMessageBuilder(input);
37         final Class<? extends DataContainer> clazz = input.getImplementedInterface();
38
39         if (clazz.equals(AddFlowInput.class)
40                 || clazz.equals(UpdatedFlow.class)) {
41             flowMessageBuilder.setCommand(FlowModCommand.OFPFCADD);
42         } else if (clazz.equals(RemoveFlowInput.class)
43                 || clazz.equals(OriginalFlow.class)) {
44             flowMessageBuilder.setCommand(Boolean.TRUE.equals(input.isStrict())
45                     ? FlowModCommand.OFPFCDELETESTRICT
46                     : FlowModCommand.OFPFCDELETE);
47         }
48
49         return flowMessageBuilder
50                 .setVersion(getVersion())
51                 .setXid(xid.getValue())
52                 .build();
53     }
54 }