PAN-50 added findByUsername to the AccountController class and tests
This commit is contained in:
+2
-2
@@ -29,7 +29,7 @@ public class AccountsIntegrationTest {
|
||||
|
||||
assertEquals("Test username", savedAccount.getUsername());
|
||||
assertEquals("test password", savedAccount.getPassword());
|
||||
assertTrue(savedAccount.isAdministratorStatus());
|
||||
assertTrue(savedAccount.getAdministratorStatus());
|
||||
|
||||
savedAccount.setPassword("Test Update");
|
||||
|
||||
@@ -37,7 +37,7 @@ public class AccountsIntegrationTest {
|
||||
|
||||
assertEquals("Test username", savedAccount.getUsername());
|
||||
assertEquals("Test Update", savedAccount.getPassword());
|
||||
assertTrue(savedAccount.isAdministratorStatus());
|
||||
assertTrue(savedAccount.getAdministratorStatus());
|
||||
assertEquals(updatedAccount.getId(), id);
|
||||
|
||||
accountsRepository.delete(accountDto);
|
||||
|
||||
+46
@@ -14,6 +14,8 @@ import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.validation.Valid;
|
||||
import javax.validation.groups.Default;
|
||||
import java.time.Duration;
|
||||
import java.time.Instant;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
@@ -73,6 +75,35 @@ public class AccountController {
|
||||
);
|
||||
}
|
||||
|
||||
@GetMapping("/{username}")
|
||||
public @ResponseBody
|
||||
ResponseEntity<AccountDto> getAccountByUsername(@PathVariable("username") final String username) {
|
||||
LOG.info("Received request to query for account with username " + username);
|
||||
if (username == null) {
|
||||
LOG.error("ERROR: username was null");
|
||||
return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
|
||||
LOG.debug("Querying for account with username " + username);
|
||||
final StopWatch stopWatch = new StopWatch();
|
||||
stopWatch.start();
|
||||
|
||||
final Optional<AccountDto> account = accountsRepository.findByUsername(username);
|
||||
|
||||
stopWatch.stop();
|
||||
|
||||
LOG.debug("Received response from server: query took " + stopWatch.getTotalTimeMillis() + "ms to complete");
|
||||
return account.map(accountDto -> {
|
||||
LOG.info("Returning account with username " + username);
|
||||
return new ResponseEntity<>(accountDto, HttpStatus.OK);
|
||||
}).orElseGet(
|
||||
() -> {
|
||||
LOG.warn("No account was found with username " + username);
|
||||
return new ResponseEntity<>(HttpStatus.NOT_FOUND);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
@PostMapping("/")
|
||||
@Validated({AccountDto.Insert.class, Default.class})
|
||||
public @ResponseBody ResponseEntity<AccountDto> insertAccount(
|
||||
@@ -89,6 +120,21 @@ public class AccountController {
|
||||
return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
|
||||
LOG.info("Checking for any existing users with username {}", accountDto.getUsername());
|
||||
|
||||
final Instant start = Instant.now();
|
||||
|
||||
LOG.debug("Querying for existing accounts");
|
||||
|
||||
final Optional<AccountDto> existingAccount = accountsRepository.findByUsername(accountDto.getUsername());
|
||||
|
||||
LOG.debug("Received response from the server: query took {} ms", Duration.between(start, Instant.now()).toMillis());
|
||||
|
||||
if (existingAccount.isPresent()) {
|
||||
LOG.warn("An account already exists with username {}", accountDto.getUsername());
|
||||
return new ResponseEntity<>(HttpStatus.CONFLICT);
|
||||
}
|
||||
|
||||
LOG.debug("Saving new account");
|
||||
|
||||
final StopWatch stopWatch = new StopWatch();
|
||||
|
||||
+1
-1
@@ -7,5 +7,5 @@ import org.springframework.stereotype.Component;
|
||||
@Component
|
||||
@AllArgsConstructor
|
||||
public class NotationController {
|
||||
final private NotationRepository notationRepository;
|
||||
private final NotationRepository notationRepository;
|
||||
}
|
||||
|
||||
+1
-1
@@ -7,5 +7,5 @@ import org.springframework.stereotype.Component;
|
||||
@Component
|
||||
@AllArgsConstructor
|
||||
public class ProofController {
|
||||
final private ProofRepository proofRepository;
|
||||
private final ProofRepository proofRepository;
|
||||
}
|
||||
|
||||
+5
-5
@@ -67,19 +67,19 @@ public class TheoremController {
|
||||
|
||||
@GetMapping("/{proven_status}")
|
||||
public @ResponseBody
|
||||
ResponseEntity<List<TheoremDto>> getAllTheoremsByBranch(@PathVariable("proven_status") final Boolean proven_status) {
|
||||
LOG.info("Received request to query for theorems whose proven status is " + proven_status);
|
||||
if (proven_status == null) {
|
||||
ResponseEntity<List<TheoremDto>> getAllTheoremsByBranch(@PathVariable("proven_status") final Boolean provenStatus) {
|
||||
LOG.info("Received request to query for theorems whose proven status is " + provenStatus);
|
||||
if (provenStatus == null) {
|
||||
LOG.error("ERROR: branch was null");
|
||||
return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
|
||||
LOG.debug("Querying for theorems with proven status " + proven_status);
|
||||
LOG.debug("Querying for theorems with proven status " + provenStatus);
|
||||
|
||||
final StopWatch stopWatch = new StopWatch();
|
||||
stopWatch.start();
|
||||
|
||||
final List<TheoremDto> listOfTheorems = theoremRepository.findByProven_status(proven_status);
|
||||
final List<TheoremDto> listOfTheorems = theoremRepository.findByProvenStatus(provenStatus);
|
||||
|
||||
stopWatch.stop();
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package edu.msudenver.tsp.persistence.dto;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import org.springframework.data.jpa.domain.support.AuditingEntityListener;
|
||||
@@ -18,15 +19,35 @@ import java.util.Date;
|
||||
public class AccountDto extends BaseDto implements Serializable {
|
||||
@NotBlank(groups = Insert.class, message = "A username must be specified") @Size(max = 50) private String username;
|
||||
@NotBlank(groups = Insert.class, message = "A password must be specified") @Size(max = 256) private String password;
|
||||
@NotNull private boolean administrator_status;
|
||||
@Temporal(TemporalType.DATE) private Date last_login;
|
||||
@NotNull private boolean administratorStatus;
|
||||
@Temporal(TemporalType.DATE) private Date lastLogin;
|
||||
|
||||
private static final long serialVersionUID = 7095627971593953734L;
|
||||
|
||||
@JsonProperty("administrator_status")
|
||||
public boolean getAdministratorStatus() {
|
||||
return administratorStatus;
|
||||
}
|
||||
|
||||
@JsonProperty("administrator_status")
|
||||
public void setAdministratorStatus(final boolean administratorStatus) {
|
||||
this.administratorStatus = administratorStatus;
|
||||
}
|
||||
|
||||
@JsonProperty("last_login")
|
||||
public Date getLastLogin() {
|
||||
return lastLogin;
|
||||
}
|
||||
|
||||
@JsonProperty("last_login")
|
||||
public void setLastLogin(final Date lastLogin) {
|
||||
this.lastLogin = lastLogin;
|
||||
}
|
||||
|
||||
public interface Insert {}
|
||||
|
||||
@PrePersist
|
||||
public void prePersist() {
|
||||
last_login = new Date();
|
||||
lastLogin = new Date();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package edu.msudenver.tsp.persistence.dto;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import org.hibernate.annotations.Type;
|
||||
@@ -20,11 +21,41 @@ import java.util.List;
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
public class TheoremDto extends BaseDto implements Serializable {
|
||||
@NotBlank @Size(min = 1, max = 512, message = "theorem name must be between 1 and 512 characters") private String name;
|
||||
@NotNull private TheoremType theorem_type;
|
||||
@NotNull private TheoremType theoremType;
|
||||
@NotNull(message = "a branch of mathematics that this theorem is associated with must be specified") private String branch;
|
||||
@Type(type = "json") @Column(columnDefinition = "jsonb") private List<String> referenced_definitions;
|
||||
@Type(type = "json") @Column(columnDefinition = "jsonb") private List<String> referenced_theorems;
|
||||
@NotNull private boolean proven_status;
|
||||
@Type(type = "json") @Column(columnDefinition = "jsonb") private List<String> referencedDefinitions;
|
||||
@Type(type = "json") @Column(columnDefinition = "jsonb") private List<String> referencedTheorems;
|
||||
@NotNull private boolean provenStatus;
|
||||
|
||||
@JsonProperty("theorem_type")
|
||||
public TheoremType getTheoremType() {
|
||||
return theoremType;
|
||||
}
|
||||
|
||||
@JsonProperty("theorem_type")
|
||||
public void setTheoremType(final TheoremType theoremType) {
|
||||
this.theoremType = theoremType;
|
||||
}
|
||||
|
||||
@JsonProperty("referenced_definitions")
|
||||
public List<String> getReferencedDefinitions() {
|
||||
return referencedDefinitions;
|
||||
}
|
||||
|
||||
@JsonProperty("referenced_definitions")
|
||||
public void setReferencedDefinitions(final List<String> referencedDefinitions) {
|
||||
this.referencedDefinitions = referencedDefinitions;
|
||||
}
|
||||
|
||||
@JsonProperty("referenced_theorems")
|
||||
public List<String> getReferencedTheorems() {
|
||||
return referencedTheorems;
|
||||
}
|
||||
|
||||
@JsonProperty("referenced_theorems")
|
||||
public void setReferencedTheorems(final List<String> referencedTheorems) {
|
||||
this.referencedTheorems = referencedTheorems;
|
||||
}
|
||||
|
||||
private static final long serialVersionUID = 1545568391140364425L;
|
||||
}
|
||||
|
||||
+3
@@ -4,6 +4,9 @@ import edu.msudenver.tsp.persistence.dto.AccountDto;
|
||||
import org.springframework.data.repository.CrudRepository;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
@Repository
|
||||
public interface AccountsRepository extends CrudRepository<AccountDto, Integer> {
|
||||
Optional<AccountDto> findByUsername(String username);
|
||||
}
|
||||
|
||||
+1
-1
@@ -11,5 +11,5 @@ public interface TheoremRepository extends JpaRepository<TheoremDto, Integer> {
|
||||
|
||||
List<TheoremDto> findByBranch(String branch);
|
||||
|
||||
List<TheoremDto> findByProven_status(Boolean proven_status);
|
||||
List<TheoremDto> findByProvenStatus(Boolean provenStatus);
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
spring.jpa.hibernate.ddl-auto = none
|
||||
spring.jpa.database=mysql
|
||||
spring.datasource.url=jdbc:mysql://127.0.0.1:3306/pandamonium?autoReconnect=true&useSSL=false
|
||||
spring.datasource.url=jdbc:mysql://127.0.0.1:3306/pandamonium?autoReconnect=true&useSSL=false&serverTimezone=UTC
|
||||
spring.datasource.username=panda
|
||||
spring.datasource.password=secret
|
||||
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
|
||||
|
||||
+52
@@ -87,10 +87,48 @@ public class AccountControllerTest {
|
||||
verify(accountsRepository).findById(anyInt());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetAccountByUsername() {
|
||||
final AccountDto accountDto = createAccount();
|
||||
when(accountsRepository.findByUsername(anyString())).thenReturn(Optional.ofNullable(accountDto));
|
||||
|
||||
final ResponseEntity<AccountDto> responseEntity = accountController.getAccountByUsername("Test username");
|
||||
|
||||
assertNotNull(responseEntity);
|
||||
assertTrue(responseEntity.hasBody());
|
||||
assertNotNull(responseEntity.getBody());
|
||||
assertEquals(HttpStatus.OK, responseEntity.getStatusCode());
|
||||
assertEquals(accountDto, responseEntity.getBody());
|
||||
verify(accountsRepository).findByUsername(anyString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetAccountById_nullUsername() {
|
||||
final ResponseEntity responseEntity = accountController.getAccountByUsername(null);
|
||||
|
||||
assertNotNull(responseEntity);
|
||||
assertFalse(responseEntity.hasBody());
|
||||
assertEquals(HttpStatus.BAD_REQUEST, responseEntity.getStatusCode());
|
||||
verifyZeroInteractions(accountsRepository);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetAccountByUsername_noAccountFound() {
|
||||
when(accountsRepository.findByUsername(anyString())).thenReturn(Optional.empty());
|
||||
|
||||
final ResponseEntity responseEntity = accountController.getAccountByUsername("Test username");
|
||||
|
||||
assertNotNull(responseEntity);
|
||||
assertFalse(responseEntity.hasBody());
|
||||
assertEquals(HttpStatus.NOT_FOUND, responseEntity.getStatusCode());
|
||||
verify(accountsRepository).findByUsername(anyString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testInsertAccount() {
|
||||
final AccountDto accountDto = createAccount();
|
||||
when(accountsRepository.save(any(AccountDto.class))).thenReturn(accountDto);
|
||||
when(accountsRepository.findByUsername(anyString())).thenReturn(Optional.empty());
|
||||
|
||||
final ResponseEntity<AccountDto> responseEntity = accountController.insertAccount(accountDto, bindingResult);
|
||||
|
||||
@@ -102,6 +140,20 @@ public class AccountControllerTest {
|
||||
verify(accountsRepository).save(any(AccountDto.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testInsertAccount_usernameAlreadyExists() {
|
||||
final AccountDto accountDto = createAccount();
|
||||
when(accountsRepository.findByUsername(anyString())).thenReturn(Optional.of(accountDto));
|
||||
|
||||
final ResponseEntity<AccountDto> responseEntity = accountController.insertAccount(accountDto, bindingResult);
|
||||
|
||||
assertNotNull(responseEntity);
|
||||
assertFalse(responseEntity.hasBody());
|
||||
assertEquals(HttpStatus.CONFLICT, responseEntity.getStatusCode());
|
||||
verify(accountsRepository).findByUsername(anyString());
|
||||
verify(accountsRepository, times(0)).save(any(AccountDto.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testInsertAccount_accountsDtoIsNull() {
|
||||
final ResponseEntity responseEntity = accountController.insertAccount(null, bindingResult);
|
||||
|
||||
@@ -19,6 +19,10 @@ repositories {
|
||||
|
||||
dependencies {
|
||||
compile project(':persistence')
|
||||
testCompile group: 'junit', name: 'junit', version: '4.12'
|
||||
compile group: 'org.apache.httpcomponents', name: 'httpcore', version: '4.4.11'
|
||||
compile group: 'org.apache.httpcomponents', name: 'fluent-hc', version: '4.5.7'
|
||||
compile group: 'com.google.code.gson', name: 'gson', version: '2.7'
|
||||
compile fileTree(dir: 'lib', include: '**/*.jar')
|
||||
|
||||
testCompile group: 'junit', name: 'junit', version: '4.12'
|
||||
}
|
||||
|
||||
@@ -0,0 +1,100 @@
|
||||
package edu.msudenver.tsp.services;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
import edu.msudenver.tsp.services.factory.RequestFactory;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.http.HttpResponse;
|
||||
import org.apache.http.client.fluent.Request;
|
||||
import org.apache.http.util.EntityUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
@Slf4j
|
||||
@Service
|
||||
public class RestService {
|
||||
private static final Gson GSON = new Gson();
|
||||
private final RequestFactory requestFactory;
|
||||
|
||||
@Autowired
|
||||
public RestService(final RequestFactory requestFactory) {
|
||||
this.requestFactory = requestFactory;
|
||||
}
|
||||
|
||||
public boolean delete(final String uri, final Integer connectionTimeout, final Integer socketTimeout, final HttpStatus httpStatus) {
|
||||
LOG.info("Sending DELETE {}", uri);
|
||||
final Optional<HttpResponse> response = send(requestFactory.delete(uri), null, connectionTimeout, socketTimeout);
|
||||
|
||||
return response.isPresent() && response.get().getStatusLine().getStatusCode() == httpStatus.value();
|
||||
}
|
||||
|
||||
<T> Optional<T> get(final String uri, final TypeToken<T> type, final Integer connectionTimeout, final Integer socketTimeout, final String auth) {
|
||||
LOG.info("Sending GET {}", uri);
|
||||
return send(requestFactory.get(uri), auth, connectionTimeout, socketTimeout, type);
|
||||
}
|
||||
|
||||
<T> Optional<T> post(final String uri, final String requestJson, final TypeToken<T> type, final Integer connectionTimeout, final Integer socketTimeout) {
|
||||
LOG.info("Sending POST {} with body: {}", uri, requestJson);
|
||||
return send(requestFactory.post(uri, requestJson), null, connectionTimeout, socketTimeout, type);
|
||||
}
|
||||
|
||||
Optional<HttpResponse> post(final String uri, final String requestJson, final Integer connectionTimeout, final Integer socketTimeout) {
|
||||
LOG.info("Sending POST {} with body: {}", uri, requestJson);
|
||||
return send(requestFactory.post(uri, requestJson), null, connectionTimeout, socketTimeout);
|
||||
}
|
||||
|
||||
<T> Optional<T> put(final String uri, final String requestJson, final TypeToken<T> type, final Integer connectionTimeout, final Integer socketTimeout, final String auth) {
|
||||
LOG.info("Sending PUT {} with body: {}", uri, requestJson);
|
||||
return send(requestFactory.put(uri, requestJson), auth, connectionTimeout, socketTimeout, type);
|
||||
}
|
||||
|
||||
private <T> Optional<T> send(final Request request, final String auth, final Integer connectionTimeout, final Integer socketTimeout, final TypeToken<T> type) {
|
||||
try {
|
||||
final Optional<HttpResponse> optionalHttpResponse = send(request, auth, connectionTimeout, socketTimeout);
|
||||
if (optionalHttpResponse.isPresent()) {
|
||||
final HttpResponse httpResponse = optionalHttpResponse.get();
|
||||
LOG.info("Received {} response", httpResponse.getStatusLine().getStatusCode());
|
||||
|
||||
final String jsonResponse = httpResponse.getEntity() == null ? null : EntityUtils.toString(httpResponse.getEntity());
|
||||
if (StringUtils.isNotBlank(jsonResponse)) {
|
||||
final T responses = GSON.fromJson(jsonResponse, type.getType());
|
||||
if (responses instanceof List) {
|
||||
LOG.info("Found {} responses.", ((List) responses).size());
|
||||
if (((List) responses).isEmpty()) {
|
||||
return Optional.empty();
|
||||
}
|
||||
}
|
||||
|
||||
return Optional.ofNullable(responses);
|
||||
}
|
||||
}
|
||||
} catch (final Exception e) {
|
||||
LOG.error("Could not send request", e);
|
||||
}
|
||||
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
private Optional<HttpResponse> send(final Request request, final String auth, final Integer connectionTimeout, final Integer socketTimeout) {
|
||||
if (StringUtils.isNotBlank(auth)) {
|
||||
request.addHeader("Authorization", "Basic " + auth);
|
||||
}
|
||||
|
||||
try {
|
||||
return Optional.ofNullable(request.connectTimeout(connectionTimeout)
|
||||
.socketTimeout(socketTimeout)
|
||||
.execute()
|
||||
.returnResponse());
|
||||
} catch (final Exception e) {
|
||||
LOG.error("Could not send request", e);
|
||||
return Optional.empty();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,57 @@
|
||||
package edu.msudenver.tsp.services;
|
||||
|
||||
import com.google.gson.GsonBuilder;
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
import edu.msudenver.tsp.services.dto.Account;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.time.Duration;
|
||||
import java.time.Instant;
|
||||
import java.util.Optional;
|
||||
|
||||
@Slf4j
|
||||
@Service
|
||||
public class UserService {
|
||||
private final RestService restService;
|
||||
@Value("${persistence.api.connection.timeout.milliseconds}") private int connectionTimeoutMilliseconds;
|
||||
@Value("${persistence.api.socket.timeout.milliseconds}") private int socketTimeoutMilliseconds;
|
||||
@Value("${persistence.api.base.url}") private String persistenceApiBaseUrl;
|
||||
|
||||
@Autowired
|
||||
public UserService(final RestService restService) {
|
||||
this.restService = restService;
|
||||
}
|
||||
|
||||
public Optional<Account> createNewAccount(final Account account) {
|
||||
if (account == null) {
|
||||
LOG.error("Given null account, returning {}");
|
||||
return Optional.empty();
|
||||
}
|
||||
final Instant start = Instant.now();
|
||||
|
||||
try {
|
||||
final TypeToken<Account> typeToken = new TypeToken<Account>() {};
|
||||
final Optional<Account> persistenceApiResponse = restService.post(persistenceApiBaseUrl + "/accounts/",
|
||||
new GsonBuilder().create().toJson(account),
|
||||
typeToken,
|
||||
connectionTimeoutMilliseconds,
|
||||
socketTimeoutMilliseconds);
|
||||
|
||||
if (persistenceApiResponse.isPresent()) {
|
||||
LOG.info("Returning {}", persistenceApiResponse.get());
|
||||
} else {
|
||||
LOG.info("Unable to create new account {}", account.toString());
|
||||
}
|
||||
|
||||
return persistenceApiResponse;
|
||||
} catch (final Exception e) {
|
||||
LOG.error("Error creating new account {}", e);
|
||||
return Optional.empty();
|
||||
} finally {
|
||||
LOG.info("Create new account request took {} ms", Duration.between(start, Instant.now()).toMillis());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
package edu.msudenver.tsp.services.dto;
|
||||
|
||||
import com.google.gson.annotations.SerializedName;
|
||||
import edu.msudenver.tsp.persistence.dto.AccountDto;
|
||||
|
||||
import javax.persistence.Temporal;
|
||||
import javax.persistence.TemporalType;
|
||||
import javax.validation.constraints.NotBlank;
|
||||
import javax.validation.constraints.NotNull;
|
||||
import javax.validation.constraints.Size;
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
|
||||
public class Account extends BaseDto implements Serializable {
|
||||
@NotBlank(groups = AccountDto.Insert.class, message = "A username must be specified") @Size(max = 50) private String username;
|
||||
@NotBlank(groups = AccountDto.Insert.class, message = "A password must be specified") @Size(max = 256) private String password;
|
||||
@NotNull @SerializedName("administrator_status") private boolean administratorStatus;
|
||||
@Temporal(TemporalType.DATE) @SerializedName("last_login") private Date lastLogin;
|
||||
|
||||
private static final long serialVersionUID = 7095627971593953734L;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
package edu.msudenver.tsp.services.dto;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
@Data
|
||||
public class BaseDto implements Serializable {
|
||||
private int id;
|
||||
private Integer version;
|
||||
|
||||
private static final long serialVersionUID = 5343705942114910963L;
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
package edu.msudenver.tsp.services.factory;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.http.client.fluent.Request;
|
||||
import org.apache.http.entity.ContentType;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@Service
|
||||
public class RequestFactory {
|
||||
public Request delete(final String uri) {
|
||||
return Request.Delete(uri);
|
||||
}
|
||||
|
||||
public Request get(final String uri) {
|
||||
return Request.Get(uri);
|
||||
}
|
||||
|
||||
public Request post(final String uri, final String requestJson) {
|
||||
return StringUtils.isNotBlank(requestJson) ? Request.Post(uri).bodyString(requestJson, ContentType.APPLICATION_JSON) : Request.Post(uri);
|
||||
}
|
||||
|
||||
public Request put(final String uri, final String requestJson) {
|
||||
return StringUtils.isNotBlank(requestJson) ? Request.Put(uri).bodyString(requestJson, ContentType.APPLICATION_JSON) : Request.Put(uri);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
persistence.api.connection.timeout.milliseconds = 5000
|
||||
persistence.api.socket.timeout.milliseconds = 10000
|
||||
persistence.api.base.url = http://localhost:8090/
|
||||
Reference in New Issue
Block a user