Skip to content

Commit

Permalink
[694] Ease change description creation from success
Browse files Browse the repository at this point in the history
Bug: #694
Signed-off-by: Guillaume Coutable <guillaume.coutable@obeo.fr>
  • Loading branch information
gcoutable committed Nov 9, 2021
1 parent 7c8d4d3 commit 5d63826
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 40 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,21 @@ public class Success implements IStatus {

private final Map<String, Object> parameters;

private final String changeKind;

public Success() {
this(new HashMap<>());
this("", new HashMap<>()); //$NON-NLS-1$
}

public Success(Map<String, Object> parameters) {
public Success(String changeKind, Map<String, Object> parameters) {
this.changeKind = Objects.requireNonNull(changeKind);
this.parameters = Objects.requireNonNull(parameters);
}

public String getChangeKind() {
return this.changeKind;
}

public Map<String, Object> getParameters() {
return this.parameters;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,22 +46,6 @@
@Service
public class DeleteListItemEventHandler implements IFormEventHandler {

/**
* The parameter key used to read from parameters {@link Success}, the change description parameter key used by the
* editing context event processor to get the object to delete.
*/
public static final String CHANGE_DESCRIPTION_PARAMETER_KEY = "change_description_parameter_key"; //$NON-NLS-1$

/**
* The parameter key used to read from parameters {@link Success}, the object id the deleted list item were holding.
*/
public static final String OBJECT_ID_TO_DELETE = "object_id"; //$NON-NLS-1$

/**
* The parameter key used to read from parameters {@link Success} the change kind to send through the sink.
*/
public static final String CHANGE_KIND = "change_kind"; //$NON-NLS-1$

private final ICollaborativeFormMessageService messageService;

private final Counter counter;
Expand Down Expand Up @@ -112,14 +96,8 @@ public void handle(One<IPayload> payloadSink, Many<ChangeDescription> changeDesc

if (status instanceof Success) {
Success success = (Success) status;
Object objectIdToDelete = success.getParameters().get(OBJECT_ID_TO_DELETE);
String changeIdParameterKey = (String) success.getParameters().get(CHANGE_DESCRIPTION_PARAMETER_KEY);
String changeKind = (String) success.getParameters().get(CHANGE_KIND);
if (objectIdToDelete != null && changeIdParameterKey != null && changeKind != null) {
changeDescription = new ChangeDescription(changeKind, formInput.getRepresentationId(), formInput);
changeDescription.addParameter(changeIdParameterKey, objectIdToDelete);
payload = new DeleteListItemSuccessPayload(formInput.getId());
}
changeDescription = new ChangeDescription(success.getChangeKind(), formInput.getRepresentationId(), formInput, success.getParameters());
payload = new DeleteListItemSuccessPayload(formInput.getId());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,18 +59,13 @@ public void testListItemDeletion() {
String changeDescriptionParameterKey = "change_description_parameter_key"; //$NON-NLS-1$

Map<String, Object> parameters = new HashMap<>();
parameters.put(DeleteListItemEventHandler.OBJECT_ID_TO_DELETE, listItemId);
parameters.put(DeleteListItemEventHandler.CHANGE_KIND, changeKind);
parameters.put(DeleteListItemEventHandler.CHANGE_DESCRIPTION_PARAMETER_KEY, changeDescriptionParameterKey);

parameters.put(changeDescriptionParameterKey, listItemId);
var input = new DeleteListItemInput(UUID.randomUUID(), FORM_ID, UUID.randomUUID(), listId, listItemId);

AtomicBoolean hasBeenExecuted = new AtomicBoolean();
Supplier<IStatus> deleteHandler = () -> {
hasBeenExecuted.set(true);
// @formatter:off
return new Success(parameters);
// @formatter:on
return new Success(changeKind, parameters);
};

// @formatter:off
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,17 @@ public class ChangeDescription {

private final IInput input;

private final Map<String, Object> parameters = new HashMap<>();
private final Map<String, Object> parameters;

public ChangeDescription(String kind, UUID sourceId, IInput input) {
this(kind, sourceId, input, new HashMap<>());
}

public ChangeDescription(String kind, UUID sourceId, IInput input, Map<String, Object> parameters) {
this.kind = Objects.requireNonNull(kind);
this.sourceId = Objects.requireNonNull(sourceId);
this.input = Objects.requireNonNull(input);
}

public Object addParameter(String key, Object value) {
return this.parameters.put(key, value);
this.parameters = Objects.requireNonNull(parameters);
}

public String getKind() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@
*/
public class EditingContextEventProcessor implements IEditingContextEventProcessor {

public static final String REPRESENTATION_ID = "representationId"; //$NON-NLS-1$

private final Logger logger = LoggerFactory.getLogger(EditingContextEventProcessor.class);

private final ICollaborativeMessageService messageService;
Expand Down Expand Up @@ -120,9 +122,9 @@ public EditingContextEventProcessor(ICollaborativeMessageService messageService,

private Disposable setupChangeDescriptionSinkConsumer() {
Consumer<ChangeDescription> consumer = changeDescription -> {

if (ChangeKind.REPRESENTATION_TO_DELETE.equals(changeDescription.getKind())) {
Object representationId = changeDescription.getParameters().get("representationId"); //$NON-NLS-1$
Object representationId = changeDescription.getParameters().get(REPRESENTATION_ID);
if (representationId instanceof UUID) {
DeleteRepresentationInput deleteRepresentationInput = new DeleteRepresentationInput(UUID.randomUUID(), (UUID) representationId);
this.doHandle(Sinks.one(), deleteRepresentationInput);
Expand Down

0 comments on commit 5d63826

Please sign in to comment.