Commit 458028e0 authored by Maxym Borodenko's avatar Maxym Borodenko
Browse files

Merge first and last name in Creator

parent 7e12845f
Pipeline #3912 passed with stage
in 1 minute and 36 seconds
......@@ -18,6 +18,7 @@ package org.genesys.catalog.model.dataset;
import java.util.Map;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
......@@ -58,13 +59,10 @@ public class DatasetCreator extends UuidModel implements PublishValidationInterf
CONTRIBUTOR
}
/** The first name. */
@PublishValidation
private String firstName;
/** The last name. */
@PublishValidation
private String lastName;
/** The full name. */
@PublishValidation
@Column(length = 200, nullable = false)
private String fullName;
/** The email. */
@PublishValidation
......@@ -133,41 +131,23 @@ public class DatasetCreator extends UuidModel implements PublishValidationInterf
this.dataset = dataset;
}
/**
* Gets the first name.
*
* @return the first name
*/
public String getFirstName() {
return firstName;
}
/**
* Sets the first name.
*
* @param firstName the new first name
*/
public void setFirstName(final String firstName) {
this.firstName = firstName;
}
/**
* Gets the last name.
*
* @return the last name
*/
public String getLastName() {
return lastName;
}
/**
* Sets the last name.
*
* @param lastName the new last name
*/
public void setLastName(final String lastName) {
this.lastName = lastName;
}
/**
* Gets the full name.
*
* @return the full name
*/
public String getFullName() {
return fullName;
}
/**
* Sets the full name.
*
* @param fullName the new full name
*/
public void setFullName(final String fullName) {
this.fullName = fullName;
}
/**
* Gets the email.
......
......@@ -150,8 +150,7 @@ public class DatasetCreatorServiceImpl implements DatasetCreatorService {
* @param source the source
*/
protected void copyValue(final DatasetCreator target, final DatasetCreator source) {
target.setFirstName(source.getFirstName());
target.setLastName(source.getLastName());
target.setFullName(source.getFullName());
target.setEmail(source.getEmail());
target.setPhoneNumber(source.getPhoneNumber());
target.setFax(source.getFax());
......
......@@ -86,11 +86,10 @@ public abstract class AbstractDatasetServiceTest extends CatalogServiceTest {
return input;
}
protected DatasetCreator buildDatasetCreator(String firsnName, String lastName, String email, String phoneNumber, Dataset dataset) {
protected DatasetCreator buildDatasetCreator(String fullName, String email, String phoneNumber, Dataset dataset) {
DatasetCreator datasetCreator = new DatasetCreator();
datasetCreator.setDataset(dataset);
datasetCreator.setFirstName(firsnName);
datasetCreator.setLastName(lastName);
datasetCreator.setFullName(fullName);
datasetCreator.setEmail(email);
datasetCreator.setRole(DatasetCreator.DatasetCreatorRole.CONTACT);
datasetCreator.setPhoneNumber(phoneNumber);
......
......@@ -54,7 +54,7 @@ public class DatasetCreatorServiceTest extends AbstractDatasetServiceTest {
@Test
public void createDatasetCreator() throws Exception {
Dataset result = buildAndSaveDataset(DATASET_TITLE_1, DATASET_DESCRIPTION_1, partner, false);
DatasetCreator datasetCreator = buildDatasetCreator("TestFirstName", "TestLastName", "TestEmailName", "0673579007", result);
DatasetCreator datasetCreator = buildDatasetCreator("TestFullName", "TestEmailName", "0673579007", result);
DatasetCreator datasetCreators = datasetCreatorService.createDatasetCreator(result.getUuid(), datasetCreator);
assertThat(datasetCreators, is(not(nullValue())));
assertThat(datasetCreators.getRole(), is(DatasetCreator.DatasetCreatorRole.CONTACT));
......@@ -64,7 +64,7 @@ public class DatasetCreatorServiceTest extends AbstractDatasetServiceTest {
@Test
public void updateDatasetCreator() throws NotFoundElement {
Dataset result = buildAndSaveDataset(DATASET_TITLE_1, DATASET_DESCRIPTION_1, partner, false);
DatasetCreator datasetCreator = buildDatasetCreator("TestFirstName", "TestLastName", "TestEmailName", "0673579007", result);
DatasetCreator datasetCreator = buildDatasetCreator("TestFullName", "TestEmailName", "0673579007", result);
datasetCreator = datasetCreatorService.createDatasetCreator(result.getUuid(), datasetCreator);
datasetCreator.setInstituteAddress("TEST FAX");
DatasetCreator updated = datasetCreatorService.updateDatasetCreator(datasetCreator);
......@@ -75,7 +75,7 @@ public class DatasetCreatorServiceTest extends AbstractDatasetServiceTest {
@Test
public void removeDatasetCreator() throws Exception {
Dataset result = buildAndSaveDataset(DATASET_TITLE_1, DATASET_DESCRIPTION_1, partner, false);
DatasetCreator datasetCreator = buildDatasetCreator("TestFirstName", "TestLastName", "TestEmailName", "0673579007", result);
DatasetCreator datasetCreator = buildDatasetCreator("TestFullName", "TestEmailName", "0673579007", result);
DatasetCreator creator = datasetCreatorService.createDatasetCreator(result.getUuid(), datasetCreator);
assertThat(creator.getDataset().getUuid().toString(), equalTo(result.getUuid().toString()));
datasetCreatorService.removeDatasetCreator(result.getUuid(), creator);
......@@ -85,10 +85,10 @@ public class DatasetCreatorServiceTest extends AbstractDatasetServiceTest {
@Test
public void listDatasetCreators() throws Exception {
Dataset result = buildAndSaveDataset(DATASET_TITLE_1, DATASET_DESCRIPTION_1, partner, false);
DatasetCreator datasetCreator = buildDatasetCreator("TestFirstName", "TestLastName", "TestEmailName", "0673579007", result);
DatasetCreator datasetCreator = buildDatasetCreator("TestFullName", "TestEmailName", "0673579007", result);
DatasetCreator creator = datasetCreatorService.createDatasetCreator(result.getUuid(), datasetCreator);
String[] strs = new String[] { "firstName" };
String[] strs = new String[] { "fullName" };
Pageable pageable = new PageRequest(0, Integer.min(50, 100), Sort.Direction.ASC, strs);
Page page = datasetCreatorService.listDatasetCreators(result.getUuid(), pageable);
......@@ -100,18 +100,18 @@ public class DatasetCreatorServiceTest extends AbstractDatasetServiceTest {
@Test
public void loadDatasetCreators() throws Exception {
Dataset result = buildAndSaveDataset(DATASET_TITLE_1, DATASET_DESCRIPTION_1, partner, false);
DatasetCreator datasetCreator = buildDatasetCreator("TestFirstName", "TestLastName", "TestEmailName", "0673579007", result);
DatasetCreator datasetCreator = buildDatasetCreator("TestFullName", "TestEmailName", "0673579007", result);
datasetCreatorService.createDatasetCreator(result.getUuid(), datasetCreator);
List<DatasetCreator> creator = datasetCreatorService.loadDatasetCreators(result.getUuid());
assertThat(creator, not(empty()));
assertThat(creator.size(),is(1));
assertThat(creator.get(0).getFirstName(),is("TestFirstName"));
assertThat(creator.get(0).getFullName(),is("TestFullName"));
}
@Test(expected = NotFoundElement.class)
public void failLoadDatasetCreator() throws NotFoundElement {
Dataset result = buildAndSaveDataset(DATASET_TITLE_1, DATASET_DESCRIPTION_1, partner, false);
DatasetCreator datasetCreator = buildDatasetCreator("TestFirstName", "TestLastName", "TestEmailName", "0673579007", result);
DatasetCreator datasetCreator = buildDatasetCreator("TestFullName", "TestEmailName", "0673579007", result);
datasetCreatorService.createDatasetCreator(result.getUuid(), datasetCreator);
datasetCreator.setUuid(UUID.randomUUID());
datasetCreatorService.loadDatasetCreator(datasetCreator);
......@@ -120,7 +120,7 @@ public class DatasetCreatorServiceTest extends AbstractDatasetServiceTest {
@Test(expected = ConcurrencyFailureException.class)
public void failLoadDatasetCreator2() throws NotFoundElement {
Dataset result = buildAndSaveDataset(DATASET_TITLE_1, DATASET_DESCRIPTION_1, partner, false);
DatasetCreator datasetCreator = buildDatasetCreator("TestFirstName", "TestLastName", "TestEmailName", "0673579007", result);
DatasetCreator datasetCreator = buildDatasetCreator("TestFullName", "TestEmailName", "0673579007", result);
datasetCreatorService.createDatasetCreator(result.getUuid(), datasetCreator);
datasetCreator.setVersion(10);
datasetCreatorService.loadDatasetCreator(datasetCreator);
......
......@@ -3047,3 +3047,41 @@ databaseChangeLog:
onUpdate: NO ACTION
referencedColumnNames: id
referencedTableName: descriptor
- changeSet:
id: 1516008352285-1
author: mborodenko
comment: Add full_name column to Datasetcreator
changes:
- addColumn:
columns:
- column:
constraints:
nullable: false
name: full_name
type: VARCHAR(200)
tableName: datasetcreator
- sql:
comment: Set blank space if first_name column is null
sql: >-
update datasetcreator set first_name = ' ' where first_name is null;
- sql:
comment: Set blank space if last_name column is null
sql: >-
update datasetcreator set last_name = ' ' where last_name is null;
- sql:
comment: Generate data from first_name and last_name columns
sql: >-
update datasetcreator set full_name = trim(concat(first_name, ' ', last_name));
- changeSet:
id: 1516008352285-2
author: mborodenko
comment: Removing obsolete columns first_name and last_name
changes:
- dropColumn:
columnName: first_name
tableName: datasetcreator
- dropColumn:
columnName: last_name
tableName: datasetcreator
......@@ -58,7 +58,7 @@ public class DatasetCreatorControllerTest extends AbstractDatasetControllerTest
@WithMockOAuth2Authentication(roles = { "ADMINISTRATOR" }, scopes = { "write" })
public void listDatasetCreators() throws Exception {
Dataset dataset = datasetService.createDataset(setUpDataset(false));
DatasetCreator datasetCreator = buildDatasetCreator("TestFirstName", "TestLastName", "TestEmailName", "0673579007", dataset);
DatasetCreator datasetCreator = buildDatasetCreator("TestFullName", "TestEmailName", "0673579007", dataset);
DatasetCreator creator = datasetCreatorService.createDatasetCreator(dataset.getUuid(), datasetCreator);
this.mockMvc.perform(RestDocumentationRequestBuilders.get(DatasetCreatorController.API_BASE.concat("/list"), dataset.getUuid()))
......@@ -72,7 +72,7 @@ public class DatasetCreatorControllerTest extends AbstractDatasetControllerTest
@Test
public void loadByUuid() throws Exception {
Dataset dataset = datasetService.createDataset(setUpDataset(true));
DatasetCreator datasetCreator = buildDatasetCreator("TestFirstName", "TestLastName", "TestEmailName", "0673579007", dataset);
DatasetCreator datasetCreator = buildDatasetCreator("TestFullName", "TestEmailName", "0673579007", dataset);
DatasetCreator creator = datasetCreatorService.createDatasetCreator(dataset.getUuid(), datasetCreator);
this.mockMvc.perform(RestDocumentationRequestBuilders.get(DatasetCreatorController.API_BASE.concat("/{creatorUuid}"), dataset.getUuid(),
......@@ -88,7 +88,7 @@ public class DatasetCreatorControllerTest extends AbstractDatasetControllerTest
@WithMockOAuth2Authentication(roles = { "ADMINISTRATOR" }, scopes = { "write" })
public void createDatasetCreator() throws Exception {
Dataset dataset = datasetService.createDataset(setUpDataset(false));
DatasetCreator datasetCreator = buildDatasetCreator("TestFirstName", "TestLastName", "TestEmailName", "0673579007", dataset);
DatasetCreator datasetCreator = buildDatasetCreator("TestFullName", "TestEmailName", "0673579007", dataset);
String s = verboseMapper.writeValueAsString(datasetCreator);
......@@ -100,14 +100,14 @@ public class DatasetCreatorControllerTest extends AbstractDatasetControllerTest
.andExpect(status().isOk())
.andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8))
.andExpect(jsonPath("$", not(nullValue())))
.andExpect(jsonPath("$.firstName", equalTo(datasetCreator.getFirstName())));
.andExpect(jsonPath("$.fullName", equalTo(datasetCreator.getFullName())));
}
@Test
@WithMockOAuth2Authentication(roles = { "ADMINISTRATOR" }, scopes = { "write" })
public void deleteDatasetCreator() throws Exception {
Dataset dataset = datasetService.createDataset(setUpDataset(false));
DatasetCreator datasetCreator = buildDatasetCreator("TestFirstName", "TestLastName", "TestEmailName", "0673579007", dataset);
DatasetCreator datasetCreator = buildDatasetCreator("TestFullName", "TestEmailName", "0673579007", dataset);
DatasetCreator creator = datasetCreatorService.createDatasetCreator(dataset.getUuid(), datasetCreator);
String s = verboseMapper.writeValueAsString(creator);
......@@ -120,11 +120,10 @@ public class DatasetCreatorControllerTest extends AbstractDatasetControllerTest
.andExpect(status().isOk());
}
protected DatasetCreator buildDatasetCreator(String firstName, String lastName, String email, String phoneNumber, Dataset dataset){
protected DatasetCreator buildDatasetCreator(String fullName, String email, String phoneNumber, Dataset dataset){
DatasetCreator datasetCreator = new DatasetCreator();
datasetCreator.setDataset(dataset);
datasetCreator.setFirstName(firstName);
datasetCreator.setLastName(lastName);
datasetCreator.setFullName(fullName);
datasetCreator.setRole(DatasetCreator.DatasetCreatorRole.CONTACT);
datasetCreator.setEmail(email);
datasetCreator.setPhoneNumber(phoneNumber);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment