package org.opendaylight.transportpce.pce.gnpy;
import com.google.common.base.Function;
+//false positive in SpotBug -> cannot be used with FluentIterable...
import com.google.common.collect.FluentIterable;
import java.io.BufferedWriter;
import org.opendaylight.transportpce.common.converter.XMLDataObjectConverter;
import org.opendaylight.transportpce.common.network.NetworkTransactionService;
import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.org.openroadm.device.container.OrgOpenroadmDevice;
-import org.opendaylight.yangtools.yang.binding.BindingStreamEventWriter;
import org.opendaylight.yangtools.yang.binding.DataObject;
import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
import org.opendaylight.yangtools.yang.binding.InstanceIdentifier.PathArgument;
public ServiceDataStoreOperationsImpl(NetworkTransactionService networkTransactionService) {
}
- public void createXMLFromDevice(DataStoreContext dataStoreContextUtil, OrgOpenroadmDevice device, String output) {
+ public void createXMLFromDevice(DataStoreContext dataStoreContextUtil, OrgOpenroadmDevice device, String output)
+ throws GnpyException {
+
if (device != null) {
Optional<NormalizedNode<?, ?>> transformIntoNormalizedNode = null;
XMLDataObjectConverter cwDsU = XMLDataObjectConverter.createWithDataStoreUtil(dataStoreContextUtil);
transformIntoNormalizedNode = cwDsU.toNormalizedNodes(device, OrgOpenroadmDevice.class);
if (!transformIntoNormalizedNode.isPresent()) {
- throw new IllegalStateException(
- String.format("Could not transform the input %s into normalized nodes", device));
+ throw new GnpyException(String.format(
+ "In ServiceDataStoreOperationsImpl: Cannot transform the device %s into normalized nodes",
+ device.toString()));
}
Writer writerFromDataObject =
cwDsU.writerFromDataObject(device, OrgOpenroadmDevice.class,cwDsU.dataContainer());
writer.write(writerFromDataObject.toString());
writer.close();
} catch (IOException e) {
- LOG.error("Bufferwriter error ");
+ throw new GnpyException(
+ String.format("In ServiceDataStoreOperationsImpl : Bufferwriter error"),e);
}
LOG.debug("GNPy: device xml : {}", writerFromDataObject.toString());
}
}
- public String createJsonStringFromDataObject(final InstanceIdentifier<?> id, DataObject object) throws Exception {
+ public String createJsonStringFromDataObject(final InstanceIdentifier<?> id, DataObject object)
+ throws GnpyException, Exception {
final SchemaPath scPath = SchemaPath
.create(FluentIterable.from(id.getPathArguments()).transform(new Function<PathArgument, QName>() {
scPath.getParent(), scPath.getLastComponent().getNamespace(),
JsonWriterFactory.createJsonWriter(writer, 2));
// The write part
- final BindingStreamEventWriter bindingWriter = codecRegistry.newWriter(id, domWriter);
- codecRegistry.getSerializer(id.getTargetType()).serialize(object, bindingWriter);
+ codecRegistry.getSerializer(id.getTargetType()).serialize(object, codecRegistry.newWriter(id, domWriter));
domWriter.close();
writer.close();
- } catch (IOException e) {
- LOG.error("GNPy: writer error ");
- } catch (YangSyntaxErrorException e) {
- LOG.warn("GNPy: exception {} occured during json file creation", e.getMessage(), e);
- } catch (ReactorException e) {
- LOG.warn("GNPy: exception {} occured during json file creation", e.getMessage(), e);
+ } catch (IOException | YangSyntaxErrorException | ReactorException e) {
+ throw new GnpyException("In ServiceDataStoreOperationsImpl: exception during json file creation",e);
}
return writer.toString();
}
// Write the json as a string in a file
- public void writeStringFile(String jsonString, String fileName) {
+ public void writeStringFile(String jsonString, String fileName) throws GnpyException {
try {
FileWriter file = new FileWriter(fileName);
file.write(jsonString);
file.close();
} catch (IOException e) {
- LOG.error("GNPy: writer error ");
+ throw new GnpyException("In ServiceDataStoreOperationsImpl : exception during file writing",e);
}
}
}