Skip to content

Commit

Permalink
#21 remove formbased template distinction
Browse files Browse the repository at this point in the history
  • Loading branch information
michael-conway committed Mar 30, 2017
1 parent fd9c1f5 commit 7df959b
Show file tree
Hide file tree
Showing 11 changed files with 500 additions and 762 deletions.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
*
*
*/
/**
* @author rskarbez
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,22 +21,20 @@
import org.slf4j.LoggerFactory;

public class JargonMetadataExporter extends AbstractMetadataExporter {
static private Logger log = LoggerFactory
.getLogger(IRODSFileFactoryImpl.class);
static private Logger log = LoggerFactory.getLogger(IRODSFileFactoryImpl.class);

public JargonMetadataExporter() {
super();
}

public JargonMetadataExporter(
final IRODSAccessObjectFactory irodsAccessObjectFactory,
public JargonMetadataExporter(final IRODSAccessObjectFactory irodsAccessObjectFactory,
final IRODSAccount irodsAccount) {
super(irodsAccessObjectFactory, irodsAccount);
}

@Override
public void saveTemplateToSystemMetadataOnObject(MetadataTemplate template,
String pathToObject) throws JargonException, FileNotFoundException {
public void saveTemplateToSystemMetadataOnObject(final MetadataTemplate template, final String pathToObject)
throws JargonException, FileNotFoundException {
log.info("saveTemplateToSystemMetadataOnObject()");

if (pathToObject == null || pathToObject.isEmpty()) {
Expand All @@ -47,16 +45,15 @@ public void saveTemplateToSystemMetadataOnObject(MetadataTemplate template,
throw new IllegalArgumentException("metadata template is null");
}

IRODSFile irodsObject = irodsAccessObjectFactory.getIRODSFileFactory(
irodsAccount).instanceIRODSFile(pathToObject);
IRODSFile irodsObject = irodsAccessObjectFactory.getIRODSFileFactory(irodsAccount)
.instanceIRODSFile(pathToObject);

if (!irodsObject.exists()) {
throw new FileNotFoundException(
"pathToObject does not resolve to an iRODS object");
throw new FileNotFoundException("pathToObject does not resolve to an iRODS object");
}
/*
* FileCatalogObjectAO objectAO = null;
*
*
* if (irodsObject.isFile()) { objectAO =
* irodsAccessObjectFactory.getDataObjectAO(irodsAccount); } else if
* (irodsObject.isDirectory()) { objectAO =
Expand All @@ -66,9 +63,8 @@ public void saveTemplateToSystemMetadataOnObject(MetadataTemplate template,
* ); }
*/
if (template.getType() == TemplateTypeEnum.FORM_BASED) {
for (MetadataElement me : ((FormBasedMetadataTemplate) template)
.getElements()) {
this.saveElementToSystemMetadataOnObject(me, pathToObject);
for (MetadataElement me : template.getElements()) {
saveElementToSystemMetadataOnObject(me, pathToObject);
/*
* if (!me.getCurrentValue().isEmpty()) { for (String s :
* me.getCurrentValue()) { AvuData avuData = AvuData .instance(
Expand All @@ -85,8 +81,8 @@ public void saveTemplateToSystemMetadataOnObject(MetadataTemplate template,
}

@Override
public void saveElementToSystemMetadataOnObject(MetadataElement element,
String pathToObject) throws JargonException, FileNotFoundException {
public void saveElementToSystemMetadataOnObject(final MetadataElement element, final String pathToObject)
throws JargonException, FileNotFoundException {
log.info("saveTemplateToSystemMetadataOnObject()");

if (pathToObject == null || pathToObject.isEmpty()) {
Expand All @@ -97,12 +93,11 @@ public void saveElementToSystemMetadataOnObject(MetadataElement element,
throw new IllegalArgumentException("metadata element is null");
}

IRODSFile irodsObject = irodsAccessObjectFactory.getIRODSFileFactory(
irodsAccount).instanceIRODSFile(pathToObject);
IRODSFile irodsObject = irodsAccessObjectFactory.getIRODSFileFactory(irodsAccount)
.instanceIRODSFile(pathToObject);

if (!irodsObject.exists()) {
throw new FileNotFoundException(
"pathToObject does not resolve to an iRODS object");
throw new FileNotFoundException("pathToObject does not resolve to an iRODS object");
}

FileCatalogObjectAO objectAO = null;
Expand All @@ -112,10 +107,8 @@ public void saveElementToSystemMetadataOnObject(MetadataElement element,
} else if (irodsObject.isDirectory()) {
objectAO = irodsAccessObjectFactory.getCollectionAO(irodsAccount);
} else {
throw new IllegalArgumentException(
"object at "
+ pathToObject
+ " is neither a data object nor a collection - the JargonMetadataResolver currently only supports these types of objects");
throw new IllegalArgumentException("object at " + pathToObject
+ " is neither a data object nor a collection - the JargonMetadataResolver currently only supports these types of objects");
}

// // Clear out "stale" metadata before adding new metadata
Expand Down Expand Up @@ -143,7 +136,7 @@ public void saveElementToSystemMetadataOnObject(MetadataElement element,
/*
* ((CollectionAO) objectAO).modifyAVUMetadata(absolutePath,
* currentAvuData, newAvuData);
*
*
* ((CollectionAO)
* objectAO).findMetadataValuesByMetadataQueryForCollection(avuQuery,
* collectionAbsolutePath)
Expand All @@ -155,7 +148,7 @@ public void saveElementToSystemMetadataOnObject(MetadataElement element,
/*
* Check if the object already has an AVU with this attribute name If
* not, add. If so, delete, then add.
*
*
* Need to delete then add to account for list types. (For example,
* replacing a list with a shorter list.)
*/
Expand All @@ -164,23 +157,18 @@ public void saveElementToSystemMetadataOnObject(MetadataElement element,
List<MetaDataAndDomainData> queryResult = null;

try {
queryElements.add(AVUQueryElement.instanceForValueQuery(
AVUQueryElement.AVUQueryPart.ATTRIBUTE,
queryElements.add(AVUQueryElement.instanceForValueQuery(AVUQueryElement.AVUQueryPart.ATTRIBUTE,
QueryConditionOperators.EQUAL, element.getName()));

if (irodsObject.isFile()) {
queryResult = ((DataObjectAO) objectAO)
.findMetadataValuesForDataObjectUsingAVUQuery(
queryElements, pathToObject);
queryResult = ((DataObjectAO) objectAO).findMetadataValuesForDataObjectUsingAVUQuery(queryElements,
pathToObject);
} else if (irodsObject.isDirectory()) {
queryResult = ((CollectionAO) objectAO)
.findMetadataValuesByMetadataQueryForCollection(
queryElements, pathToObject);
queryResult = ((CollectionAO) objectAO).findMetadataValuesByMetadataQueryForCollection(queryElements,
pathToObject);
}
} catch (JargonQueryException e) {
log.error(
"Jargon query exception looking up AVUs on iRODS object:{}",
pathToObject, e);
log.error("Jargon query exception looking up AVUs on iRODS object:{}", pathToObject, e);
throw new JargonException(e);
}

Expand All @@ -189,18 +177,15 @@ public void saveElementToSystemMetadataOnObject(MetadataElement element,
if (!queryResult.isEmpty()) {
List<AvuData> oldAvuData = new ArrayList<AvuData>();
for (MetaDataAndDomainData mdd : queryResult) {
AvuData avuData = AvuData.instance(mdd.getAvuAttribute(),
mdd.getAvuValue(), mdd.getAvuUnit());
AvuData avuData = AvuData.instance(mdd.getAvuAttribute(), mdd.getAvuValue(), mdd.getAvuUnit());
oldAvuData.add(avuData);
}

// Delete AVUs
if (irodsObject.isFile()) {
((DataObjectAO) objectAO).deleteBulkAVUMetadataFromDataObject(
pathToObject, oldAvuData);
((DataObjectAO) objectAO).deleteBulkAVUMetadataFromDataObject(pathToObject, oldAvuData);
} else if (irodsObject.isDirectory()) {
((CollectionAO) objectAO).deleteBulkAVUMetadataFromCollection(
pathToObject, oldAvuData);
((CollectionAO) objectAO).deleteBulkAVUMetadataFromCollection(pathToObject, oldAvuData);
}
}

Expand All @@ -209,14 +194,11 @@ public void saveElementToSystemMetadataOnObject(MetadataElement element,
if (!element.getCurrentValue().isEmpty()) {
for (String s : element.getCurrentValue()) {
AvuData avuData = AvuData.instance(element.getName(), s,
JargonMetadataTemplateConstants.AVU_UNIT_PREFIX
+ element.getTemplateUuid().toString());
JargonMetadataTemplateConstants.AVU_UNIT_PREFIX + element.getTemplateUuid().toString());
if (irodsObject.isFile()) {
((DataObjectAO) objectAO).addAVUMetadata(pathToObject,
avuData);
((DataObjectAO) objectAO).addAVUMetadata(pathToObject, avuData);
} else if (irodsObject.isDirectory()) {
((CollectionAO) objectAO).addAVUMetadata(pathToObject,
avuData);
((CollectionAO) objectAO).addAVUMetadata(pathToObject, avuData);
}
}
}
Expand Down
Loading

0 comments on commit 7df959b

Please sign in to comment.