Skip to content

Commit

Permalink
#1197 Introduce AdempiereException setParameter/getParameters
Browse files Browse the repository at this point in the history
  • Loading branch information
teosarca committed Mar 25, 2017
1 parent 1e5eac9 commit 4b6f187
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 68 deletions.
Original file line number Diff line number Diff line change
@@ -1,29 +1,5 @@
package org.compiere.acct;

/*
* #%L
* de.metas.adempiere.adempiere.base
* %%
* Copyright (C) 2015 metas GmbH
* %%
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as
* published by the Free Software Foundation, either version 2 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public
* License along with this program. If not, see
* <http://www.gnu.org/licenses/gpl-2.0.html>.
* #L%
*/


import java.util.LinkedHashMap;
import java.util.Map;

import org.adempiere.exceptions.AdempiereException;
Expand Down Expand Up @@ -56,7 +32,6 @@ public final class PostingException extends AdempiereException
private String _detailMessage;
private boolean _preserveDocumentPostedStatus = false;
private Level _logLevel = Level.ERROR;
private final Map<String, Object> parameters = new LinkedHashMap<>();

public PostingException(final Doc document)
{
Expand Down Expand Up @@ -135,6 +110,7 @@ protected String buildMessage()
message.append("\n Preserve Posted status: ").append(isPreserveDocumentPostedStatus());

// Other parameters
final Map<String, Object> parameters = getParameters();
for (final Map.Entry<String, Object> param : parameters.entrySet())
{
final String parameterName = param.getKey();
Expand Down Expand Up @@ -315,10 +291,10 @@ public Level getLogLevel()
return _logLevel;
}

@Override
public PostingException setParameter(final String parameterName, Object parameterValue)
{
parameters.put(parameterName, parameterValue);
resetMessageBuilt();
super.setParameter(parameterName, parameterValue);
return this;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,14 @@

import java.lang.reflect.InvocationTargetException;
import java.sql.SQLException;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Properties;
import java.util.concurrent.ExecutionException;
import java.util.function.Supplier;

import javax.annotation.OverridingMethodsMustInvokeSuper;

import org.adempiere.ad.service.IDeveloperModeBL;
import org.adempiere.util.Services;
import org.adempiere.util.api.IMsgBL;
Expand All @@ -27,6 +31,8 @@
import org.compiere.util.Language;
import org.slf4j.Logger;

import com.google.common.collect.ImmutableMap;

import ch.qos.logback.classic.Level;
import de.metas.logging.MetasfreshLastError;

Expand Down Expand Up @@ -157,6 +163,8 @@ public static final void suppressOrThrow(final Throwable exceptionToSuppress, fi
private String _messageBuilt = null;

private Integer adIssueId = null;

private Map<String, Object> parameters = null;

/**
* Default Constructor (saved logger error will be used as message)
Expand Down Expand Up @@ -265,6 +273,7 @@ protected final String getOriginalMessage()
*/
protected String buildMessage()
{
// NOTE: by default we are not appending the parameterss
return super.getMessage();
}

Expand Down Expand Up @@ -417,4 +426,27 @@ public final boolean isIssueReported()
// NOTE: we consider it as issue reported even if the AD_Issue_ID <= 0
return adIssueId != null;
}

@OverridingMethodsMustInvokeSuper
public AdempiereException setParameter(final String name, final Object value)
{
if (parameters == null)
{
parameters = new LinkedHashMap<>();
}

parameters.put(name, value);
resetMessageBuilt();

return this;
}

public final Map<String, Object> getParameters()
{
if(parameters == null)
{
return ImmutableMap.of();
}
return ImmutableMap.copyOf(parameters);
}
}
Original file line number Diff line number Diff line change
@@ -1,29 +1,5 @@
package org.adempiere.server.rpl.exceptions;

/*
* #%L
* de.metas.adempiere.adempiere.base
* %%
* Copyright (C) 2015 metas GmbH
* %%
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as
* published by the Free Software Foundation, either version 2 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public
* License along with this program. If not, see
* <http://www.gnu.org/licenses/gpl-2.0.html>.
* #L%
*/


import java.util.HashMap;
import java.util.Map;

import org.adempiere.exceptions.AdempiereException;
Expand All @@ -43,7 +19,6 @@ public class ReplicationException extends AdempiereException
private static final long serialVersionUID = 8608172237424907859L;

private final String adMessage;
private final Map<String, Object> params = new HashMap<String, Object>();
private final Throwable cause;

/**
Expand Down Expand Up @@ -71,18 +46,23 @@ public ReplicationException(final String adMessage, final Throwable cause)
this.cause = cause;
}

public ReplicationException addParameter(final String parameterName, final Object value)
@Override
public ReplicationException setParameter(final String parameterName, final Object value)
{
params.put(parameterName, value);
resetMessageBuilt();
setParameter(parameterName, value);
return this;
}

public ReplicationException addParameter(final String parameterName, final Object value)
{
return setParameter(parameterName, value);
}

@Override
protected String buildMessage()
{
final StringBuilder sbParams = new StringBuilder();
for (final Map.Entry<String, Object> e : params.entrySet())
for (final Map.Entry<String, Object> e : getParameters().entrySet())
{
final String name = Services.get(IMsgBL.class).translate(getCtx(), e.getKey());
final Object value = e.getValue();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@


import java.util.Arrays;
import java.util.LinkedHashMap;
import java.util.Map;

import javax.annotation.OverridingMethodsMustInvokeSuper;
Expand Down Expand Up @@ -53,8 +52,6 @@ public abstract class LockException extends AdempiereException
private Object[] sqlParams;
private ITableRecordReference record;

private Map<String, Object> parameters = null;

public LockException(final String message)
{
super(message);
Expand Down Expand Up @@ -86,7 +83,8 @@ protected final String buildMessage()
message.append("\n SQL Params: ").append(Arrays.asList(sqlParams));
}

if (parameters != null)
final Map<String, Object> parameters = getParameters();
if (!parameters.isEmpty())
{
for (final Map.Entry<String, Object> paramName2Value : parameters.entrySet())
{
Expand Down Expand Up @@ -114,17 +112,11 @@ public LockException setRecord(final ITableRecordReference record)
return this;
}

@Override
@OverridingMethodsMustInvokeSuper
public LockException setParameter(final String name, final Object value)
{
if (parameters == null)
{
parameters = new LinkedHashMap<>();
}

parameters.put(name, value);
resetMessageBuilt();

super.setParameter(name, value);
return this;
}
}

0 comments on commit 4b6f187

Please sign in to comment.