Skip to content

Commit

Permalink
Merge pull request #3782 from ferrys/3747-compute-button-UI
Browse files Browse the repository at this point in the history
Updated Cloud Storage Access box to container name
  • Loading branch information
ferrys committed Apr 21, 2017
2 parents cc9d4eb + 6d5dc7f commit 113976e
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 14 deletions.
16 changes: 16 additions & 0 deletions src/main/java/edu/harvard/iq/dataverse/DatasetPage.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package edu.harvard.iq.dataverse;

import edu.harvard.iq.dataverse.authorization.AuthenticationServiceBean;
import edu.harvard.iq.dataverse.dataaccess.SwiftAccessIO;
import edu.harvard.iq.dataverse.authorization.Permission;
import edu.harvard.iq.dataverse.authorization.providers.builtin.BuiltinUserServiceBean;
import edu.harvard.iq.dataverse.authorization.users.AuthenticatedUser;
Expand Down Expand Up @@ -350,6 +351,21 @@ public String getDataverseSiteUrl() {
public void setDataverseSiteUrl(String dataverseSiteUrl) {
this.dataverseSiteUrl = dataverseSiteUrl;
}

public String getSwiftContainerName(){
String swiftContainerName = null;
String swiftFolderPathSeparator = "_";
if (persistentId != null) {
dataset = datasetService.findByGlobalId(persistentId);
String authorityNoSlashes = dataset.getAuthority().replace(dataset.getDoiSeparator(), swiftFolderPathSeparator);
swiftContainerName = dataset.getProtocol() + swiftFolderPathSeparator + authorityNoSlashes.replace(".", swiftFolderPathSeparator)
+ swiftFolderPathSeparator + dataset.getIdentifier();
logger.info("Swift container name: " + swiftContainerName);
}

return swiftContainerName;
}


public DataFile getSelectedDownloadFile() {
return selectedDownloadFile;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ public DataAccess() {
// set by the user in glassfish-setup.sh if DEFFAULT_STORAGE_DRIVER_IDENTIFIER = swift
public static final String DEFAULT_STORAGE_DRIVER_IDENTIFIER = System.getProperty("dataverse.files.storage-driver-id");
public static String swiftFileUri;
public static String swiftContainerUri;

// The getDataFileIO() methods initialize DataFileIO objects for
// datafiles that are already saved using one of the supported Dataverse
Expand Down Expand Up @@ -118,11 +117,11 @@ public static String getSwiftFileURI(StoredObject fileObject) throws IOException
return fileUri;
}

public static String getSwiftContainerURI(StoredObject fileObject) throws IOException {
String containerUri;
containerUri = getSwiftFileURI(fileObject);
containerUri = containerUri.substring(0, containerUri.lastIndexOf('/'));
return containerUri;
}
// public static String getSwiftContainer(StoredObject fileObject) throws IOException {
// String containerUri;
// containerUri = getSwiftFileURI(fileObject);
// containerUri = containerUri.substring(0, containerUri.lastIndexOf('/'));
// return containerUri;
// }

}
10 changes: 10 additions & 0 deletions src/main/java/edu/harvard/iq/dataverse/dataaccess/DataFileIO.java
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,8 @@ public DataFileIO(DataFile dataFile, DataAccessRequest req) {
private String varHeader;
private String errorMessage;

//private String swiftContainerName;

private Boolean isLocalFile = false;
private Boolean isRemoteAccess = false;
private Boolean isHttpAccess = false;
Expand Down Expand Up @@ -271,6 +273,10 @@ public String getRemoteUrl() {
return remoteUrl;
}

// public String getSwiftContainerName(){
// return swiftContainerName;
// }

public GetMethod getHTTPMethod() {
return method;
}
Expand Down Expand Up @@ -356,6 +362,10 @@ public void setRemoteUrl(String u) {
remoteUrl = u;
}

// public void setSwiftContainerName(String u){
// swiftContainerName = u;
// }

public void setHTTPMethod(GetMethod hm) {
method = hm;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -275,9 +275,12 @@ private StoredObject initializeSwiftFileObject(boolean writeAccess) throws IOExc

//swiftFolderPath = this.getDataFile().getOwner().getDisplayName();
String swiftFolderPathSeparator = "_";
swiftFolderPath = this.getDataFile().getOwner().getAuthority().replace(this.getDataFile().getOwner().getDoiSeparator(), swiftFolderPathSeparator) +
String authorityNoSlashes = this.getDataFile().getOwner().getAuthority().replace(this.getDataFile().getOwner().getDoiSeparator(), swiftFolderPathSeparator);
swiftFolderPath = this.getDataFile().getOwner().getProtocol() + swiftFolderPathSeparator +
authorityNoSlashes.replace(".", swiftFolderPathSeparator) +
swiftFolderPathSeparator + this.getDataFile().getOwner().getIdentifier();
swiftFileName = storageIdentifier;
//setSwiftContainerName(swiftFolderPath);
//swiftFileName = this.getDataFile().getDisplayName();
//Storage Identifier is now updated after the object is uploaded on Swift.
this.getDataFile().setStorageIdentifier("swift://"+swiftEndPoint+":"+swiftFolderPath+":"+swiftFileName);
Expand Down Expand Up @@ -310,7 +313,14 @@ private StoredObject initializeSwiftFileObject(boolean writeAccess) throws IOExc
if (!dataContainer.exists()) {
if (writeAccess) {
dataContainer.create();
//dataContainer.makePublic();
try {
dataContainer.makePublic();
}
catch (Exception ex) {
ex.printStackTrace();
throw new IOException("Failed to make container public");
}

} else {
// This is a fatal condition - it has to exist, if we were to
// read an existing object!
Expand All @@ -319,14 +329,13 @@ private StoredObject initializeSwiftFileObject(boolean writeAccess) throws IOExc
}

StoredObject fileObject = dataContainer.getObject(swiftFileName);
dataContainer.makePublic(); //set public
//file download url for public files
DataAccess.swiftFileUri = DataAccess.getSwiftFileURI(fileObject);
setRemoteUrl(DataAccess.getSwiftFileURI(fileObject));

logger.info(DataAccess.swiftFileUri + " success");
//shows contents of container for public containers
DataAccess.swiftContainerUri = DataAccess.getSwiftContainerURI(fileObject);
logger.info(DataAccess.swiftContainerUri + " success");


if (!writeAccess && !fileObject.exists()) {
throw new IOException("SwiftAccessIO: File object " + swiftFileName + " does not exist (Dataverse datafile id: " + this.getDataFile().getId());
Expand Down Expand Up @@ -368,6 +377,8 @@ Account authenticateWithSwift(String swiftEndPoint) throws IOException {
String swiftEndPointSecretKey = p.getProperty("swift.password." + swiftEndPoint);
String swiftEndPointTenantName = p.getProperty("swift.tenant." + swiftEndPoint);
String swiftEndPointAuthMethod = p.getProperty("swift.auth_type." + swiftEndPoint);
String swiftEndPointUrl = p.getProperty("swift.swift_endpoint." + swiftEndPoint);
String swiftEndPointTenantId = p.getProperty("swift.tenant_id." + swiftEndPoint);

if (swiftEndPointAuthUrl == null || swiftEndPointUsername == null || swiftEndPointSecretKey == null
|| "".equals(swiftEndPointAuthUrl) || "".equals(swiftEndPointUsername) || "".equals(swiftEndPointSecretKey)) {
Expand All @@ -390,6 +401,7 @@ Account authenticateWithSwift(String swiftEndPoint) throws IOException {
if (swiftEndPointAuthMethod.equals("keystone")) {
account = new AccountFactory()
.setTenantName(swiftEndPointTenantName)
// .setTenantId(swiftEndPointTenantId)
.setUsername(swiftEndPointUsername)
.setPassword(swiftEndPointSecretKey)
.setAuthUrl(swiftEndPointAuthUrl)
Expand Down
3 changes: 1 addition & 2 deletions src/main/webapp/filesFragment.xhtml
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,7 @@

<!-- Cloud Storage Access -->
<div class="input-group">

<input class="form-control" value="10-5072-FK2_J8HHCF" placeholder="Cloud Storage Access" id="copy-input" style="font-weight:normal;" type="text"/>
<p:inputText class="form-control" value="#{DatasetPage.getSwiftContainerName()}" placeholder="Cloud Storage Access" id="copy-input" style="font-weight:normal;" type="text"/>

<span class="input-group-btn">
<a href="#" class="btn btn-default">
Expand Down

0 comments on commit 113976e

Please sign in to comment.