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

Fixing Material Receipt Candidates -> Create Material Receipt error #1402

Merged
merged 1 commit into from
Apr 8, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
33 changes: 26 additions & 7 deletions src/main/java/de/metas/ui/web/process/ProcessId.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,12 @@ public static ProcessId of(final String processHandlerType, final String process
return new ProcessId(processHandlerType, processId);
}

public static final ProcessId ofAD_Process_ID(final int adProcessId)
public static ProcessId ofAD_Process_ID(final int adProcessId)
{
return new ProcessId(PROCESSHANDLERTYPE_AD_Process, adProcessId);
}

public static final ProcessId ofAD_Process_ID(@NonNull final AdProcessId adProcessId)
public static ProcessId ofAD_Process_ID(@NonNull final AdProcessId adProcessId)
{
return new ProcessId(PROCESSHANDLERTYPE_AD_Process, adProcessId.getRepoId());
}
Expand All @@ -72,8 +72,6 @@ public static final ProcessId ofAD_Process_ID(@NonNull final AdProcessId adProce
@JsonCreator
private ProcessId(final String json)
{
super();

Preconditions.checkArgument(json != null && !json.isEmpty(), "invalid ProcessId json: %s", json);

this.json = json;
Expand Down Expand Up @@ -147,11 +145,32 @@ public int getProcessIdAsInt()

public AdProcessId toAdProcessId()
{
if (!PROCESSHANDLERTYPE_AD_Process.contentEquals(getProcessHandlerType()))
final AdProcessId adProcessId = toAdProcessIdOrNull();
if (adProcessId == null)
{
throw new AdempiereException("Cannot convert " + this + " to " + AdProcessId.class.getSimpleName() + " because the processHanderType=" + processHandlerType + " is not supported");
}
return adProcessId;
}

/**
* Convenience method to get the {@link AdProcessId} for this instance if its {@code processIdAsInt} member is set and/or if {@link #getProcessHandlerType()} is {@value #PROCESSHANDLERTYPE_AD_Process}.
* {@code null} otherwise.
*/
public AdProcessId toAdProcessIdOrNull()
{
if (this.processIdAsInt > 0) // was set by the creator of this instance
{
return AdProcessId.ofRepoId(this.processIdAsInt);
}
else if (PROCESSHANDLERTYPE_AD_Process.contentEquals(getProcessHandlerType())) // can be derived via standard handler type
{
return AdProcessId.ofRepoId(getProcessIdAsInt());
}
else // nothing we can do here
{
throw new AdempiereException("Cannot convert " + this + " to " + AdProcessId.class.getSimpleName() + " because the processHanderType is not " + PROCESSHANDLERTYPE_AD_Process);
return null;
}
return AdProcessId.ofRepoId(getProcessIdAsInt());
}

public DocumentId toDocumentId()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ public boolean isEnabled()

public boolean isEnabledOrNotSilent()
{
try (final MDCCloseable processMDC = TableRecordMDC.putTableRecordReference(I_AD_Process.Table_Name, processId.toAdProcessId()))
try (final MDCCloseable processMDC = TableRecordMDC.putTableRecordReference(I_AD_Process.Table_Name, processId == null ? null : processId.toAdProcessIdOrNull()))
{
final ProcessPreconditionsResolution preconditionsResolution = getPreconditionsResolution();
return preconditionsResolution.isAccepted() || !preconditionsResolution.isInternal();
Expand Down