Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[AAE-15727] add and modify columns for name in project table #1178

Draft
wants to merge 4 commits into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
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 @@ -50,7 +50,7 @@ public static ModelingNamingIdentifier<Project> projectNamed(String name) {
return new ModelingNamingIdentifier<Project>(name) {
@Override
protected String getName(Project project) {
return project.getName();
return project.getTechnicalName();
Copy link
Contributor

Choose a reason for hiding this comment

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

The step to renaming the getTechnicalName that is not the final name yet should be done in the end Why it's already here?

}
};
}
Expand All @@ -59,7 +59,7 @@ public static ModelingNamingIdentifier projectsNamed(List<String> names) {
return new ModelingNamingIdentifier<Project>(names) {
@Override
protected String getName(Project project) {
return project.getName();
return project.getTechnicalName();
}
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public void checkCurrentProjects(List<String> expectedNames) {
assertThat(
modelingContextHandler
.getCurrentProjects()
.map(resources -> resources.stream().map(EntityModel::getContent).map(Project::getName))
.map(resources -> resources.stream().map(EntityModel::getContent).map(Project::getTechnicalName))
.orElseGet(Stream::empty)
.collect(Collectors.toList())
)
Expand All @@ -84,15 +84,15 @@ public void checkCurrentProjects(List<String> expectedNames) {
@Step
public EntityModel<Project> create(String projectName) {
Project project = mock(Project.class);
doReturn(projectName).when(project).getName();
doReturn(projectName).when(project).getTechnicalName();
return create(project);
}

@Step
public void updateProjectName(String newProjectName) {
EntityModel<Project> currentContext = checkAndGetCurrentContext(Project.class);
Project project = currentContext.getContent();
project.setName(newProjectName);
project.setTechnicalName(newProjectName);

modelingProjectService.updateByUri(modelingUri(currentContext.getLink(SELF).get().getHref()), project);
}
Expand All @@ -101,7 +101,7 @@ public void updateProjectName(String newProjectName) {
public void checkCurrentProjectName(String projectName) {
updateCurrentModelingObject();
EntityModel<Project> currentContext = checkAndGetCurrentContext(Project.class);
assertThat(currentContext.getContent().getName()).isEqualTo(projectName);
assertThat(currentContext.getContent().getTechnicalName()).isEqualTo(projectName);
}

@Step
Expand Down Expand Up @@ -172,11 +172,11 @@ public void checkExportedProjectContainsModel(
assertThat(modelingContextHandler.getCurrentModelingFile())
.hasValueSatisfying(fileContent ->
assertThatFileContent(fileContent)
.hasName(currentProject.getName() + ".zip")
.hasName(currentProject.getTechnicalName() + ".zip")
.hasContentType(ContentTypeUtils.CONTENT_TYPE_ZIP)
.isZip()
.hasEntries(
changeToJsonFilename(currentProject.getName()),
changeToJsonFilename(currentProject.getTechnicalName()),
modelType.getFolderName() + "/",
modelType.getFolderName() +
"/" +
Expand All @@ -186,8 +186,8 @@ public void checkExportedProjectContainsModel(
changeExtension(modelName, modelType.getContentFileExtension())
)
.hasJsonContentSatisfying(
changeToJsonFilename(currentProject.getName()),
jsonContent -> jsonContent.node("name").isEqualTo(currentProject.getName())
changeToJsonFilename(currentProject.getTechnicalName()),
jsonContent -> jsonContent.node("name").isEqualTo(currentProject.getTechnicalName())
)
.hasJsonContentSatisfying(
modelType.getFolderName() +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,11 @@ public class ProjectImpl extends AbstractAuditable<String> implements Project<St
@Schema(description = "The unique identifier of the project", readOnly = true)
private String id;

@Schema(description = "The name of the project")
private String name;
@Schema(description = "The technical name of the project")
private String technicalName;

@Schema(description = "The display name of the project")
private String displayName;

@Schema(description = "The description of the project")
private String description;
Expand All @@ -47,7 +50,7 @@ public ProjectImpl() {}

public ProjectImpl(String id, String name) {
this.id = id;
this.name = name;
setName(name);
}

@Override
Expand All @@ -62,12 +65,35 @@ public void setId(String id) {

@Override
public String getName() {
return name;
return getTechnicalName();
}

@Override
public void setName(String name) {
this.name = name;
setTechnicalName(name);

//TODO: Modify temporary code that sets display name same as technical name
setDisplayName(name);
}
Comment on lines 72 to +77
Copy link
Contributor

Choose a reason for hiding this comment

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

I will leave just a comment since I will be off after today and I don't want to block the PR.
I think we should not set both names here, but just delegate to setTechnicalName. If it is required to set also the display name, I think it would be better doing it in another place to avoid having issues when get/set name will be deleted.
In addition, it would be easier implementing getName and setName with a default implementation in the interfaces to avoid repeating the same behavior.


@Override
public String getTechnicalName() {
return technicalName;
}

@Override
public void setTechnicalName(String technicalName) {
this.technicalName = technicalName;
}

@Override
public String getDisplayName() {
return displayName;
}

@Override
public void setDisplayName(String name) {
this.displayName = name;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,14 @@ public interface Project<U> extends Auditable<U> {

void setName(String name);

String getTechnicalName();

void setTechnicalName(String name);

String getDisplayName();

void setDisplayName(String name);

String getVersion();

void setVersion(String version);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonInclude;
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.Id;
Expand All @@ -36,7 +37,7 @@
/**
* Project model entity
*/
@Table(name = "Project", uniqueConstraints = @UniqueConstraint(columnNames = { "name", "createdBy" }))
@Table(name = "Project", uniqueConstraints = @UniqueConstraint(columnNames = { "tech_name", "createdBy" }))
@Entity(name = "Project")
@JsonIgnoreProperties(ignoreUnknown = true)
@JsonInclude(NON_NULL)
Expand All @@ -51,7 +52,11 @@ public class ProjectEntity extends AuditableEntity<String> implements Project<St
@GenericGenerator(name = "system-uuid", strategy = "uuid2")
private String id;

private String name;
@Column(name = "tech_name", nullable = false)
private String technicalName;

@Column(name = "disp_name", nullable = false)
private String displayName;

private String description;

Expand All @@ -60,7 +65,7 @@ public class ProjectEntity extends AuditableEntity<String> implements Project<St
public ProjectEntity() {} // for JPA

public ProjectEntity(String name) {
this.name = name;
setName(name);
}

@Override
Expand All @@ -83,12 +88,35 @@ public void setModels(Set<ModelEntity> models) {

@Override
public String getName() {
return name;
return getTechnicalName();
}

@Override
public void setName(String name) {
this.name = name;
setTechnicalName(name);

//TODO: Modify temporary code that sets display name same as technical name
setDisplayName(name);
}

@Override
public String getTechnicalName() {
return technicalName;
}

@Override
public void setTechnicalName(String technicalName) {
this.technicalName = technicalName;
}

@Override
public String getDisplayName() {
return displayName;
}

@Override
public void setDisplayName(String displayName) {
this.displayName = displayName;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,11 @@
exported = false
)
public interface ProjectJpaRepository extends JpaRepository<ProjectEntity, String>, ProjectRepository<ProjectEntity> {
Page<ProjectEntity> findAllByNameContaining(String name, Pageable pageable);
Page<ProjectEntity> findAllByTechnicalNameContaining(String name, Pageable pageable);

Page<ProjectEntity> findAllByIdIn(Collection<String> filteredProjectIds, Pageable pageable);

Page<ProjectEntity> findAllByNameContainingAndIdIn(
Page<ProjectEntity> findAllByTechnicalNameContainingAndIdIn(
String name,
Collection<String> filteredProjectIds,
Pageable pageable
Expand All @@ -48,9 +48,9 @@ Page<ProjectEntity> findAllByNameContainingAndIdIn(
@Override
default Page<ProjectEntity> getProjects(Pageable pageable, String nameToFilter, List<String> filteredProjectIds) {
if (nameToFilter != null && filteredProjectIds != null) {
return findAllByNameContainingAndIdIn(nameToFilter, filteredProjectIds, pageable);
return findAllByTechnicalNameContainingAndIdIn(nameToFilter, filteredProjectIds, pageable);
} else if (nameToFilter != null) {
return findAllByNameContaining(nameToFilter, pageable);
return findAllByTechnicalNameContaining(nameToFilter, pageable);
} else if (filteredProjectIds != null) {
return findAllByIdIn(filteredProjectIds, pageable);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public void setUp() {
repository = new ModelRepositoryImpl(modelJpaRepository);
project = new ProjectEntity();
project.setId("testProjectId");
project.setName("testProjectName");
project.setTechnicalName("testProjectName");
model = new ModelEntity();
model.setId("testModelId");
model.setName("testNameId");
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
* Copyright 2017-2020 Alfresco Software, Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

ALTER TABLE project
ADD COLUMN disp_name varchar(255);

UPDATE project p
SET disp_name = p.name;

ALTER TABLE project
ALTER COLUMN disp_name SET NOT NULL;

ALTER TABLE project
RENAME COLUMN name TO tech_name;

ALTER TABLE project
ALTER COLUMN tech_name SET NOT NULL;
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ create table project
last_modified_by varchar(255),
last_modified_date timestamp,
description varchar(255),
name varchar(255),
tech_name varchar(255) not null,
disp_name varchar(255) not null,
version varchar(255),
primary key (id)
);
Expand All @@ -54,7 +55,7 @@ create table project_models
alter table model_versions
add constraint UK_ei9juhk09r20q4bmvgpjrcrs3 unique (versions_version, versions_versioned_entity_id);
alter table project
add constraint unique_project_name_createdby unique (name, created_by);
add constraint unique_project_name_createdby unique (tech_name, created_by);
alter table model
add constraint FKqjpgrrtoo1bryor3iymmb03pu foreign key (latest_version_version, latest_version_versioned_entity_id) references model_version;
alter table model_versions
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,4 +67,13 @@
splitStatements="true"
stripComments="true"/>
</changeSet>

<changeSet id="project-name-alter" author="aae-modeling">
<sqlFile dbms="postgresql"
encoding="utf8"
path="changelog/05.pg.update.sql"
relativeToChangelogFile="true"
splitStatements="true"
stripComments="true" />
</changeSet>
</databaseChangeLog>
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ public ProjectPayloadValidator(boolean validateRequiredFields) {

@Override
public void validatePayload(Project project, Errors errors) {
if (validateRequiredFields || project.getName() != null) {
validateDNSName(project.getName(), "project")
if (validateRequiredFields || project.getTechnicalName() != null) {
validateDNSName(project.getTechnicalName(), "project")
.forEach(error -> errors.rejectValue("name", error.getErrorCode(), error.getDescription()));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ public void should_returnStatusCreated_when_importingProjectWithExistingNameCrea
.andExpect(status().isCreated());

assertThat((Page<ProjectEntity>) projectRepository.getProjects(Pageable.ofSize(50), null, null))
.extracting(ProjectEntity::getCreatedBy, ProjectEntity::getName)
.extracting(ProjectEntity::getCreatedBy, ProjectEntity::getTechnicalName)
.contains(tuple("otherUser", "application-xy"), tuple("testuser", "application-xy"));
}

Expand All @@ -129,7 +129,7 @@ public void should_returnStatusCreated_when_creatingProjectWithExistingNameCreat
.andExpect(status().isCreated());

assertThat((Page<ProjectEntity>) projectRepository.getProjects(Pageable.ofSize(50), null, null))
.extracting(ProjectEntity::getCreatedBy, ProjectEntity::getName)
.extracting(ProjectEntity::getCreatedBy, ProjectEntity::getTechnicalName)
.contains(tuple("otherUser", "creating-project"), tuple("testuser", "creating-project"));
}

Expand All @@ -149,7 +149,7 @@ public void should_returnStatusOk_when_updatingProjectWithExistingNameCreatedByO
.andExpect(status().isOk());

assertThat((Page<ProjectEntity>) projectRepository.getProjects(Pageable.ofSize(50), null, null))
.extracting(ProjectEntity::getCreatedBy, ProjectEntity::getName)
.extracting(ProjectEntity::getCreatedBy, ProjectEntity::getTechnicalName)
.contains(tuple("otherUser", "updating-project"), tuple("testuser", "updating-project"));
}

Expand All @@ -165,7 +165,7 @@ public void should_returnStatusOk_when_copyingProjectWithExistingNameCreatedByOt
.andExpect(status().isOk());

assertThat((Page<ProjectEntity>) projectRepository.getProjects(Pageable.ofSize(50), null, null))
.extracting(ProjectEntity::getCreatedBy, ProjectEntity::getName)
.extracting(ProjectEntity::getCreatedBy, ProjectEntity::getTechnicalName)
.contains(tuple("otherUser", "copying-project"), tuple("testuser", "copying-project"));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ public void should_returnStatusOk_when_updatingExistingProject() throws Exceptio

assertThat((Optional<Project>) projectRepository.findProjectById(project.getId()))
.hasValueSatisfying(updatedProject -> {
assertThat(updatedProject.getName()).isEqualTo("updated-project-name");
assertThat(updatedProject.getTechnicalName()).isEqualTo("updated-project-name");
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public String getId() {
}

public String getName() {
return project.getName();
return project.getTechnicalName();
}

public String getVersion() {
Expand Down
Loading