Skip to content
Snippets Groups Projects
Commit f782963c authored by Felix Reichenbach's avatar Felix Reichenbach
Browse files

OZG-7515 remove comand objects from migration

parent 0657c181
No related branches found
No related tags found
1 merge request!11Ozg 7515 migrate patch item command
......@@ -25,13 +25,13 @@ package de.ozgcloud.vorgang.common.migration;
import java.util.List;
import org.bson.Document;
import org.bson.types.ObjectId;
import org.springframework.data.mongodb.core.MongoOperations;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.data.mongodb.core.query.Update;
import de.ozgcloud.command.Command;
import de.ozgcloud.vorgang.command.PersistedCommand;
import io.mongock.api.annotations.ChangeUnit;
import io.mongock.api.annotations.Execution;
import io.mongock.api.annotations.RollbackExecution;
......@@ -39,6 +39,7 @@ import io.mongock.api.annotations.RollbackExecution;
@ChangeUnit(id = "2025-01-17 16:00:00 OZG-7515", order = "M014", author = "freichenbach", runAlways = true)
public class M014_AddItemNameBescheidToPatchAttachedItemCommand { // NOSONAR
private static final String COMMAND_COLLECTION_NAME = "command";
private static final String ORDER_FIELD = "order";
private static final String SEND_BESCHEID_ORDER = "SEND_BESCHEID";
private static final String PARENT_ID_FIELD = "bodyObject.parentId";
......@@ -53,8 +54,9 @@ public class M014_AddItemNameBescheidToPatchAttachedItemCommand { // NOSONAR
}
List<String> getSendBescheidCommandIds(MongoOperations mongoOperations) {
var commands = mongoOperations.find(Query.query(Criteria.where(ORDER_FIELD).is(SEND_BESCHEID_ORDER)), PersistedCommand.class);
return commands.stream().map(Command::getId).toList();
var commands = mongoOperations.find(Query.query(Criteria.where(ORDER_FIELD).is(SEND_BESCHEID_ORDER)), Document.class,
COMMAND_COLLECTION_NAME);
return commands.stream().map(command -> command.getObjectId("_id")).map(ObjectId::toString).toList();
}
private void updateDocuments(MongoOperations mongoOperations, List<String> parentIds) {
......@@ -63,7 +65,7 @@ public class M014_AddItemNameBescheidToPatchAttachedItemCommand { // NOSONAR
Criteria.where(ORDER_FIELD).is(PATCH_ATTACHED_ITEM_ORDER),
Criteria.where(ITEM_NAME_FILED).exists(false)));
var update = new Update().set(ITEM_NAME_FILED, BESCHEID_ITEM_NAME);
mongoOperations.updateMulti(query, update, PersistedCommand.class);
mongoOperations.updateMulti(query, update, COMMAND_COLLECTION_NAME);
}
@RollbackExecution
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment