Created
May 2, 2016 11:02
-
-
Save krisfoster/09e04d727a9af809592103b1b6781dc8 to your computer and use it in GitHub Desktop.
Asset API Update code
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private final void migrateAsset(final Long imageID, Set<String> cats) | |
throws AssetNotExistException, AssetAccessException { | |
// Used to indicate whether or not we needed to udpate the asset | |
boolean updated = false; | |
// | |
Iterable<AssetData> assets = getAssetData(this._adm, "Image_C", imageID); | |
// | |
List<AssetData> sAssets = new ArrayList<AssetData>(); | |
for ( AssetData a : assets ) { | |
// | |
sAssets.add( a ); | |
// Has the asset already been migrated? | |
final AttributeData flexType = a.getAttributeData(FLEX_TEMPL_ATTR); | |
final AssetId flexTemplType = (AssetId)flexType.getData(); | |
final Long flexTemplTypeL = this.parseOutImageID(flexTemplType.toString()); | |
LOG.info(LOG_PREFIX + "Flex tenplate ID:: " + flexTemplTypeL.toString()); | |
if (this._flexTemplateID.toString().equals(flexTemplTypeL.toString())) { | |
// Has been migrated, so check whether we need to update the ATG categories | |
//final String | |
updated = true; | |
LOG.info(LOG_PREFIX + "Asset has been migrated:: " + imageID.toString()); | |
// Update the flextemplate | |
flexType.setData(new AssetIdImpl("Image_C", this._flexTemplateID.longValue())); | |
// Add the categories to the attribute | |
final AttributeData catAttr = a.getAttributeData(ATG_CAT_ATTR); | |
List<String> mergedCats = mergeCategories(catAttr, cats); | |
// TODO - remove the following debug code | |
StringBuffer b = new StringBuffer(); | |
for (Iterator<String> i = mergedCats.iterator(); i.hasNext();) { | |
String v = i.next(); | |
b.append(v); | |
b.append(","); | |
} | |
LOG.info(LOG_PREFIX + "Merged Attrs:: " + b.toString()); | |
// Update the data on the attribute | |
catAttr.setData(mergedCats); | |
LOG.info(LOG_PREFIX + "Set merged categories on attribute"); | |
} else { | |
// Has *NOT* been updated so migrate the asset | |
LOG.info(LOG_PREFIX + "Asset has **NOT** been migrated:: " + imageID.toString()); | |
updated = true; | |
flexType.setData(new AssetIdImpl("Image_C", this._flexTemplateID.longValue())); | |
} | |
// | |
} | |
// Update the asset to the DB only if we needed to change it | |
if (updated) { | |
// | |
this._adm.update( sAssets ); | |
LOG.info(LOG_PREFIX + "Migrated Image Asset:: " + imageID.toString()); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment