org.xlcloud.service.heat.parsers.resources.quantum.properties.NetworkPropertiesParser Maven / Gradle / Ivy
/*
* Copyright 2012 AMG.lab, a Bull Group Company
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.xlcloud.service.heat.parsers.resources.quantum.properties;
import static org.xlcloud.service.heat.template.quantum.fields.RouterFields.ADMIN_STATE_UP;
import static org.xlcloud.service.heat.template.quantum.fields.RouterFields.NAME;
import static org.xlcloud.service.heat.template.quantum.fields.RouterFields.VALUE_SPECS;
import org.apache.commons.lang.StringUtils;
import org.json.JSONException;
import org.xlcloud.service.heat.parsers.resources.properties.PropertiesParser;
import org.xlcloud.service.heat.parsers.utils.JsonObjectWrapper;
import org.xlcloud.service.heat.template.resources.quantum.Network;
/**
* Implementation of {@link PropertiesParser} for {@link Network} resource
* @author Konrad Król, AMG.net
*/
public class NetworkPropertiesParser implements PropertiesParser {
/** {@inheritDoc} */
@Override
public void appendPropertiesToPojo(Network pojo, JsonObjectWrapper propsWrapper) throws JSONException {
pojo.setAdminStateUp(propsWrapper.optBooleanNull(ADMIN_STATE_UP));
pojo.setNetworkName(propsWrapper.optStringNull(NAME));
pojo.setValueSpecs(propsWrapper.optStringNull(VALUE_SPECS));
}
/** {@inheritDoc} */
@Override
public void appendPropertiesToJSON(JsonObjectWrapper propsWrapper, Network pojo) throws JSONException {
propsWrapper.putOpt(ADMIN_STATE_UP, pojo.getAdminStateUp());
propsWrapper.putOpt(NAME, pojo.getNetworkName());
if(StringUtils.isNotBlank(pojo.getValueSpecs())) {
propsWrapper.putValue(VALUE_SPECS, pojo.getValueSpecs());
}
}
}