*/
@Override
public void save(ProductAttribute productAttribute) throws ServiceException {
if (productAttribute.getId() != null
|| exists(productAttribute.getCode()))
throw new ServiceException(
productAttribute.getCode()
+ " exists already. Not allowed to update product attributes yet");
Integer id = null;
try {
id = Integer.parseInt((String) soapClient.call(
ResourcePath.ProductAttributeCreate,
productAttribute.serializeToApi()));
} catch (AxisFault e) {
if (debug)
e.printStackTrace();
throw new ServiceException(e.getMessage());
}
if (id == null)
throw new ServiceException("Error on save product attribute");
productAttribute.setId(id);
// if has options, include this too
if (productAttribute.getOptions() != null) {
if (!productAttribute.getOptions().isEmpty()) {
String[] options = new String[productAttribute.getOptions()
.size()];
int i = 0;
for (Map.Entry<Integer, String> option : productAttribute
.getOptions().entrySet())
options[i++] = option.getValue();
List<Object> params = new LinkedList<Object>();
params.add(productAttribute.getId());
params.add(options);
try {
if (!(Boolean) soapClient.call(
ResourcePath.ProductAttributeAddOptions, params))
throw new ServiceException(
"The product attribute was saved, but had error "
+ "on save the options for that");
} catch (AxisFault e) {
if (debug)
e.printStackTrace();
throw new ServiceException(e.getMessage());
}
}
}
}