Skip to content

Commit

Permalink
Fixing Material Receipt Candidates -> Create Material Receipt e… (#1402)
Browse files Browse the repository at this point in the history
  • Loading branch information
metas-ts committed Apr 8, 2020
1 parent c9e05f9 commit 68b92a5
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 8 deletions.
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

0 comments on commit 68b92a5

Please sign in to comment.