Skip to content

Commit

Permalink
Fix identifer typo in code
Browse files Browse the repository at this point in the history
Just in case code outside this project is referencing the old methods,
I created deprecated versions.
  • Loading branch information
bencomp committed Oct 18, 2023
1 parent 3c98c7d commit d76e494
Show file tree
Hide file tree
Showing 12 changed files with 85 additions and 40 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -495,10 +495,24 @@ private DatasetVersion getDatasetVersionByQuery(String queryString){
}
} // end getDatasetVersionByQuery




public DatasetVersion retrieveDatasetVersionByIdentiferClause(String identifierClause, String version){
/**
* @deprecated because of a typo; use {@link #retrieveDatasetVersionByIdentifierClause(String, String) retrieveDatasetVersionByIdentifierClause} instead
* @see #retrieveDatasetVersionByIdentifierClause(String, String)
* @param identifierClause
* @param version
* @return a DatasetVersion if found, or {@code null} otherwise
*/
@Deprecated
public DatasetVersion retrieveDatasetVersionByIdentiferClause(String identifierClause, String version) {
return retrieveDatasetVersionByIdentifierClause(identifierClause, version);
}

/**
* @param identifierClause
* @param version
* @return a DatasetVersion if found, or {@code null} otherwise
*/
public DatasetVersion retrieveDatasetVersionByIdentifierClause(String identifierClause, String version) {

if (identifierClause == null){
return null;
Expand Down Expand Up @@ -620,7 +634,7 @@ public RetrieveDatasetVersionResponse retrieveDatasetVersionByPersistentId(Strin
identifierClause += " AND ds.identifier = '" + parsedId.getIdentifier() + "'";


DatasetVersion ds = retrieveDatasetVersionByIdentiferClause(identifierClause, version);
DatasetVersion ds = retrieveDatasetVersionByIdentifierClause(identifierClause, version);

if (ds != null){
msg("retrieved dataset: " + ds.getId() + " semantic: " + ds.getSemanticVersion());
Expand Down Expand Up @@ -718,7 +732,7 @@ public DatasetVersion getDatasetVersionById(Long datasetId, String version){

String identifierClause = this.getIdClause(datasetId);

DatasetVersion ds = retrieveDatasetVersionByIdentiferClause(identifierClause, version);
DatasetVersion ds = retrieveDatasetVersionByIdentifierClause(identifierClause, version);

return ds;

Expand Down
11 changes: 6 additions & 5 deletions src/main/java/edu/harvard/iq/dataverse/Shib.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import java.util.Arrays;
import java.util.Date;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import jakarta.ejb.EJB;
import jakarta.ejb.EJBException;
Expand Down Expand Up @@ -62,7 +63,7 @@ public class Shib implements java.io.Serializable {
HttpServletRequest request;

private String userPersistentId;
private String internalUserIdentifer;
private String internalUserIdentifier;
AuthenticatedUserDisplayInfo displayInfo;
/**
* @todo Remove this boolean some day? Now the mockups show a popup. Should
Expand Down Expand Up @@ -210,8 +211,8 @@ public void init() {
}

String usernameAssertion = getValueFromAssertion(ShibUtil.usernameAttribute);
internalUserIdentifer = ShibUtil.generateFriendlyLookingUserIdentifer(usernameAssertion, emailAddress);
logger.fine("friendly looking identifer (backend will enforce uniqueness):" + internalUserIdentifer);
internalUserIdentifier = ShibUtil.generateFriendlyLookingUserIdentifier(usernameAssertion, emailAddress);
logger.log(Level.FINE, "friendly looking identifier (backend will enforce uniqueness): {0}", internalUserIdentifier);

String shibAffiliationAttribute = settingsService.getValueForKey(SettingsServiceBean.Key.ShibAffiliationAttribute);
String affiliation = (StringUtils.isNotBlank(shibAffiliationAttribute))
Expand Down Expand Up @@ -326,7 +327,7 @@ public String confirmAndCreateAccount() {
AuthenticatedUser au = null;
try {
au = authSvc.createAuthenticatedUser(
new UserRecordIdentifier(shibAuthProvider.getId(), lookupStringPerAuthProvider), internalUserIdentifer, displayInfo, true);
new UserRecordIdentifier(shibAuthProvider.getId(), lookupStringPerAuthProvider), internalUserIdentifier, displayInfo, true);
} catch (EJBException ex) {
/**
* @todo Show the ConstraintViolationException, if any.
Expand Down Expand Up @@ -354,7 +355,7 @@ public String confirmAndConvertAccount() {
visibleTermsOfUse = false;
ShibAuthenticationProvider shibAuthProvider = new ShibAuthenticationProvider();
String lookupStringPerAuthProvider = userPersistentId;
UserIdentifier userIdentifier = new UserIdentifier(lookupStringPerAuthProvider, internalUserIdentifer);
UserIdentifier userIdentifier = new UserIdentifier(lookupStringPerAuthProvider, internalUserIdentifier);
logger.fine("builtin username: " + builtinUsername);
AuthenticatedUser builtInUserToConvert = authSvc.canLogInAsBuiltinUser(builtinUsername, builtinPassword);
if (builtInUserToConvert != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ public Feed listCollectionContents(IRI iri, AuthCredentials authCredentials, Swo
throw new SwordError(UriRegistry.ERROR_BAD_REQUEST, "Could not find dataverse: " + dvAlias);
}
} else {
throw new SwordError(UriRegistry.ERROR_BAD_REQUEST, "Couldn't determine target type or identifer from URL: " + iri);
throw new SwordError(UriRegistry.ERROR_BAD_REQUEST, "Couldn't determine target type or identifier from URL: " + iri);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ public void deleteMediaResource(String uri, AuthCredentials authCredentials, Swo
throw new SwordError(UriRegistry.ERROR_BAD_REQUEST, "Unsupported file type found in URL: " + uri);
}
} else {
throw new SwordError(UriRegistry.ERROR_BAD_REQUEST, "Target or identifer not specified in URL: " + uri);
throw new SwordError(UriRegistry.ERROR_BAD_REQUEST, "Target or identifier not specified in URL: " + uri);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -580,7 +580,7 @@ public boolean updateProvider( AuthenticatedUser authenticatedUser, String authe
* {@code userDisplayInfo}, a lookup entry for them based
* UserIdentifier.getLookupStringPerAuthProvider (within the supplied
* authentication provider), and internal user identifier (used for role
* assignments, etc.) based on UserIdentifier.getInternalUserIdentifer.
* assignments, etc.) based on UserIdentifier.getInternalUserIdentifier.
*
* @param userRecordId
* @param proposedAuthenticatedUserIdentifier
Expand All @@ -605,20 +605,20 @@ public AuthenticatedUser createAuthenticatedUser(UserRecordIdentifier userRecord
proposedAuthenticatedUserIdentifier = proposedAuthenticatedUserIdentifier.trim();
}
// we now select a username for the generated AuthenticatedUser, or give up
String internalUserIdentifer = proposedAuthenticatedUserIdentifier;
String internalUserIdentifier = proposedAuthenticatedUserIdentifier;
// TODO should lock table authenticated users for write here
if ( identifierExists(internalUserIdentifer) ) {
if ( identifierExists(internalUserIdentifier) ) {
if ( ! generateUniqueIdentifier ) {
return null;
}
int i=1;
String identifier = internalUserIdentifer + i;
String identifier = internalUserIdentifier + i;
while ( identifierExists(identifier) ) {
i += 1;
}
authenticatedUser.setUserIdentifier(identifier);
} else {
authenticatedUser.setUserIdentifier(internalUserIdentifer);
authenticatedUser.setUserIdentifier(internalUserIdentifier);
}
authenticatedUser = save( authenticatedUser );
// TODO should unlock table authenticated users for write here
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,31 @@ public class UserIdentifier {
/**
* The String used in the permission system to assign roles, for example.
*/
String internalUserIdentifer;
String internalUserIdentifier;

public UserIdentifier(String lookupStringPerAuthProvider, String internalUserIdentifer) {
public UserIdentifier(String lookupStringPerAuthProvider, String internalUserIdentifier) {
this.lookupStringPerAuthProvider = lookupStringPerAuthProvider;
this.internalUserIdentifer = internalUserIdentifer;
this.internalUserIdentifier = internalUserIdentifier;
}

public String getLookupStringPerAuthProvider() {
return lookupStringPerAuthProvider;
}

/**
* @deprecated because of a typo; use {@link #getInternalUserIdentifier()} instead
* @see #getInternalUserIdentifier()
* @return the internal user identifier
*/
@Deprecated
public String getInternalUserIdentifer() {
return internalUserIdentifer;
return getInternalUserIdentifier();
}

/**
* @return the internal user identifier
*/
public String getInternalUserIdentifier() {
return internalUserIdentifier;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,24 @@ public static String findSingleValue(String mayHaveMultipleValues) {
return singleValue;
}

/**
* @deprecated because of a typo; use {@link #generateFriendlyLookingUserIdentifier(String, String)} instead
* @see #generateFriendlyLookingUserIdentifier(String, String)
* @param usernameAssertion
* @param email
* @return a friendly-looking user identifier based on the asserted username or email, or a UUID as fallback
*/
@Deprecated
public static String generateFriendlyLookingUserIdentifer(String usernameAssertion, String email) {
return generateFriendlyLookingUserIdentifier(usernameAssertion, email);
}

/**
* @param usernameAssertion
* @param email
* @return a friendly-looking user identifier based on the asserted username or email, or a UUID as fallback
*/
public static String generateFriendlyLookingUserIdentifier(String usernameAssertion, String email) {
if (usernameAssertion != null && !usernameAssertion.isEmpty()) {
return usernameAssertion;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -450,7 +450,7 @@ private void loadChecksumManifest() {
// We probably want package files to be able to use specific stores instead.
// More importantly perhaps, the approach above does not take into account
// if the dataset may have an AlternativePersistentIdentifier, that may be
// designated isStorageLocationDesignator() - i.e., if a different identifer
// designated isStorageLocationDesignator() - i.e., if a different identifier
// needs to be used to name the storage directory, instead of the main/current
// persistent identifier above.
getJobLogger().log(Level.INFO, "Reading checksum manifest: " + manifestAbsolutePath);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ public void open(Serializable checkpoint) throws Exception {
// We probably want package files to be able to use specific stores instead.
// More importantly perhaps, the approach above does not take into account
// if the dataset may have an AlternativePersistentIdentifier, that may be
// designated isStorageLocationDesignator() - i.e., if a different identifer
// designated isStorageLocationDesignator() - i.e., if a different identifier
// needs to be used to name the storage directory, instead of the main/current
// persistent identifier above.
getJobLogger().log(Level.INFO, "Reading dataset directory: " + directory.getAbsolutePath()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public JsonObject execute(CommandContext ctxt) throws CommandException {
// We probably want package files to be able to use specific stores instead.
// More importantly perhaps, the approach above does not take into account
// if the dataset may have an AlternativePersistentIdentifier, that may be
// designated isStorageLocationDesignator() - i.e., if a different identifer
// designated isStorageLocationDesignator() - i.e., if a different identifier
// needs to be used to name the storage directory, instead of the main/current
// persistent identifier above.
if (!isValidDirectory(directory)) {
Expand Down
12 changes: 6 additions & 6 deletions src/test/java/edu/harvard/iq/dataverse/api/AdminIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -153,10 +153,10 @@ public void testFilterAuthenticatedUsers() throws Exception {
.body("data.pagination.pageCount", equalTo(1))
.body("data.pagination.numResults", equalTo(numResults));

String userIdentifer;
String userIdentifier;
for (int i=0; i < numResults; i++){
userIdentifer = JsonPath.from(filterReponse01.getBody().asString()).getString("data.users[" + i + "].userIdentifier");
assertEquals(randomUsernames.contains(userIdentifer), true);
userIdentifier = JsonPath.from(filterReponse01.getBody().asString()).getString("data.users[" + i + "].userIdentifier");
assertTrue(randomUsernames.contains(userIdentifier));
}

List<Object> userList1 = JsonPath.from(filterReponse01.body().asString()).getList("data.users");
Expand All @@ -177,10 +177,10 @@ public void testFilterAuthenticatedUsers() throws Exception {
.body("data.pagination.pageCount", equalTo(3))
.body("data.pagination.numResults", equalTo(numResults));

String userIdentifer2;
String userIdentifier2;
for (int i=0; i < numUsersReturned; i++){
userIdentifer2 = JsonPath.from(filterReponse02.getBody().asString()).getString("data.users[" + i + "].userIdentifier");
assertEquals(randomUsernames.contains(userIdentifer2), true);
userIdentifier2 = JsonPath.from(filterReponse02.getBody().asString()).getString("data.users[" + i + "].userIdentifier");
assertTrue(randomUsernames.contains(userIdentifier2));
}

List<Object> userList2 = JsonPath.from(filterReponse02.body().asString()).getList("data.users");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,16 +102,16 @@ public void testFindSingleValue() {
}

@Test
public void testGenerateFriendlyLookingUserIdentifer() {
public void testGenerateFriendlyLookingUserIdentifier() {
int lengthOfUuid = UUID.randomUUID().toString().length();
assertEquals("uid1", ShibUtil.generateFriendlyLookingUserIdentifer("uid1", null));
assertEquals(" leadingWhiteSpace", ShibUtil.generateFriendlyLookingUserIdentifer(" leadingWhiteSpace", null));
assertEquals("uid1", ShibUtil.generateFriendlyLookingUserIdentifer("uid1", "email1@example.com"));
assertEquals("email1", ShibUtil.generateFriendlyLookingUserIdentifer(null, "email1@example.com"));
assertEquals(lengthOfUuid, ShibUtil.generateFriendlyLookingUserIdentifer(null, null).length());
assertEquals(lengthOfUuid, ShibUtil.generateFriendlyLookingUserIdentifer(null, "").length());
assertEquals(lengthOfUuid, ShibUtil.generateFriendlyLookingUserIdentifer("", null).length());
assertEquals(lengthOfUuid, ShibUtil.generateFriendlyLookingUserIdentifer(null, "junkEmailAddress").length());
assertEquals("uid1", ShibUtil.generateFriendlyLookingUserIdentifier("uid1", null));
assertEquals(" leadingWhiteSpace", ShibUtil.generateFriendlyLookingUserIdentifier(" leadingWhiteSpace", null));
assertEquals("uid1", ShibUtil.generateFriendlyLookingUserIdentifier("uid1", "email1@example.com"));
assertEquals("email1", ShibUtil.generateFriendlyLookingUserIdentifier(null, "email1@example.com"));
assertEquals(lengthOfUuid, ShibUtil.generateFriendlyLookingUserIdentifier(null, null).length());
assertEquals(lengthOfUuid, ShibUtil.generateFriendlyLookingUserIdentifier(null, "").length());
assertEquals(lengthOfUuid, ShibUtil.generateFriendlyLookingUserIdentifier("", null).length());
assertEquals(lengthOfUuid, ShibUtil.generateFriendlyLookingUserIdentifier(null, "junkEmailAddress").length());
}

@Test
Expand Down

0 comments on commit d76e494

Please sign in to comment.