String message = "Document URL is empty";
log.debug(message);
return message;
}
String key;
SpreadsheetService service = new SpreadsheetService("GSpread Connection Service");
try {
key = GSpreadConfig.extractKey(documentURL);
} catch (DataServiceFault e) {
String message = "Invalid documentURL:" + documentURL;
log.warn(message);
return message;
}
if (protectedTokens == null) {
protectedTokens = "";
}
if (passwordProvider == null) {
passwordProvider = "";
}
if (!(DBUtils.isEmptyString(protectedTokens) && DBUtils.isEmptyString(passwordProvider))) {
OMFactory fac = OMAbstractFactory.getOMFactory();
OMElement dataEl = fac.createOMElement("data", null);
OMElement passwordManagerEl = fac.createOMElement("passwordManager", null);
OMElement protectedTokensEl = fac.createOMElement("protectedTokens", null);
protectedTokensEl.setText(protectedTokens);
OMElement passwordProviderEl = fac.createOMElement("passwordProvider", null);
passwordProviderEl.setText(passwordProvider);
passwordManagerEl.addChild(protectedTokensEl);
passwordManagerEl.addChild(passwordProviderEl);
dataEl.addChild(passwordManagerEl);
SecretResolver secretResolver = SecretResolverFactory.create(dataEl, false);
if (secretResolver.isInitialized() && secretResolver.isTokenProtected(password)) {
resolvePwd = secretResolver.resolve(password);
} else {
resolvePwd = password;
}
} else {
resolvePwd = password;
}
if (!visibility.equals("public")) {
if (DBUtils.isEmptyString(user)) {
String message = "User name field is empty";
log.error(message);
return message;
}
if (DBUtils.isEmptyString(resolvePwd)) {
String message = "Password field is empty";
log.error(message);
return message;
}
try {
service.setUserCredentials(user, resolvePwd);
} catch (AuthenticationException e) {
String message = "Invalid User Credentials";
log.error(message,e);
return message;
}
}
String worksheetFeedURL = GSpreadConfig.BASE_WORKSHEET_URL + key + "/" + visibility
+ "/basic";
try {
URL url = new URL(worksheetFeedURL);
try {
service.getFeed(url, CellFeed.class);
String message = "Google spreadsheet connection is successfull ";
log.debug(message);
return message;
} catch (IOException e) {
String message = "URL Not found:" + documentURL;