Skip to content

Commit

Permalink
[#420] Add functions for manipulating AVUs as a rodsadmin.
Browse files Browse the repository at this point in the history
  • Loading branch information
korydraughn committed Aug 9, 2024
1 parent 10e8329 commit ecbd30b
Show file tree
Hide file tree
Showing 7 changed files with 777 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ public class ModAvuMetadataInp extends AbstractIRODSPackingInstruction {
public static final String ARG_PREFIX = "arg";

public static final int MOD_AVU_API_NBR = 706;

public static final String ADMIN_KW = "irodsAdmin";

/**
* Type of metadata to be modified
Expand All @@ -42,6 +44,27 @@ public enum ActionType {
private final AvuData avuData;
private final AvuData newAvuData;
private final ActionType actionType;
private boolean adminFlag;

/**
* Create an instance of the packing instruction.
*
* Supports all use-cases.
*
* @param targetIdentifier The absolute logical path to the entity.
* @param metadataTargetType The entity type.
* @param avuData An AVU. Depends on the operation.
* @param newAvuData An AVU. Depends on the operation. Set to null if
* unused.
* @param actionType The AVU operation.
* @param adminFlag Execute operation using rodsadmin privileges.
* @return {@link ModAvuMetadataInp}
*/
public static final ModAvuMetadataInp instance(final String targetIdentifier,
final MetadataTargetType metadataTargetType, final AvuData avuData, final AvuData newAvuData,
final ActionType actionType, boolean adminFlag) {
return new ModAvuMetadataInp(targetIdentifier, metadataTargetType, avuData, newAvuData, actionType, adminFlag);
}

/**
* Create an instance of the packing instruction that will add the AVU to a
Expand Down Expand Up @@ -335,6 +358,11 @@ public static final ModAvuMetadataInp instanceForDeleteUserMetadata(final String

private ModAvuMetadataInp(final String targetIdentifier, final MetadataTargetType metadataTargetType,
final AvuData avuData, final AvuData newAvuData, final ActionType actionType) {
this(targetIdentifier, metadataTargetType, avuData, newAvuData, actionType, false);
}

private ModAvuMetadataInp(final String targetIdentifier, final MetadataTargetType metadataTargetType,
final AvuData avuData, final AvuData newAvuData, final ActionType actionType, final boolean adminFlag) {
super();

if (targetIdentifier == null || targetIdentifier.isEmpty()) {
Expand All @@ -358,6 +386,7 @@ private ModAvuMetadataInp(final String targetIdentifier, final MetadataTargetTyp
this.avuData = avuData;
this.actionType = actionType;
this.newAvuData = newAvuData;
this.adminFlag = adminFlag;

setApiNumber(MOD_AVU_API_NBR);

Expand Down Expand Up @@ -433,6 +462,11 @@ public Tag getTagValue() throws JargonException {
}

List<KeyValuePair> kvps = new ArrayList<KeyValuePair>();

if (adminFlag) {
kvps.add(KeyValuePair.instance(ADMIN_KW, ""));
}

message.addTag(super.createKeyValueTag(kvps));

// take the arg list and compact the params
Expand Down Expand Up @@ -460,5 +494,9 @@ public ActionType getActionType() {
public AvuData getNewAvuData() {
return newAvuData;
}

public boolean isAdminFlagEnabled() {
return adminFlag;
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -892,4 +892,48 @@ void setAccessPermissionToNotInheritInAdminMode(String zone, String absolutePath
*/
void setAccessPermissionInheritAsAdmin(String zone, String absolutePath, boolean recursive) throws JargonException;

/**
* Add an AVU to a collection.
*
* @param absolutePath The absolute path to a collection.
* @param avuData The AVU to add.
* @param adminFlag Execute operation using rodsadmin privileges.
* @throws JargonException If an error occurs.
*/
void addAVUMetadata(String absolutePath, AvuData avuData, boolean adminFlag) throws JargonException;

/**
* Removes an AVU from a collection.
*
* @param absolutePath The absolute path to a collection.
* @param avuData The AVU to remove.
* @param adminFlag Execute operation using rodsadmin privileges.
* @throws JargonException If an error occurs.
*/
void deleteAVUMetadata(String absolutePath, AvuData avuData, boolean adminFlag) throws JargonException;

/**
* Sets an AVU on a collection.
*
* All AVUs having an attribute name matching the new AVU will be removed from
* the collection.
*
* @param absolutePath The absolute path to a collection.
* @param avuData The AVU to set.
* @param adminFlag Execute operation using rodsadmin privileges.
* @throws JargonException If an error occurs.
*/
void setAVUMetadata(String absolutePath, AvuData avuData, boolean adminFlag) throws JargonException;

/**
* Modifies an existing AVU on a collection.
*
* @param absolutePath The absolute path to a collection.
* @param avuData The AVU to modify.
* @param newAvuData The AVU that will replace the target AVU.
* @param adminFlag Execute operation using rodsadmin privileges.
* @throws JargonException If an error occurs.
*/
void modifyAVUMetadata(String absolutePath, AvuData avuData, AvuData newAvuData, boolean adminFlag)
throws JargonException;
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
import org.irods.jargon.core.exception.OperationNotSupportedByThisServerException;
import org.irods.jargon.core.packinstr.ModAccessControlInp;
import org.irods.jargon.core.packinstr.ModAvuMetadataInp;
import org.irods.jargon.core.packinstr.ModAvuMetadataInp.ActionType;
import org.irods.jargon.core.packinstr.ModAvuMetadataInp.MetadataTargetType;
import org.irods.jargon.core.protovalues.FilePermissionEnum;
import org.irods.jargon.core.protovalues.UserTypeEnum;
import org.irods.jargon.core.pub.BulkAVUOperationResponse.ResultStatus;
Expand Down Expand Up @@ -70,6 +72,7 @@ public final class CollectionAOImpl extends FileCatalogObjectAOImpl implements C

public static final String SHOW_COLL_ACLS = "ShowCollAcls";
public static final String ERROR_IN_COLECTION_QUERY = "An error occurred in the query for the collection";
private static final String NULL_OR_EMPTY_ABSOLUTE_PATH = "null or empty absolutePath";
private final IRODSFileFactory irodsFileFactory = new IRODSFileFactoryImpl(getIRODSSession(), getIRODSAccount());
private final IRODSGenQueryExecutor irodsGenQueryExecutor = new IRODSGenQueryExecutorImpl(getIRODSSession(),
getIRODSAccount());
Expand Down Expand Up @@ -2104,4 +2107,172 @@ public void replicateCollectionAsynchronously(final String irodsCollectionAbsolu

}

@Override
public void addAVUMetadata(final String absolutePath, final AvuData avuData, final boolean adminFlag)
throws DataNotFoundException, DuplicateDataException, JargonException {
log.info("addAVUMetadata()");

if (null == absolutePath || absolutePath.isEmpty()) {
throw new IllegalArgumentException(NULL_OR_EMPTY_ABSOLUTE_PATH);
}

if (null == avuData) {
throw new IllegalArgumentException("null AVU data");
}

String myPath = MiscIRODSUtils.normalizeIrodsPath(absolutePath);

log.info("adding avu metadata to collection");
log.info("absolute path: {}", myPath);
log.info("avu: {}", avuData);
log.info("adminFlag: {}", adminFlag);

final ModAvuMetadataInp modifyAvuMetadataInp = ModAvuMetadataInp.instance(myPath,
MetadataTargetType.COLLECTION, avuData, null, ActionType.ADD, adminFlag);

log.debug("sending avu request");

try {
getIRODSProtocol().irodsFunction(modifyAvuMetadataInp);
} catch (JargonException je) {
if (je.getMessage().indexOf("-814000") > -1) {
throw new DataNotFoundException("Target collection was not found, could not add AVU");
} else if (je.getMessage().indexOf("-809000") > -1) {
throw new DuplicateDataException("Duplicate AVU exists, cannot add");
}

log.error("jargon exception adding AVU metadata", je);
throw je;
}

log.debug("metadata added");
}

@Override
public void deleteAVUMetadata(final String absolutePath, final AvuData avuData, final boolean adminFlag)
throws DataNotFoundException, JargonException {
log.info("deleteAVUMetadata()");

if (null == absolutePath || absolutePath.isEmpty()) {
throw new IllegalArgumentException(NULL_OR_EMPTY_ABSOLUTE_PATH);
}

if (null == avuData) {
throw new IllegalArgumentException("null AVU data");
}

String myPath = MiscIRODSUtils.normalizeIrodsPath(absolutePath);

log.info("deleting avu metadata on dataObject");
log.info("absolute path: {}", myPath);
log.info("avu: {}", avuData);
log.info("adminFlag: {}", adminFlag);

final ModAvuMetadataInp modifyAvuMetadataInp = ModAvuMetadataInp.instance(myPath,
MetadataTargetType.COLLECTION, avuData, null, ActionType.REMOVE, adminFlag);

log.debug("sending avu request");

try {
getIRODSProtocol().irodsFunction(modifyAvuMetadataInp);
} catch (JargonException je) {
if (je.getMessage().indexOf("-814000") > -1) {
throw new DataNotFoundException("Target collection was not found, could not remove AVU");
}

log.error("jargon exception removing AVU metadata", je);
throw je;
}

log.debug("metadata removed");
}

@Override
public void setAVUMetadata(final String absolutePath, final AvuData avuData, final boolean adminFlag)
throws DataNotFoundException, JargonException {
log.info("setAVUMetadata()");

if (null == absolutePath || absolutePath.isEmpty()) {
throw new IllegalArgumentException(NULL_OR_EMPTY_ABSOLUTE_PATH);
}

if (null == avuData) {
throw new IllegalArgumentException("null AVU data");
}

if (!getIRODSServerProperties().isSupportsMetadataSet()) {
log.error("irods version does not support set avu");
throw new OperationNotSupportedByThisServerException("set avu not available on this iRODS version");
}

String myPath = MiscIRODSUtils.normalizeIrodsPath(absolutePath);

log.info("setting avu metadata on collection");
log.info("absolute path: {}", myPath);
log.info("avu: {}", avuData);
log.info("adminFlag: {}", adminFlag);

final ModAvuMetadataInp modifyAvuMetadataInp = ModAvuMetadataInp.instance(myPath,
MetadataTargetType.COLLECTION, avuData, null, ActionType.SET, adminFlag);

log.debug("sending avu request");

try {
getIRODSProtocol().irodsFunction(modifyAvuMetadataInp);
} catch (JargonException je) {
if (je.getMessage().indexOf("-814000") > -1) {
throw new DataNotFoundException("Target collection was not found, could not add AVU");
}

log.error("jargon exception setting AVU metadata", je);
throw je;
}

log.debug("metadata set");
}

@Override
public void modifyAVUMetadata(final String absolutePath, final AvuData avuData, final AvuData newAvuData,
final boolean adminFlag) throws DataNotFoundException, JargonException {
log.info("modifyAVUMetadata()");

if (null == absolutePath || absolutePath.isEmpty()) {
throw new IllegalArgumentException(NULL_OR_EMPTY_ABSOLUTE_PATH);
}

if (null == avuData) {
throw new IllegalArgumentException("target AVU data is null");
}

if (null == newAvuData) {
throw new IllegalArgumentException("new AVU data is null");
}

String myPath = MiscIRODSUtils.normalizeIrodsPath(absolutePath);

log.info("modifying avu metadata on collection");
log.info("absolute path: {}", myPath);
log.info("target avu: {}", avuData);
log.info("new avu: {}", newAvuData);
log.info("adminFlag: {}", adminFlag);

final ModAvuMetadataInp modifyAvuMetadataInp = ModAvuMetadataInp.instance(myPath,
MetadataTargetType.COLLECTION, avuData, newAvuData, ActionType.MOD, adminFlag);

log.debug("sending avu request");

try {
getIRODSProtocol().irodsFunction(modifyAvuMetadataInp);
} catch (JargonException je) {
if (je.getMessage().indexOf("-814000") > -1) {
throw new DataNotFoundException("Target collection was not found, could not modify AVU");
}

log.error("jargon exception modifying AVU metadata", je);
throw je;
}

log.debug("metadata modified");
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -1144,4 +1144,49 @@ String truncateReplicaByReplicaNumber(final String logicalPath, final int replic
String truncateReplicaByResource(final String logicalPath, final String resource, final long newDataSize)
throws JargonException;

/**
* Add an AVU to a data object.
*
* @param absolutePath The absolute path to a data object.
* @param avuData The AVU to add.
* @param adminFlag Execute operation using rodsadmin privileges.
* @throws JargonException If an error occurs.
*/
void addAVUMetadata(String absolutePath, AvuData avuData, boolean adminFlag) throws JargonException;

/**
* Removes an AVU from a data object.
*
* @param absolutePath The absolute path to a data object.
* @param avuData The AVU to remove.
* @param adminFlag Execute operation using rodsadmin privileges.
* @throws JargonException If an error occurs.
*/
void deleteAVUMetadata(String absolutePath, AvuData avuData, boolean adminFlag) throws JargonException;

/**
* Sets an AVU on a data object.
*
* All AVUs having an attribute name matching the new AVU will be removed from
* the data object.
*
* @param absolutePath The absolute path to a data object.
* @param avuData The AVU to set.
* @param adminFlag Execute operation using rodsadmin privileges.
* @throws JargonException If an error occurs.
*/
void setAVUMetadata(String absolutePath, AvuData avuData, boolean adminFlag) throws JargonException;

/**
* Modifies an existing AVU on a data object.
*
* @param absolutePath The absolute path to a data object.
* @param avuData The AVU to modify.
* @param newAvuData The AVU that will replace the target AVU.
* @param adminFlag Execute operation using rodsadmin privileges.
* @throws JargonException If an error occurs.
*/
void modifyAVUMetadata(String absolutePath, AvuData avuData, AvuData newAvuData, boolean adminFlag)
throws JargonException;

}
Loading

0 comments on commit ecbd30b

Please sign in to comment.