Skip to content

Commit

Permalink
[MODDICONV-380] Validate Job Profile with Modify action at Update (#56)
Browse files Browse the repository at this point in the history
  • Loading branch information
RomanChernetskyi authored May 21, 2024
1 parent f92ddeb commit ddd6d7a
Show file tree
Hide file tree
Showing 31 changed files with 905 additions and 562 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@
import org.folio.dao.PostgresClientFactory;
import org.folio.rest.jaxrs.model.ProfileAssociation;
import org.folio.rest.jaxrs.model.ProfileAssociationCollection;
import org.folio.rest.jaxrs.model.ProfileSnapshotWrapper;
import org.folio.rest.jaxrs.model.ProfileSnapshotWrapper.ContentType;
import org.folio.rest.jaxrs.model.ProfileType;
import org.folio.rest.jaxrs.model.ReactToType;
import org.folio.rest.persist.Criteria.Criteria;
import org.folio.rest.persist.Criteria.Criterion;
Expand All @@ -28,10 +27,10 @@
import static java.lang.String.format;
import static org.folio.dao.util.DaoUtil.constructCriteria;
import static org.folio.dao.util.DaoUtil.getCQLWrapper;
import static org.folio.rest.jaxrs.model.ProfileSnapshotWrapper.ContentType.ACTION_PROFILE;
import static org.folio.rest.jaxrs.model.ProfileSnapshotWrapper.ContentType.JOB_PROFILE;
import static org.folio.rest.jaxrs.model.ProfileSnapshotWrapper.ContentType.MAPPING_PROFILE;
import static org.folio.rest.jaxrs.model.ProfileSnapshotWrapper.ContentType.MATCH_PROFILE;
import static org.folio.rest.jaxrs.model.ProfileType.ACTION_PROFILE;
import static org.folio.rest.jaxrs.model.ProfileType.JOB_PROFILE;
import static org.folio.rest.jaxrs.model.ProfileType.MAPPING_PROFILE;
import static org.folio.rest.jaxrs.model.ProfileType.MATCH_PROFILE;

/**
* Generic implementation of the of the {@link ProfileAssociationDao}
Expand Down Expand Up @@ -72,14 +71,14 @@ public class CommonProfileAssociationDao implements ProfileAssociationDao {
}

@Override
public Future<String> save(ProfileAssociation entity, ContentType masterType, ContentType detailType, String tenantId) {
public Future<String> save(ProfileAssociation entity, ProfileType masterType, ProfileType detailType, String tenantId) {
Promise<String> promise = Promise.promise();
pgClientFactory.createInstance(tenantId).save(getAssociationTableName(masterType, detailType), entity.getId(), entity, promise);
return promise.future();
}

@Override
public Future<ProfileAssociationCollection> getAll(ContentType masterType, ContentType detailType, String tenantId) {
public Future<ProfileAssociationCollection> getAll(ProfileType masterType, ProfileType detailType, String tenantId) {
Promise<Results<ProfileAssociation>> promise = Promise.promise();
try {
String[] fieldList = {"*"};
Expand All @@ -94,7 +93,7 @@ public Future<ProfileAssociationCollection> getAll(ContentType masterType, Conte
}

@Override
public Future<Optional<ProfileAssociation>> getById(String id, ContentType masterType, ContentType detailType, String tenantId) {
public Future<Optional<ProfileAssociation>> getById(String id, ProfileType masterType, ProfileType detailType, String tenantId) {
Promise<Results<ProfileAssociation>> promise = Promise.promise();
try {
Criteria idCrit = constructCriteria(ID_FIELD, id);
Expand All @@ -109,7 +108,7 @@ public Future<Optional<ProfileAssociation>> getById(String id, ContentType maste
}

@Override
public Future<ProfileAssociation> update(ProfileAssociation entity, ProfileSnapshotWrapper.ContentType masterType, ProfileSnapshotWrapper.ContentType detailType, String tenantId) {
public Future<ProfileAssociation> update(ProfileAssociation entity, ProfileType masterType, ProfileType detailType, String tenantId) {
Promise<ProfileAssociation> promise = Promise.promise();
try {
Criteria idCrit = constructCriteria(ID_FIELD, entity.getId());
Expand All @@ -133,15 +132,15 @@ public Future<ProfileAssociation> update(ProfileAssociation entity, ProfileSnaps
}

@Override
public Future<Boolean> delete(String id, ProfileSnapshotWrapper.ContentType masterType, ProfileSnapshotWrapper.ContentType detailType, String tenantId) {
public Future<Boolean> delete(String id, ProfileType masterType, ProfileType detailType, String tenantId) {
Promise<RowSet<Row>> promise = Promise.promise();
pgClientFactory.createInstance(tenantId).delete(getAssociationTableName(masterType, detailType), id, promise);
return promise.future().map(updateResult -> updateResult.rowCount() == 1);
}

@Override
public Future<Boolean> delete(String masterWrapperId, String detailWrapperId, ProfileSnapshotWrapper.ContentType masterType,
ProfileSnapshotWrapper.ContentType detailType, String jobProfileId, ReactToType reactTo, Integer order, String tenantId) {
public Future<Boolean> delete(String masterWrapperId, String detailWrapperId, ProfileType masterType,
ProfileType detailType, String jobProfileId, ReactToType reactTo, Integer order, String tenantId) {
Promise<RowSet<Row>> promise = Promise.promise();
try {
CQLWrapper filter = getCQLWrapper(getAssociationTableName(masterType, detailType),
Expand All @@ -163,7 +162,7 @@ public Future<Boolean> delete(String masterWrapperId, String detailWrapperId, Pr
}

@Override
public Future<Boolean> deleteByMasterWrapperId(String wrapperId, ProfileSnapshotWrapper.ContentType masterType, ProfileSnapshotWrapper.ContentType detailType, String tenantId) {
public Future<Boolean> deleteByMasterWrapperId(String wrapperId, ProfileType masterType, ProfileType detailType, String tenantId) {
Promise<RowSet<Row>> promise = Promise.promise();
try {
CQLWrapper filter = getCQLWrapper(getAssociationTableName(masterType, detailType), "(" + MASTER_WRAPPER_ID_FIELD + "==" + wrapperId + ")");
Expand All @@ -176,8 +175,8 @@ public Future<Boolean> deleteByMasterWrapperId(String wrapperId, ProfileSnapshot
}

@Override
public Future<Boolean> deleteByMasterIdAndDetailId(String masterId, String detailId, ContentType masterType,
ContentType detailType, String tenantId) {
public Future<Boolean> deleteByMasterIdAndDetailId(String masterId, String detailId, ProfileType masterType,
ProfileType detailType, String tenantId) {
Promise<RowSet<Row>> promise = Promise.promise();
try {
/* Setting WHERE clause explicitly here because incorrect query is created by CQLWrapper by default due to
Expand All @@ -199,7 +198,7 @@ public Future<Boolean> deleteByMasterIdAndDetailId(String masterId, String detai
* @param detailType a detail type in association
* @return table name
*/
private String getAssociationTableName(ContentType masterType, ContentType detailType) {
private String getAssociationTableName(ProfileType masterType, ProfileType detailType) {
String associationTableName = associationTableNamesMap.get(masterType.value() + detailType.value());
if (associationTableName == null) {
String message = format("Invalid ProfileAssociation type with master type '%s' and detail type '%s'. ", masterType, detailType);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import io.vertx.core.Future;
import org.folio.rest.jaxrs.model.ProfileSnapshotWrapper;
import org.folio.rest.jaxrs.model.ProfileType;

import java.util.List;

Expand All @@ -21,7 +22,7 @@ public interface MasterDetailAssociationDao {
* @param tenantId tenant id
* @return a list of details for a master id
*/
Future<List<ProfileSnapshotWrapper>> getDetailProfilesByMasterId(String masterId, ProfileSnapshotWrapper.ContentType detailType, String query, int offset, int limit, String tenantId);
Future<List<ProfileSnapshotWrapper>> getDetailProfilesByMasterId(String masterId, ProfileType detailType, String query, int offset, int limit, String tenantId);

/**
* Returns master profiles linked to detail profile id
Expand All @@ -34,5 +35,5 @@ public interface MasterDetailAssociationDao {
* @param tenantId tenant id
* @return a list of masters for a detail id
*/
Future<List<ProfileSnapshotWrapper>> getMasterProfilesByDetailId(String detailId, ProfileSnapshotWrapper.ContentType masterType, String query, int offset, int limit, String tenantId);
Future<List<ProfileSnapshotWrapper>> getMasterProfilesByDetailId(String detailId, ProfileType masterType, String query, int offset, int limit, String tenantId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
import org.folio.rest.jaxrs.model.MappingProfile;
import org.folio.rest.jaxrs.model.MatchProfile;
import org.folio.rest.jaxrs.model.ProfileSnapshotWrapper;
import org.folio.rest.jaxrs.model.ProfileSnapshotWrapper.ContentType;
import org.folio.rest.jaxrs.model.ProfileType;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

Expand Down Expand Up @@ -52,7 +52,7 @@ public class MasterDetailAssociationDaoImpl implements MasterDetailAssociationDa
protected PostgresClientFactory pgClientFactory;

@Override
public Future<List<ProfileSnapshotWrapper>> getDetailProfilesByMasterId(String masterId, ContentType detailType, String query, int offset, int limit, String tenantId) {
public Future<List<ProfileSnapshotWrapper>> getDetailProfilesByMasterId(String masterId, ProfileType detailType, String query, int offset, int limit, String tenantId) {
SelectBuilder selectBuilder = new SelectBuilder(RETRIEVES_DETAILS_SQL)
.where()
.equals(MASTER_ID_FIELD, putInQuotes(masterId));
Expand All @@ -79,7 +79,7 @@ public Future<List<ProfileSnapshotWrapper>> getDetailProfilesByMasterId(String m
private List<ProfileSnapshotWrapper> mapToDetails(RowSet<Row> rowSet) {
List<ProfileSnapshotWrapper> wrappers = new ArrayList<>();
rowSet.forEach(row -> {
ContentType detailType = ContentType.fromValue(row.getString(DETAIL_TYPE_FIELD));
ProfileType detailType = ProfileType.fromValue(row.getString(DETAIL_TYPE_FIELD));
JsonObject detail = row.get(JsonArray.class, row.getColumnIndex(DETAIL_FIELD)).getJsonObject(0);
ProfileSnapshotWrapper wrapper = new ProfileSnapshotWrapper();
wrapper.setId(row.getUUID(DETAIL_ID_FIELD).toString());
Expand All @@ -98,7 +98,7 @@ private List<ProfileSnapshotWrapper> mapToDetails(RowSet<Row> rowSet) {
* @param contentType type of a profile.
* @return a profile instance.
*/
private Object mapProfile(JsonObject object, ContentType contentType) {
private Object mapProfile(JsonObject object, ProfileType contentType) {
switch (contentType) {
case JOB_PROFILE:
return object.mapTo(JobProfile.class);
Expand All @@ -115,7 +115,7 @@ private Object mapProfile(JsonObject object, ContentType contentType) {


@Override
public Future<List<ProfileSnapshotWrapper>> getMasterProfilesByDetailId(String detailId, ContentType masterType, String query, int offset, int limit, String tenantId) {
public Future<List<ProfileSnapshotWrapper>> getMasterProfilesByDetailId(String detailId, ProfileType masterType, String query, int offset, int limit, String tenantId) {
SelectBuilder selectBuilder = new SelectBuilder(RETRIEVES_MASTERS_SQL)
.where()
.equals(DETAIL_ID_FIELD, putInQuotes(detailId));
Expand All @@ -142,7 +142,7 @@ public Future<List<ProfileSnapshotWrapper>> getMasterProfilesByDetailId(String d
private List<ProfileSnapshotWrapper> mapToMasters(RowSet<Row> rowSet) {
List<ProfileSnapshotWrapper> wrappers = new ArrayList<>();
rowSet.forEach(row -> {
ContentType masterType = ContentType.fromValue(row.getString(MASTER_TYPE_FIELD));
ProfileType masterType = ProfileType.fromValue(row.getString(MASTER_TYPE_FIELD));
JsonObject master = row.get(JsonArray.class, row.getColumnIndex(MASTER_FIELD)).getJsonObject(0);
ProfileSnapshotWrapper wrapper = new ProfileSnapshotWrapper();
wrapper.setId(row.getUUID(MASTER_ID_FIELD).toString());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import io.vertx.core.Future;
import org.folio.rest.jaxrs.model.ProfileAssociation;
import org.folio.rest.jaxrs.model.ProfileAssociationCollection;
import org.folio.rest.jaxrs.model.ProfileSnapshotWrapper;
import org.folio.rest.jaxrs.model.ProfileType;
import org.folio.rest.jaxrs.model.ReactToType;

import java.util.Optional;
Expand All @@ -22,7 +22,7 @@ public interface ProfileAssociationDao {
* @param tenantId tenant id
* @return future
*/
Future<String> save(ProfileAssociation entity, ProfileSnapshotWrapper.ContentType masterType, ProfileSnapshotWrapper.ContentType detailType, String tenantId);
Future<String> save(ProfileAssociation entity, ProfileType masterType, ProfileType detailType, String tenantId);

/**
* Searches for ProfileAssociation by masterType and detailType
Expand All @@ -32,7 +32,7 @@ public interface ProfileAssociationDao {
* @param tenantId tenant id
* @return future with {@link ProfileAssociationCollection}
*/
Future<ProfileAssociationCollection> getAll(ProfileSnapshotWrapper.ContentType masterType, ProfileSnapshotWrapper.ContentType detailType, String tenantId);
Future<ProfileAssociationCollection> getAll(ProfileType masterType, ProfileType detailType, String tenantId);

/**
* Searches for ProfileAssociation entity by id
Expand All @@ -43,7 +43,7 @@ public interface ProfileAssociationDao {
* @param tenantId tenant id
* @return future with optional entity
*/
Future<Optional<ProfileAssociation>> getById(String id, ProfileSnapshotWrapper.ContentType masterType, ProfileSnapshotWrapper.ContentType detailType, String tenantId);
Future<Optional<ProfileAssociation>> getById(String id, ProfileType masterType, ProfileType detailType, String tenantId);

/**
* Updates ProfileAssociation entity in database
Expand All @@ -54,7 +54,7 @@ public interface ProfileAssociationDao {
* @param tenantId tenant id
* @return future with updated entity
*/
Future<ProfileAssociation> update(ProfileAssociation entity, ProfileSnapshotWrapper.ContentType masterType, ProfileSnapshotWrapper.ContentType detailType, String tenantId);
Future<ProfileAssociation> update(ProfileAssociation entity, ProfileType masterType, ProfileType detailType, String tenantId);

/**
* Deletes entity from database
Expand All @@ -65,7 +65,7 @@ public interface ProfileAssociationDao {
* @param tenantId tenant id
* @return future with true if succeeded
*/
Future<Boolean> delete(String id, ProfileSnapshotWrapper.ContentType masterType, ProfileSnapshotWrapper.ContentType detailType, String tenantId);
Future<Boolean> delete(String id, ProfileType masterType, ProfileType detailType, String tenantId);

/**
* Delete ProfileAssociation by masterWrapperId and detailWrapperId
Expand All @@ -80,8 +80,8 @@ public interface ProfileAssociationDao {
* @param tenantId - tenant id
* @return - boolean result of operation
*/
Future<Boolean> delete(String masterWrapperId, String detailWrapperId, ProfileSnapshotWrapper.ContentType masterType,
ProfileSnapshotWrapper.ContentType detailType, String jobProfileId, ReactToType reactTo, Integer order, String tenantId);
Future<Boolean> delete(String masterWrapperId, String detailWrapperId, ProfileType masterType,
ProfileType detailType, String jobProfileId, ReactToType reactTo, Integer order, String tenantId);

/**
* Delete profile associations for particular master profile by wrapperId
Expand All @@ -92,7 +92,7 @@ Future<Boolean> delete(String masterWrapperId, String detailWrapperId, ProfileSn
* @param tenantId - tenant id
* @return future with boolean
*/
Future<Boolean> deleteByMasterWrapperId(String wrapperId, ProfileSnapshotWrapper.ContentType masterType, ProfileSnapshotWrapper.ContentType detailType, String tenantId);
Future<Boolean> deleteByMasterWrapperId(String wrapperId, ProfileType masterType, ProfileType detailType, String tenantId);

/**
* Delete ProfileAssociation by masterWrapperId and detailWrapperId
Expand All @@ -104,6 +104,6 @@ Future<Boolean> delete(String masterWrapperId, String detailWrapperId, ProfileSn
* @param tenantId - tenant id
* @return - boolean result of operation
*/
Future<Boolean> deleteByMasterIdAndDetailId(String masterId, String detailId, ProfileSnapshotWrapper.ContentType masterType,
ProfileSnapshotWrapper.ContentType detailType, String tenantId);
Future<Boolean> deleteByMasterIdAndDetailId(String masterId, String detailId, ProfileType masterType,
ProfileType detailType, String tenantId);
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package org.folio.dao.snapshot;

import io.vertx.core.Future;
import org.folio.rest.jaxrs.model.ProfileAssociation;
import org.folio.rest.jaxrs.model.ProfileSnapshotWrapper;
import org.folio.rest.jaxrs.model.ProfileType;

import java.util.List;
import java.util.Optional;
Expand Down Expand Up @@ -29,13 +31,13 @@ public interface ProfileSnapshotDao {
Future<String> save(ProfileSnapshotWrapper entity, String tenantId);

/**
* Returns the list of snapshot items, listed in hierarchical order
* Returns the list of snapshot associations, listed in hierarchical order
*
* @param profileId profile uuid
* @param profileType profile type
* @param jobProfileId job profile uuid
* @param tenantId tenant id
* @return list of the snapshot items
*/
Future<List<ProfileSnapshotItem>> getSnapshotItems(String profileId, ProfileSnapshotWrapper.ContentType profileType, String jobProfileId, String tenantId);
Future<List<ProfileAssociation>> getSnapshotAssociations(String profileId, ProfileType profileType, String jobProfileId, String tenantId);
}
Loading

0 comments on commit ddd6d7a

Please sign in to comment.