Skip to content
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
package com.researchspace.dataverse.api.v1;

import java.text.ParseException;
import java.util.Date;
import java.time.LocalDateTime;

import com.researchspace.springrest.ext.RestClientException;

Expand All @@ -29,19 +29,18 @@ public interface UsersOperations {

/**
* Get token expiration date.
* @return java.util.Date token expiration date.
* @return java.time.LocalDateTime token expiration.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will break existing client code that expects java.util.Date. To avoid doing that, suggest creating a new method with a variant name e.g. 'getTokenExpirationLocalDateTime'

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was a work in progress, and is not breaking anything because the method was non existing before.

* @throws ParseException
* @throws RestClientException
*/
Date getTokenExpirationDate() throws ParseException;
LocalDateTime getTokenExpirationDate() throws ParseException;

/**
* Recreate user token.
* @return new token
* @throws Exception
* Get token expiration text returned by dataverse.
* @return String as the form of <Token XXXXX expires on yyyy-MM-dd HH:mm:ss.SSS>.
* @throws ParseException
* @throws RestClientException
*/
String recreateToken();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

deleting /renaming this will break existing clients. Solution is to keep the original method signature and add your method as a new method - it looks like it is doing something different?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The method was finally not developed. We considered, that in our use, it was better to create the token ourselves when it would expire.



String getTokenExpiration() throws ParseException;

}
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,10 @@
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import org.apache.abdera.model.Entry;
Expand Down Expand Up @@ -453,20 +452,21 @@ public void deleteFile(final String fileName, final Identifier dsIdentifier)
}

@Override
public Date getTokenExpirationDate() throws ParseException, RestClientException {
public LocalDateTime getTokenExpirationDate() throws ParseException, RestClientException {
final String url = createAdminUrl("users", "token");
final HttpEntity<String> entity = createHttpEntity("");
final ParameterizedTypeReference<DataverseResponse<DvMessage>> type =
new ParameterizedTypeReference<DataverseResponse<DvMessage>>() {
};
final ResponseEntity<DataverseResponse<DvMessage>> resp = template.exchange(url, HttpMethod.GET, entity, type);
final DateFormat df = new SimpleDateFormat();
return df.parse(resp.getBody().getData().getMessage());
// Split the String given as <Token -token- expires on -date->
final String date = resp.getBody().getData().getMessage().split(" expires on ")[1];
return LocalDateTime.parse(date, DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss.SSS"));
}

@Override
public String recreateToken() throws RestClientException {
final String url = createAdminUrl("users", "token", "recreate");
public String getTokenExpiration() throws ParseException, RestClientException {
final String url = createAdminUrl("users", "token");
final HttpEntity<String> entity = createHttpEntity("");
final ParameterizedTypeReference<DataverseResponse<DvMessage>> type =
new ParameterizedTypeReference<DataverseResponse<DvMessage>>() {
Expand Down