is canceled.
@throws PhotoNotFoundException if the original image cound not be located
*/
public void save() throws PhotoNotFoundException, PhotovaultException {
// Get a transaction context (whole saving operation should be done in a single transaction)
ODMGXAWrapper txw = new ODMGXAWrapper();
try {
// Check if we already have a PhotoInfo object to control
if ( isCreatingNew ) {
photos = new PhotoInfo[1];
if ( originalFile != null ) {
photos[0] = PhotoInfo.addToDB( originalFile );
} else {
photos[0] = PhotoInfo.create();
}
// Set the model to all fields but preserve field state so that it is changed to the photoInfo
// object
changeModelInFields( true );
isCreatingNew = false;
}
// Inform all fields that the modifications should be saved to model
Iterator fieldIter = modelFields.values().iterator();
while ( fieldIter.hasNext() ) {
FieldController fieldCtrl = (FieldController) fieldIter.next();
fieldCtrl.save();
}
// Update the raw settings if any field affecting them has been changed
if ( isRawSettingsChanged ) {
Iterator rawIter = rawFactories.entrySet().iterator();
while ( rawIter.hasNext() ) {
Map.Entry e = (Map.Entry) rawIter.next();
PhotoInfo p = (PhotoInfo) e.getKey();
RawSettingsFactory f = (RawSettingsFactory) e.getValue();
RawConversionSettings r = null;
try {
r = f.create();
} catch (PhotovaultException ex) {
ex.printStackTrace();
}
p.setRawSettings( r );
}
}
// Update the color mapping if any field affecting them has been changed
if ( isColorMappingChanged ) {
Iterator colorIter = colorMappingFactories.entrySet().iterator();
while ( colorIter.hasNext() ) {
Map.Entry e = (Map.Entry) colorIter.next();
PhotoInfo p = (PhotoInfo) e.getKey();
ChannelMapOperationFactory f = (ChannelMapOperationFactory) e.getValue();
ChannelMapOperation o = null;
o = f.create();
p.setColorChannelMapping( o );
}
}
} catch ( LockNotGrantedException e ) {
txw.abort();
throw new PhotovaultException( "Photo locked for other use", e );
}
txw.commit();
}