Details
diff --git a/util/src/main/java/com/ning/billing/util/callcontext/InternalCallContext.java b/util/src/main/java/com/ning/billing/util/callcontext/InternalCallContext.java
index 9f6da10..e79e5ca 100644
--- a/util/src/main/java/com/ning/billing/util/callcontext/InternalCallContext.java
+++ b/util/src/main/java/com/ning/billing/util/callcontext/InternalCallContext.java
@@ -28,7 +28,8 @@ import org.joda.time.DateTime;
public class InternalCallContext extends InternalTenantContext {
private final UUID userToken;
- private final String userName;
+ private final String createdBy;
+ private final String updatedBy;
private final CallOrigin callOrigin;
private final UserType userType;
private final String reasonCode;
@@ -41,7 +42,8 @@ public class InternalCallContext extends InternalTenantContext {
final DateTime createdDate, final DateTime updatedDate) {
super(tenantRecordId, accountRecordId);
this.userToken = userToken;
- this.userName = userName;
+ this.createdBy = userName;
+ this.updatedBy = userName;
this.callOrigin = callOrigin;
this.userType = userType;
this.reasonCode = reasonCode;
@@ -61,15 +63,19 @@ public class InternalCallContext extends InternalTenantContext {
// Unfortunately not true as some APIs ae hidden in object-- e.g OverdueStateApplicator is doing subscription.cancelWithPolicy(polciy, context);
//
public CallContext toCallContext() {
- return new DefaultCallContext(null, userName, callOrigin, userType, reasonCode, comment, userToken, createdDate, updatedDate);
+ return new DefaultCallContext(null, createdBy, callOrigin, userType, reasonCode, comment, userToken, createdDate, updatedDate);
}
public UUID getUserToken() {
return userToken;
}
- public String getUserName() {
- return userName;
+ public String getCreatedBy() {
+ return createdBy;
+ }
+
+ public String getUpdatedBy() {
+ return updatedBy;
}
public CallOrigin getCallOrigin() {
@@ -101,7 +107,8 @@ public class InternalCallContext extends InternalTenantContext {
final StringBuilder sb = new StringBuilder();
sb.append("InternalCallContext");
sb.append("{userToken=").append(userToken);
- sb.append(", userName='").append(userName).append('\'');
+ sb.append(", createdBy='").append(createdBy).append('\'');
+ sb.append(", updatedBy='").append(updatedBy).append('\'');
sb.append(", callOrigin=").append(callOrigin);
sb.append(", userType=").append(userType);
sb.append(", reasonCode='").append(reasonCode).append('\'');
@@ -132,16 +139,19 @@ public class InternalCallContext extends InternalTenantContext {
if (comment != null ? !comment.equals(that.comment) : that.comment != null) {
return false;
}
+ if (createdBy != null ? !createdBy.equals(that.createdBy) : that.createdBy != null) {
+ return false;
+ }
if (createdDate != null ? !createdDate.equals(that.createdDate) : that.createdDate != null) {
return false;
}
if (reasonCode != null ? !reasonCode.equals(that.reasonCode) : that.reasonCode != null) {
return false;
}
- if (updatedDate != null ? !updatedDate.equals(that.updatedDate) : that.updatedDate != null) {
+ if (updatedBy != null ? !updatedBy.equals(that.updatedBy) : that.updatedBy != null) {
return false;
}
- if (userName != null ? !userName.equals(that.userName) : that.userName != null) {
+ if (updatedDate != null ? !updatedDate.equals(that.updatedDate) : that.updatedDate != null) {
return false;
}
if (userToken != null ? !userToken.equals(that.userToken) : that.userToken != null) {
@@ -158,7 +168,8 @@ public class InternalCallContext extends InternalTenantContext {
public int hashCode() {
int result = super.hashCode();
result = 31 * result + (userToken != null ? userToken.hashCode() : 0);
- result = 31 * result + (userName != null ? userName.hashCode() : 0);
+ result = 31 * result + (createdBy != null ? createdBy.hashCode() : 0);
+ result = 31 * result + (updatedBy != null ? updatedBy.hashCode() : 0);
result = 31 * result + (callOrigin != null ? callOrigin.hashCode() : 0);
result = 31 * result + (userType != null ? userType.hashCode() : 0);
result = 31 * result + (reasonCode != null ? reasonCode.hashCode() : 0);
diff --git a/util/src/main/java/com/ning/billing/util/callcontext/InternalCallContextFactory.java b/util/src/main/java/com/ning/billing/util/callcontext/InternalCallContextFactory.java
index 97202bd..89fb15b 100644
--- a/util/src/main/java/com/ning/billing/util/callcontext/InternalCallContextFactory.java
+++ b/util/src/main/java/com/ning/billing/util/callcontext/InternalCallContextFactory.java
@@ -198,14 +198,14 @@ public class InternalCallContextFactory {
// Used when we need to re-hydrate the context with the account_record_id (when creating the account)
public InternalCallContext createInternalCallContext(final Long accountRecordId, final InternalCallContext context) {
- return new InternalCallContext(context.getTenantRecordId(), accountRecordId, context.getUserToken(), context.getUserName(),
+ return new InternalCallContext(context.getTenantRecordId(), accountRecordId, context.getUserToken(), context.getCreatedBy(),
context.getCallOrigin(), context.getUserType(), context.getReasonCode(), context.getComment(),
context.getCreatedDate(), context.getUpdatedDate());
}
// Used when we need to re-hydrate the context with the tenant_record_id and account_record_id (when claiming bus events)
public InternalCallContext createInternalCallContext(final Long tenantRecordId, final Long accountRecordId, final InternalCallContext context) {
- return new InternalCallContext(tenantRecordId, accountRecordId, context.getUserToken(), context.getUserName(),
+ return new InternalCallContext(tenantRecordId, accountRecordId, context.getUserToken(), context.getCreatedBy(),
context.getCallOrigin(), context.getUserType(), context.getReasonCode(), context.getComment(),
context.getCreatedDate(), context.getUpdatedDate());
}
diff --git a/util/src/main/java/com/ning/billing/util/callcontext/InternalTenantContextBinder.java b/util/src/main/java/com/ning/billing/util/callcontext/InternalTenantContextBinder.java
index 0349be5..499e907 100644
--- a/util/src/main/java/com/ning/billing/util/callcontext/InternalTenantContextBinder.java
+++ b/util/src/main/java/com/ning/billing/util/callcontext/InternalTenantContextBinder.java
@@ -57,7 +57,7 @@ public @interface InternalTenantContextBinder {
if (context instanceof InternalCallContext) {
final InternalCallContext callContext = (InternalCallContext) context;
- q.bind("userName", callContext.getUserName());
+ q.bind("userName", callContext.getCreatedBy());
if (callContext.getCreatedDate() == null) {
q.bindNull("createdDate", Types.DATE);
} else {
diff --git a/util/src/main/java/com/ning/billing/util/customfield/dao/CustomFieldHistoryBinder.java b/util/src/main/java/com/ning/billing/util/customfield/dao/CustomFieldHistoryBinder.java
index 506017a..48b53dd 100644
--- a/util/src/main/java/com/ning/billing/util/customfield/dao/CustomFieldHistoryBinder.java
+++ b/util/src/main/java/com/ning/billing/util/customfield/dao/CustomFieldHistoryBinder.java
@@ -40,8 +40,8 @@ public @interface CustomFieldHistoryBinder {
return new Binder<CustomFieldHistoryBinder, EntityHistory<CustomField>>() {
@Override
public void bind(final SQLStatement<?> q, final CustomFieldHistoryBinder bind, final EntityHistory<CustomField> customFieldHistory) {
- q.bind("recordId", customFieldHistory.getValue());
- q.bind("changeType", customFieldHistory.getChangeType().toString());
+// q.bind("recordId", customFieldHistory.getValue());
+// q.bind("changeType", customFieldHistory.getChangeType().toString());
q.bind("id", customFieldHistory.getId().toString());
q.bind("fieldName", customFieldHistory.getEntity().getName());
q.bind("fieldValue", customFieldHistory.getEntity().getValue());
diff --git a/util/src/main/java/com/ning/billing/util/dao/AuditSqlDao.java b/util/src/main/java/com/ning/billing/util/dao/AuditSqlDao.java
index 5ec8499..55a35c5 100644
--- a/util/src/main/java/com/ning/billing/util/dao/AuditSqlDao.java
+++ b/util/src/main/java/com/ning/billing/util/dao/AuditSqlDao.java
@@ -19,6 +19,7 @@ package com.ning.billing.util.dao;
import java.util.List;
import org.skife.jdbi.v2.sqlobject.Bind;
+import org.skife.jdbi.v2.sqlobject.BindBean;
import org.skife.jdbi.v2.sqlobject.SqlBatch;
import org.skife.jdbi.v2.sqlobject.SqlQuery;
import org.skife.jdbi.v2.sqlobject.SqlUpdate;
@@ -36,12 +37,12 @@ import com.ning.billing.util.callcontext.InternalTenantContextBinder;
public interface AuditSqlDao {
@SqlUpdate
- public void insertAuditFromTransaction(@AuditBinder final EntityAudit audit,
- @InternalTenantContextBinder final InternalCallContext context);
+ public void insertAuditFromTransaction(@BindBean final EntityAudit audit,
+ @BindBean final InternalCallContext context);
@SqlBatch(transactional = false)
- public void insertAuditFromTransaction(@AuditBinder final List<EntityAudit> audit,
- @InternalTenantContextBinder final InternalCallContext context);
+ public void insertAuditFromTransaction(@BindBean final List<EntityAudit> audit,
+ @BindBean final InternalCallContext context);
@SqlQuery
public List<AuditLog> getAuditLogsForTargetRecordId(@TableNameBinder final TableName tableName,
diff --git a/util/src/main/java/com/ning/billing/util/dao/DateTimeArgumentFactory.java b/util/src/main/java/com/ning/billing/util/dao/DateTimeArgumentFactory.java
new file mode 100644
index 0000000..1e0cfc6
--- /dev/null
+++ b/util/src/main/java/com/ning/billing/util/dao/DateTimeArgumentFactory.java
@@ -0,0 +1,68 @@
+/*
+ * Copyright 2010-2012 Ning, Inc.
+ *
+ * Ning licenses this file to you under the Apache License, version 2.0
+ * (the "License"); you may not use this file except in compliance with the
+ * License. You may obtain a copy of the License at:
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ */
+
+package com.ning.billing.util.dao;
+
+import java.sql.PreparedStatement;
+import java.sql.SQLException;
+import java.sql.Timestamp;
+import java.sql.Types;
+
+import org.joda.time.DateTime;
+import org.skife.jdbi.v2.StatementContext;
+import org.skife.jdbi.v2.tweak.Argument;
+import org.skife.jdbi.v2.tweak.ArgumentFactory;
+
+public class DateTimeArgumentFactory implements ArgumentFactory<DateTime> {
+
+ @Override
+ public boolean accepts(final Class<?> expectedType, final Object value, final StatementContext ctx) {
+ return value instanceof DateTime;
+ }
+
+ @Override
+ public Argument build(final Class<?> expectedType, final DateTime value, final StatementContext ctx) {
+ return new DateTimeArgument(value);
+ }
+
+ public static class DateTimeArgument implements Argument {
+
+ private final DateTime value;
+
+ public DateTimeArgument(final DateTime value) {
+ this.value = value;
+ }
+
+ @Override
+ public void apply(final int position, final PreparedStatement statement, final StatementContext ctx) throws SQLException {
+ if (value != null) {
+ statement.setTimestamp(position, new Timestamp(value.toDate().getTime()));
+ } else {
+ statement.setNull(position, Types.TIMESTAMP);
+ }
+ }
+
+ @Override
+ public String toString() {
+ final StringBuilder sb = new StringBuilder();
+ sb.append("DateTimeArgument");
+ sb.append("{value=").append(value);
+ sb.append('}');
+ return sb.toString();
+ }
+ }
+
+}
diff --git a/util/src/main/java/com/ning/billing/util/dao/EntityHistory.java b/util/src/main/java/com/ning/billing/util/dao/EntityHistory.java
index 9ee036b..505b742 100644
--- a/util/src/main/java/com/ning/billing/util/dao/EntityHistory.java
+++ b/util/src/main/java/com/ning/billing/util/dao/EntityHistory.java
@@ -18,11 +18,39 @@ package com.ning.billing.util.dao;
import java.util.UUID;
+import org.joda.time.DateTime;
+import org.skife.jdbi.v2.tweak.Argument;
+
import com.ning.billing.util.audit.ChangeType;
import com.ning.billing.util.entity.Entity;
+import com.ning.billing.util.entity.EntityBase;
+
+public class EntityHistory<T extends Entity> extends EntityBase {
+
+ private final Long targetRecordId;
+ private final T entity;
+ private ChangeType changeType;
+
+ public EntityHistory(final UUID id, final T src, final Long targetRecordId, final ChangeType type, final DateTime createdDate) {
+ super(id, createdDate, createdDate);
+ this.changeType = type;
+ this.targetRecordId = targetRecordId;
+ this.entity = src;
+ }
+
+ public EntityHistory(final T src, final Long targetRecordId, final ChangeType type, final DateTime createdDate) {
+ this(UUID.randomUUID(), src, targetRecordId, type, createdDate);
+ }
+
+ public ChangeType getChangeType() {
+ return changeType;
+ }
+
+ public T getEntity() {
+ return entity;
+ }
-public class EntityHistory<T extends Entity> extends MappedEntity<T, UUID, Long> {
- public EntityHistory(final UUID id, final Long recordId, final T entity, final ChangeType changeType) {
- super(new Mapper<UUID, Long>(id, recordId), entity, changeType);
+ public Long getTargetRecordId() {
+ return targetRecordId;
}
}
diff --git a/util/src/main/java/com/ning/billing/util/dao/EntityHistoryBinder.java b/util/src/main/java/com/ning/billing/util/dao/EntityHistoryBinder.java
new file mode 100644
index 0000000..a9435a8
--- /dev/null
+++ b/util/src/main/java/com/ning/billing/util/dao/EntityHistoryBinder.java
@@ -0,0 +1,78 @@
+/*
+ * Copyright 2010-2012 Ning, Inc.
+ *
+ * Ning licenses this file to you under the Apache License, version 2.0
+ * (the "License"); you may not use this file except in compliance with the
+ * License. You may obtain a copy of the License at:
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ */
+
+package com.ning.billing.util.dao;
+
+import java.beans.BeanInfo;
+import java.beans.IntrospectionException;
+import java.beans.Introspector;
+import java.beans.PropertyDescriptor;
+import java.lang.annotation.Annotation;
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+import java.lang.reflect.InvocationTargetException;
+
+import org.skife.jdbi.v2.SQLStatement;
+import org.skife.jdbi.v2.sqlobject.Binder;
+import org.skife.jdbi.v2.sqlobject.BinderFactory;
+import org.skife.jdbi.v2.sqlobject.BindingAnnotation;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.ning.billing.util.entity.Entity;
+
+@BindingAnnotation(EntityHistoryBinder.EntityHistoryBinderFactory.class)
+@Retention(RetentionPolicy.RUNTIME)
+@Target({ElementType.PARAMETER})
+public @interface EntityHistoryBinder {
+
+
+ public static class EntityHistoryBinderFactory<T extends Entity> implements BinderFactory {
+
+ private static final Logger logger = LoggerFactory.getLogger(EntityHistoryBinder.class);
+
+ @Override
+ public Binder build(final Annotation annotation) {
+ return new Binder<EntityHistoryBinder, EntityHistory<T>>() {
+
+
+ @Override
+ public void bind(final SQLStatement<?> q, final EntityHistoryBinder bind, final EntityHistory<T> history) {
+ try {
+ // Emulate @BndBean
+ final Entity arg = history.getEntity();
+ final BeanInfo infos = Introspector.getBeanInfo(arg.getClass());
+ final PropertyDescriptor[] props = infos.getPropertyDescriptors();
+ for (PropertyDescriptor prop : props) {
+ q.bind(prop.getName(), prop.getReadMethod().invoke(arg));
+ }
+ q.bind("id", history.getId());
+ q.bind("targetRecordId", history.getTargetRecordId());
+ q.bind("changeType", history.getChangeType().toString());
+ } catch (IntrospectionException e) {
+ logger.warn(e.getMessage());
+ } catch (InvocationTargetException e) {
+ logger.warn(e.getMessage());
+ } catch (IllegalAccessException e) {
+ logger.warn(e.getMessage());
+ }
+ }
+ };
+ }
+ }
+}
diff --git a/util/src/main/java/com/ning/billing/util/dao/EnumArgumentFactory.java b/util/src/main/java/com/ning/billing/util/dao/EnumArgumentFactory.java
new file mode 100644
index 0000000..aa8dbb2
--- /dev/null
+++ b/util/src/main/java/com/ning/billing/util/dao/EnumArgumentFactory.java
@@ -0,0 +1,61 @@
+/*
+ * Copyright 2010-2012 Ning, Inc.
+ *
+ * Ning licenses this file to you under the Apache License, version 2.0
+ * (the "License"); you may not use this file except in compliance with the
+ * License. You may obtain a copy of the License at:
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ */
+
+package com.ning.billing.util.dao;
+
+import java.sql.PreparedStatement;
+import java.sql.SQLException;
+import java.sql.Types;
+import java.util.UUID;
+
+import org.skife.jdbi.v2.StatementContext;
+import org.skife.jdbi.v2.tweak.Argument;
+import org.skife.jdbi.v2.tweak.ArgumentFactory;
+
+public class EnumArgumentFactory implements ArgumentFactory<Enum> {
+
+ @Override
+ public Argument build(final Class<?> expectedType, final Enum value, final StatementContext ctx) {
+ return new StringArgument(value.toString());
+ }
+
+ class StringArgument implements Argument {
+
+ private final String value;
+
+ StringArgument(final String value) {
+ this.value = value;
+ }
+
+ public void apply(final int position, final PreparedStatement statement, final StatementContext ctx) throws SQLException {
+ if (value != null) {
+ statement.setString(position, value);
+ } else {
+ statement.setNull(position, Types.VARCHAR);
+ }
+ }
+
+ @Override
+ public String toString() {
+ return "'" + value + "'";
+ }
+ }
+
+ @Override
+ public boolean accepts(final Class expectedType, final Object value, final StatementContext ctx) {
+ return value != null && value.getClass().isEnum();
+ }
+}
diff --git a/util/src/main/java/com/ning/billing/util/dao/HistorySqlDao.java b/util/src/main/java/com/ning/billing/util/dao/HistorySqlDao.java
index 8976541..7822434 100644
--- a/util/src/main/java/com/ning/billing/util/dao/HistorySqlDao.java
+++ b/util/src/main/java/com/ning/billing/util/dao/HistorySqlDao.java
@@ -18,6 +18,7 @@ package com.ning.billing.util.dao;
import java.util.List;
+import org.skife.jdbi.v2.sqlobject.BindBean;
import org.skife.jdbi.v2.sqlobject.SqlBatch;
import org.skife.jdbi.v2.sqlobject.SqlUpdate;
@@ -28,10 +29,10 @@ import com.ning.billing.util.entity.Entity;
public interface HistorySqlDao<T extends Entity> {
@SqlBatch(transactional = false)
- public void batchAddHistoryFromTransaction(List<EntityHistory<T>> histories,
+ public void batchAddHistoryFromTransaction(List<EntityHistory> histories,
@InternalTenantContextBinder InternalCallContext context);
@SqlUpdate
- public void addHistoryFromTransaction(EntityHistory<T> history,
- @InternalTenantContextBinder InternalCallContext context);
+ public void addHistoryFromTransaction(@EntityHistoryBinder EntityHistory<T> history,
+ @BindBean InternalCallContext context);
}
diff --git a/util/src/main/java/com/ning/billing/util/dao/UUIDArgumentFactory.java b/util/src/main/java/com/ning/billing/util/dao/UUIDArgumentFactory.java
new file mode 100644
index 0000000..385314b
--- /dev/null
+++ b/util/src/main/java/com/ning/billing/util/dao/UUIDArgumentFactory.java
@@ -0,0 +1,66 @@
+/*
+ * Copyright 2010-2012 Ning, Inc.
+ *
+ * Ning licenses this file to you under the Apache License, version 2.0
+ * (the "License"); you may not use this file except in compliance with the
+ * License. You may obtain a copy of the License at:
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ */
+
+package com.ning.billing.util.dao;
+
+import java.sql.PreparedStatement;
+import java.sql.SQLException;
+import java.sql.Types;
+import java.util.UUID;
+
+import org.skife.jdbi.v2.StatementContext;
+import org.skife.jdbi.v2.tweak.Argument;
+import org.skife.jdbi.v2.tweak.ArgumentFactory;
+
+public class UUIDArgumentFactory implements ArgumentFactory<UUID> {
+
+ @Override
+ public boolean accepts(final Class<?> expectedType, final Object value, final StatementContext ctx) {
+ return value instanceof UUID;
+ }
+
+ @Override
+ public Argument build(final Class<?> expectedType, final UUID value, final StatementContext ctx) {
+ return new UUIDArgument(value);
+ }
+
+ public class UUIDArgument implements Argument {
+
+ private final UUID value;
+
+ public UUIDArgument(final UUID value) {
+ this.value = value;
+ }
+
+ @Override
+ public void apply(final int position, final PreparedStatement statement, final StatementContext ctx) throws SQLException {
+ if (value != null) {
+ statement.setString(position, value.toString());
+ } else {
+ statement.setNull(position, Types.VARCHAR);
+ }
+ }
+
+ @Override
+ public String toString() {
+ final StringBuilder sb = new StringBuilder();
+ sb.append("UUIDArgument");
+ sb.append("{value=").append(value);
+ sb.append('}');
+ return sb.toString();
+ }
+ }
+}
diff --git a/util/src/main/java/com/ning/billing/util/entity/dao/EntitySqlDao.java b/util/src/main/java/com/ning/billing/util/entity/dao/EntitySqlDao.java
index b8aee42..5ddcc53 100644
--- a/util/src/main/java/com/ning/billing/util/entity/dao/EntitySqlDao.java
+++ b/util/src/main/java/com/ning/billing/util/entity/dao/EntitySqlDao.java
@@ -26,6 +26,7 @@ import org.skife.jdbi.v2.sqlobject.mixins.CloseMe;
import org.skife.jdbi.v2.sqlobject.mixins.Transactional;
import org.skife.jdbi.v2.sqlobject.mixins.Transmogrifier;
+import com.ning.billing.util.audit.ChangeType;
import com.ning.billing.util.callcontext.InternalCallContext;
import com.ning.billing.util.callcontext.InternalTenantContext;
import com.ning.billing.util.callcontext.InternalTenantContextBinder;
@@ -37,8 +38,9 @@ import com.ning.billing.util.entity.EntityPersistenceException;
public interface EntitySqlDao<T extends Entity> extends AuditSqlDao, HistorySqlDao<T>, Transmogrifier, Transactional<EntitySqlDao<T>>, CloseMe {
@SqlUpdate
+ @Audited(ChangeType.INSERT)
public void create(@BindBean final T entity,
- @InternalTenantContextBinder final InternalCallContext context) throws EntityPersistenceException;
+ @BindBean final InternalCallContext context) throws EntityPersistenceException;
@SqlQuery
public T getById(@Bind("id") final String id,
diff --git a/util/src/main/java/com/ning/billing/util/entity/dao/EntitySqlDaoWrapperInvocationHandler.java b/util/src/main/java/com/ning/billing/util/entity/dao/EntitySqlDaoWrapperInvocationHandler.java
index 7502ef7..a7a7018 100644
--- a/util/src/main/java/com/ning/billing/util/entity/dao/EntitySqlDaoWrapperInvocationHandler.java
+++ b/util/src/main/java/com/ning/billing/util/entity/dao/EntitySqlDaoWrapperInvocationHandler.java
@@ -19,19 +19,21 @@ package com.ning.billing.util.entity.dao;
import java.lang.annotation.Annotation;
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
+import java.lang.reflect.Proxy;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
+import java.util.UUID;
import org.skife.jdbi.v2.exceptions.DBIException;
import org.skife.jdbi.v2.sqlobject.Bind;
import com.ning.billing.util.audit.ChangeType;
import com.ning.billing.util.callcontext.InternalCallContext;
-import com.ning.billing.util.callcontext.InternalTenantContextBinder;
import com.ning.billing.util.dao.EntityAudit;
import com.ning.billing.util.dao.EntityHistory;
+import com.ning.billing.util.dao.EntityHistoryToBeRenamed;
import com.ning.billing.util.dao.TableName;
import com.ning.billing.util.entity.Entity;
@@ -199,12 +201,7 @@ public class EntitySqlDaoWrapperInvocationHandler<T extends EntitySqlDao<U>, U e
if (!(arg instanceof InternalCallContext)) {
continue;
}
-
- for (final Annotation annotation : parameterAnnotations[i]) {
- if (InternalTenantContextBinder.class.equals(annotation.annotationType())) {
- return (InternalCallContext) arg;
- }
- }
+ return (InternalCallContext) arg;
}
return null;
@@ -222,11 +219,17 @@ public class EntitySqlDaoWrapperInvocationHandler<T extends EntitySqlDao<U>, U e
}
private Long insertHistory(final Long entityRecordId, final U entity, final ChangeType changeType, final InternalCallContext context) {
- final EntityHistory<U> history = new EntityHistory<U>(entity.getId(), entityRecordId, entity, changeType);
+
+ // TODO use clock
+ EntityHistory<U> history = new EntityHistory<U>(entity, entityRecordId, changeType, context.getCreatedDate());
+
sqlDao.addHistoryFromTransaction(history, context);
return sqlDao.getHistoryRecordId(entityRecordId, context);
+
}
+
+
private void insertAudits(final TableName tableName, final Long historyRecordId, final ChangeType changeType, final InternalCallContext context) {
// STEPH can we trust context or should we use Clock?
final EntityAudit audit = new EntityAudit(tableName, historyRecordId, changeType, context.getCreatedDate());
diff --git a/util/src/main/java/com/ning/billing/util/entity/EntityBase.java b/util/src/main/java/com/ning/billing/util/entity/EntityBase.java
index 4b8810c..4babfbe 100644
--- a/util/src/main/java/com/ning/billing/util/entity/EntityBase.java
+++ b/util/src/main/java/com/ning/billing/util/entity/EntityBase.java
@@ -42,6 +42,12 @@ public abstract class EntityBase implements Entity {
this.updatedDate = updatedDate;
}
+ public EntityBase(final EntityBase target) {
+ this.id = UUID.randomUUID();
+ this.createdDate = target.getCreatedDate();
+ this.updatedDate = target.getUpdatedDate();
+ }
+
@Override
public UUID getId() {
return id;
diff --git a/util/src/main/java/com/ning/billing/util/tag/dao/TagDefinitionSqlDao.java b/util/src/main/java/com/ning/billing/util/tag/dao/TagDefinitionSqlDao.java
index 2052921..ba23fdd 100644
--- a/util/src/main/java/com/ning/billing/util/tag/dao/TagDefinitionSqlDao.java
+++ b/util/src/main/java/com/ning/billing/util/tag/dao/TagDefinitionSqlDao.java
@@ -35,6 +35,7 @@ import org.skife.jdbi.v2.sqlobject.BinderFactory;
import org.skife.jdbi.v2.sqlobject.BindingAnnotation;
import org.skife.jdbi.v2.sqlobject.SqlQuery;
import org.skife.jdbi.v2.sqlobject.SqlUpdate;
+import org.skife.jdbi.v2.sqlobject.customizers.RegisterArgumentFactory;
import org.skife.jdbi.v2.sqlobject.customizers.RegisterMapper;
import org.skife.jdbi.v2.tweak.ResultSetMapper;
@@ -42,22 +43,21 @@ import com.ning.billing.util.audit.ChangeType;
import com.ning.billing.util.callcontext.InternalCallContext;
import com.ning.billing.util.callcontext.InternalTenantContext;
import com.ning.billing.util.callcontext.InternalTenantContextBinder;
+import com.ning.billing.util.dao.DateTimeArgumentFactory;
import com.ning.billing.util.dao.EntityHistory;
+import com.ning.billing.util.dao.EnumArgumentFactory;
+import com.ning.billing.util.dao.UUIDArgumentFactory;
import com.ning.billing.util.entity.dao.Audited;
import com.ning.billing.util.entity.dao.EntitySqlDao;
import com.ning.billing.util.entity.dao.EntitySqlDaoStringTemplate;
import com.ning.billing.util.tag.DefaultTagDefinition;
import com.ning.billing.util.tag.TagDefinition;
+@RegisterArgumentFactory({UUIDArgumentFactory.class, DateTimeArgumentFactory.class, EnumArgumentFactory.class})
@EntitySqlDaoStringTemplate
@RegisterMapper(TagDefinitionSqlDao.TagDefinitionMapper.class)
public interface TagDefinitionSqlDao extends EntitySqlDao<TagDefinition> {
- @Override
- @SqlUpdate
- @Audited(ChangeType.INSERT)
- public void create(@TagDefinitionBinder final TagDefinition entity,
- @InternalTenantContextBinder final InternalCallContext context);
@SqlQuery
public TagDefinition getByName(@Bind("name") final String definitionName,
@@ -76,10 +76,6 @@ public interface TagDefinitionSqlDao extends EntitySqlDao<TagDefinition> {
public List<TagDefinition> getByIds(@UUIDCollectionBinder final Collection<String> definitionIds,
@InternalTenantContextBinder final InternalTenantContext context);
- @Override
- @SqlUpdate
- public void addHistoryFromTransaction(@TagDefinitionHistoryBinder final EntityHistory<TagDefinition> tagDefinition,
- @InternalTenantContextBinder final InternalCallContext context);
public class TagDefinitionMapper implements ResultSetMapper<TagDefinition> {
@@ -92,49 +88,4 @@ public interface TagDefinitionSqlDao extends EntitySqlDao<TagDefinition> {
}
}
- @BindingAnnotation(TagDefinitionBinder.TagDefinitionBinderFactory.class)
- @Retention(RetentionPolicy.RUNTIME)
- @Target({ElementType.PARAMETER})
- public @interface TagDefinitionBinder {
-
- public static class TagDefinitionBinderFactory implements BinderFactory {
-
- @Override
- public Binder build(final Annotation annotation) {
- return new Binder<TagDefinitionBinder, TagDefinition>() {
- @Override
- public void bind(final SQLStatement q, final TagDefinitionBinder bind, final TagDefinition tagDefinition) {
- q.bind("id", tagDefinition.getId().toString());
- q.bind("name", tagDefinition.getName());
- q.bind("description", tagDefinition.getDescription());
- }
- };
- }
- }
- }
-
- @BindingAnnotation(TagDefinitionHistoryBinder.TagDefinitionHistoryBinderFactory.class)
- @Retention(RetentionPolicy.RUNTIME)
- @Target({ElementType.PARAMETER})
- public @interface TagDefinitionHistoryBinder {
-
- public static class TagDefinitionHistoryBinderFactory implements BinderFactory {
-
- @Override
- public Binder<TagDefinitionHistoryBinder, EntityHistory<TagDefinition>> build(final Annotation annotation) {
- return new Binder<TagDefinitionHistoryBinder, EntityHistory<TagDefinition>>() {
- @Override
- public void bind(final SQLStatement<?> q, final TagDefinitionHistoryBinder bind, final EntityHistory<TagDefinition> history) {
- q.bind("recordId", history.getValue());
- q.bind("changeType", history.getChangeType().toString());
-
- final TagDefinition tagDefinition = history.getEntity();
- q.bind("id", tagDefinition.getId().toString());
- q.bind("name", tagDefinition.getName());
- q.bind("description", tagDefinition.getDescription());
- }
- };
- }
- }
- }
}
diff --git a/util/src/main/java/com/ning/billing/util/tag/dao/TagHistoryBinder.java b/util/src/main/java/com/ning/billing/util/tag/dao/TagHistoryBinder.java
index 11d279e..4ef9100 100644
--- a/util/src/main/java/com/ning/billing/util/tag/dao/TagHistoryBinder.java
+++ b/util/src/main/java/com/ning/billing/util/tag/dao/TagHistoryBinder.java
@@ -40,6 +40,7 @@ public @interface TagHistoryBinder {
return new Binder<TagHistoryBinder, EntityHistory<Tag>>() {
@Override
public void bind(final SQLStatement<?> q, final TagHistoryBinder bind, final EntityHistory<Tag> tagHistory) {
+
q.bind("recordId", tagHistory.getValue());
q.bind("changeType", tagHistory.getChangeType().toString());
q.bind("id", tagHistory.getId().toString());
diff --git a/util/src/main/resources/com/ning/billing/util/customfield/dao/CustomFieldSqlDao.sql.stg b/util/src/main/resources/com/ning/billing/util/customfield/dao/CustomFieldSqlDao.sql.stg
index 74421f0..018104e 100644
--- a/util/src/main/resources/com/ning/billing/util/customfield/dao/CustomFieldSqlDao.sql.stg
+++ b/util/src/main/resources/com/ning/billing/util/customfield/dao/CustomFieldSqlDao.sql.stg
@@ -11,6 +11,15 @@ tableFields(prefix) ::= <<
, <prefix>updated_date
>>
+tableValues() ::= <<
+ :objectId
+, :objectType
+, :createdBy
+, :createdDate
+, :updatedBy
+, :updatedDate
+>>
+
historyTableName() ::= "custom_field_history"
updateFromTransaction() ::= <<
diff --git a/util/src/main/resources/com/ning/billing/util/ddl.sql b/util/src/main/resources/com/ning/billing/util/ddl.sql
index 25758e8..06002da 100644
--- a/util/src/main/resources/com/ning/billing/util/ddl.sql
+++ b/util/src/main/resources/com/ning/billing/util/ddl.sql
@@ -58,20 +58,21 @@ CREATE INDEX tag_definitions_tenant_record_id ON tag_definitions(tenant_record_i
DROP TABLE IF EXISTS tag_definition_history;
CREATE TABLE tag_definition_history (
- history_record_id int(11) unsigned NOT NULL AUTO_INCREMENT,
- record_id int(11) unsigned NOT NULL,
+ record_id int(11) unsigned NOT NULL AUTO_INCREMENT,
id char(36) NOT NULL,
+ target_record_id int(11) unsigned NOT NULL,
name varchar(30) NOT NULL,
- created_by varchar(50),
description varchar(200),
change_type char(6) NOT NULL,
+ created_by varchar(50),
+ created_date datetime NOT NULL,
updated_by varchar(50) NOT NULL,
- date datetime NOT NULL,
+ updated_date datetime NOT NULL,
tenant_record_id int(11) unsigned default null,
- PRIMARY KEY(history_record_id)
+ PRIMARY KEY(record_id)
) ENGINE=innodb;
CREATE INDEX tag_definition_history_id ON tag_definition_history(id);
-CREATE INDEX tag_definition_history_record_id ON tag_definition_history(record_id);
+CREATE INDEX tag_definition_history_target_record_id ON tag_definition_history(target_record_id);
CREATE INDEX tag_definition_history_name ON tag_definition_history(name);
CREATE INDEX tag_definition_history_tenant_record_id ON tag_definition_history(tenant_record_id);
@@ -155,7 +156,7 @@ CREATE TABLE audit_log (
table_name varchar(50) NOT NULL,
target_record_id int(11) NOT NULL,
change_type char(6) NOT NULL,
- changed_by varchar(50) NOT NULL,
+ created_by varchar(50) NOT NULL,
reason_code varchar(255) DEFAULT NULL,
comments varchar(255) DEFAULT NULL,
user_token char(36),
@@ -165,7 +166,7 @@ CREATE TABLE audit_log (
PRIMARY KEY(record_id)
) ENGINE=innodb;
CREATE INDEX audit_log_fetch_target_record_id ON audit_log(table_name, target_record_id);
-CREATE INDEX audit_log_user_name ON audit_log(changed_by);
+CREATE INDEX audit_log_user_name ON audit_log(created_by);
CREATE INDEX audit_log_tenant_account_record_id ON audit_log(tenant_record_id, account_record_id);
DROP TABLE IF EXISTS bus_events;
diff --git a/util/src/main/resources/com/ning/billing/util/entity/dao/EntitySqlDao.sql.stg b/util/src/main/resources/com/ning/billing/util/entity/dao/EntitySqlDao.sql.stg
index 6d3b9e4..d3752d4 100644
--- a/util/src/main/resources/com/ning/billing/util/entity/dao/EntitySqlDao.sql.stg
+++ b/util/src/main/resources/com/ning/billing/util/entity/dao/EntitySqlDao.sql.stg
@@ -4,16 +4,24 @@ group EntitySqlDao;
tableName() ::= ""
-/** Leave out id, account_record_id and tenant_record_id */
+/** Leave out id, account_record_id and tenant_record_id **/
tableFields(prefix) ::= ""
tableValues() ::= ""
historyTableName() ::= ""
-historyTableFields(prefix) ::= "<tableFields(prefix)>"
+historyTableFields(prefix) ::= <<
+ <targetRecordIdField(prefix)>
+, <changeTypeField(prefix)>
+, <tableFields(prefix)>
+>>
-historyTableValues() ::= "<tableValues()>"
+historyTableValues() ::= <<
+ <targetRecordIdValue()>
+, <changeTypeValue()>
+, <tableValues()>
+>>
/****************************************************/
@@ -21,85 +29,96 @@ idField(prefix) ::= <<
<prefix>id
>>
+idValue() ::= ":id"
+
recordIdField(prefix) ::= <<
<prefix>record_id
>>
-historyRecordIdField(prefix) ::= <<
-<prefix>history_record_id
+recordIdValue() ::= ":recordId"
+
+changeTypeField(prefix) ::= <<
+<prefix>change_type
>>
-/** Override this if the Entity isn't tied to an account */
+changeTypeValue() ::= ":changeType"
+
+targetRecordIdField(prefix) ::= <<
+<prefix>target_record_id
+>>
+
+targetRecordIdValue() ::= ":targetRecordId"
+
+/** Override this if the Entity isn't tied to an account **/
+
+
accountRecordIdField(prefix) ::= <<
<prefix>account_record_id
>>
+accountRecordIdFieldWithComma(prefix) ::= <<
+, <accountRecordIdField(prefix)>
+>>
+
accountRecordIdValue() ::= ":accountRecordId"
+accountRecordIdValueWithComma() ::= <<
+, <accountRecordIdValue()>
+>>
+
tenantRecordIdField(prefix) ::= <<
<prefix>tenant_record_id
>>
+tenantRecordIdFieldWithComma(prefix) ::= <<
+, <tenantRecordIdField(prefix)>
+>>
+
+
tenantRecordIdValue() ::= ":tenantRecordId"
+tenantRecordIdValueWithComma() ::= <<
+, <tenantRecordIdValue()>
+>>
+
allTableFields(prefix) ::= <<
<recordIdField(prefix)>
, <idField(prefix)>
, <tableFields(prefix)>
-<if(accountRecordIdField(prefix))>, <accountRecordIdField(prefix)><endif>
-, <tenantRecordIdField(prefix)>
+<accountRecordIdFieldWithComma(prefix)>
+<tenantRecordIdFieldWithComma(prefix)>
+>>
+
+
+
+allTableValues() ::= <<
+ <recordIdValue()>
+, <idValue()>
+, <tableValues()>
+<accountRecordIdValueWithComma()>
+<tenantRecordIdValueWithComma()>
>>
-/** TODO history tables should not start with history_record_id, instead: record_id, id, target_record_id **/
+
allHistoryTableFields(prefix) ::= <<
- <historyRecordIdField(prefix)>
-, <recordIdField(prefix)>
+ <recordIdField(prefix)>
, <idField(prefix)>
+, <targetRecordIdField(prefix)>
, <historyTableFields(prefix)>
-<if(accountRecordIdField(prefix))>, <accountRecordIdField(prefix)><endif>
-, <tenantRecordIdField(prefix)>
+<accountRecordIdFieldWithComma(prefix)>
+<tenantRecordIdFieldWithComma(prefix)>
>>
allHistoryTableValues() ::= <<
- :recordId
-, :id
+ <recordIdValue()>
+, <idValue()>
+, <targetRecordIdValue()>
, <historyTableValues()>
-<if(accountRecordIdField(""))>, <accountRecordIdValue()><endif>
-<if(tenantRecordIdField(""))>, <tenantRecordIdValue()><endif>
->>
-
-auditTableName() ::= "audit_log"
-
-
-auditTableFields(prefix) ::= <<
- <prefix>id
-, <prefix>table_name
-, <prefix>target_record_id
-, <prefix>change_type
-, <prefix>changed_by
-, <prefix>reason_code
-, <prefix>comments
-, <prefix>user_token
-, <prefix>created_date
-, <accountRecordIdField(prefix)>
-, <tenantRecordIdField(prefix)>
+<accountRecordIdValueWithComma()>
+<tenantRecordIdValueWithComma()>
>>
-auditTableValues(prefix) ::= <<
- :id
-, :tableName
-, :targetRecordId
-, :changeType
-, :changedBy
-, :reasonCode
-, :comment
-, :userToken
-, :createdDate
-, <accountRecordIdValue()>
-, <tenantRecordIdValue()>
->>
-
/** Macros used for multi-tenancy (almost any query should use them!) */
CHECK_TENANT(prefix) ::= "<prefix>tenant_record_id = :tenantRecordId"
AND_CHECK_TENANT(prefix) ::= "and <CHECK_TENANT(prefix)>"
@@ -131,15 +150,34 @@ where <idField("t.")> = :id
;
>>
+getRecordIdForTable(tableName) ::= <<
+select
+ <recordIdField("t.")>
+from <tableName> t
+where <idField("t.")> = :id
+<AND_CHECK_TENANT("t.")>
+;
+>>
+
getHistoryRecordId(recordId) ::= <<
select
- max(<historyRecordIdField("t.")>)
+ max(<recordIdField("t.")>)
from <tableName()> t
where <recordIdField("t.")> = :recordId
<AND_CHECK_TENANT("t.")>
;
>>
+
+getHistoryRecordIdsForTable(tableName) ::= <<
+select
+ <recordIdField("t.")> record_id
+from <tableName> t
+where <idField("t.")> = :id
+<AND_CHECK_TENANT("t.")>
+;
+>>
+
get(limit) ::= <<
select
<allTableFields("t.")>
@@ -149,25 +187,71 @@ where <CHECK_TENANT("t.")>
;
>>
-test() ::= <<
-select
-<allTableFields("t.")>
-from <tableName()> t
-where <CHECK_TENANT("t.")>
-limit 1
+create() ::= <<
+insert into <tableName()> (
+ <idField()>
+, <tableFields()>
+<accountRecordIdFieldWithComma()>
+<tenantRecordIdFieldWithComma()>
+)
+values (
+ <idValue()>
+, <tableValues()>
+<accountRecordIdValueWithComma()>
+<tenantRecordIdValueWithComma()>
+)
;
>>
+/** Audits, History **/
+auditTableName() ::= "audit_log"
+
+auditTableFields(prefix) ::= <<
+ <prefix>id
+, <prefix>table_name
+, <prefix>target_record_id
+, <prefix>change_type
+, <prefix>created_by
+, <prefix>reason_code
+, <prefix>comments
+, <prefix>user_token
+, <prefix>created_date
+<if(accountRecordIdField(prefix))>, <accountRecordIdField(prefix)><endif>
+<if(tenantRecordIdField(prefix))>, <tenantRecordIdField(prefix)><endif>
+>>
+
+auditTableValues() ::= <<
+ :id
+, :tableName
+, :targetRecordId
+, :changeType
+, :createdBy
+, :reasonCode
+, :comment
+, :userToken
+, :createdDate
+<if(accountRecordIdField(""))>, <accountRecordIdValue()><endif>
+<if(tenantRecordIdField(""))>, <tenantRecordIdValue()><endif>
+>>
+
+
addHistoryFromTransaction() ::= <<
insert into <historyTableName()> (
-<allHistoryTableFields()>
+ <idField()>
+, <historyTableFields()>
+<accountRecordIdFieldWithComma()>
+<tenantRecordIdFieldWithComma()>
)
values (
-<allHistoryTableValues()>
+ <idValue()>
+, <historyTableValues()>
+<accountRecordIdValueWithComma()>
+<tenantRecordIdValueWithComma()>
)
;
>>
+
insertAuditFromTransaction() ::= <<
insert into <auditTableName()> (
<auditTableFields()>
@@ -177,3 +261,23 @@ values (
)
;
>>
+
+getAuditLogsForTargetRecordId() ::= <<
+select
+ <auditTableFields("t.")>
+from <auditTableName()> t
+where t.target_record_id = :targetRecordId
+and t.table_name = :tableName
+<AND_CHECK_TENANT("t.")>
+order by change_date ASC
+;
+>>
+
+test() ::= <<
+select
+<allTableFields("t.")>
+from <tableName()> t
+where <CHECK_TENANT("t.")>
+limit 1
+;
+>>
diff --git a/util/src/main/resources/com/ning/billing/util/tag/dao/TagDefinitionSqlDao.sql.stg b/util/src/main/resources/com/ning/billing/util/tag/dao/TagDefinitionSqlDao.sql.stg
index 2e356eb..9492ebd 100644
--- a/util/src/main/resources/com/ning/billing/util/tag/dao/TagDefinitionSqlDao.sql.stg
+++ b/util/src/main/resources/com/ning/billing/util/tag/dao/TagDefinitionSqlDao.sql.stg
@@ -11,8 +11,19 @@ tableFields(prefix) ::= <<
, <prefix>updated_date
>>
-/** No account_record_id field */
-accountRecordIdField(prefix) ::= ""
+tableValues() ::= <<
+ :name
+, :description
+, :createdBy
+, :createdDate
+, :updatedBy
+, :updatedDate
+>>
+
+accountRecordIdFieldWithComma() ::= ""
+
+accountRecordIdValueWithComma() ::= ""
+
historyTableName() ::= "tag_definition_history"
@@ -31,7 +42,7 @@ tagDefinitionUsageCount() ::= <<
>>
getByName() ::= <<
- SELECT <fields()>
+ SELECT <allTableFields()>
FROM tag_definitions
WHERE name = :name
<AND_CHECK_TENANT()>
@@ -39,7 +50,7 @@ getByName() ::= <<
>>
getByIds(tag_definition_ids) ::= <<
- SELECT <fields()>
+ SELECT <allTableFields()>
FROM tag_definitions
WHERE id IN (<tag_definition_ids: {id | :id_<i0>}; separator="," >)
<AND_CHECK_TENANT()>
diff --git a/util/src/test/java/com/ning/billing/util/audit/dao/TestDefaultAuditDao.java b/util/src/test/java/com/ning/billing/util/audit/dao/TestDefaultAuditDao.java
index d0fe9c4..1c4bc59 100644
--- a/util/src/test/java/com/ning/billing/util/audit/dao/TestDefaultAuditDao.java
+++ b/util/src/test/java/com/ning/billing/util/audit/dao/TestDefaultAuditDao.java
@@ -134,7 +134,7 @@ public class TestDefaultAuditDao extends UtilTestSuiteWithEmbeddedDB {
Assert.assertEquals(auditLogs.get(0).getChangeType(), ChangeType.INSERT);
Assert.assertEquals(auditLogs.get(0).getComment(), internalCallContext.getComment());
Assert.assertEquals(auditLogs.get(0).getReasonCode(), internalCallContext.getReasonCode());
- Assert.assertEquals(auditLogs.get(0).getUserName(), internalCallContext.getUserName());
+ Assert.assertEquals(auditLogs.get(0).getUserName(), internalCallContext.getCreatedBy());
Assert.assertNotNull(auditLogs.get(0).getCreatedDate());
}
}
diff --git a/util/src/test/java/com/ning/billing/util/callcontext/TestInternalCallContextFactory.java b/util/src/test/java/com/ning/billing/util/callcontext/TestInternalCallContextFactory.java
index 5564b47..3b4c06d 100644
--- a/util/src/test/java/com/ning/billing/util/callcontext/TestInternalCallContextFactory.java
+++ b/util/src/test/java/com/ning/billing/util/callcontext/TestInternalCallContextFactory.java
@@ -100,7 +100,7 @@ public class TestInternalCallContextFactory extends UtilTestSuiteWithEmbeddedDB
Assert.assertEquals(context.getCreatedDate(), callContext.getCreatedDate());
Assert.assertEquals(context.getReasonCode(), callContext.getReasonCode());
Assert.assertEquals(context.getUpdatedDate(), callContext.getUpdatedDate());
- Assert.assertEquals(context.getUserName(), callContext.getUserName());
+ Assert.assertEquals(context.getCreatedBy(), callContext.getUserName());
Assert.assertEquals(context.getUserToken(), callContext.getUserToken());
Assert.assertEquals(context.getUserType(), callContext.getUserType());
// Our test callContext doesn't have a tenant id
diff --git a/util/src/test/java/com/ning/billing/util/tag/TestTagStore.java b/util/src/test/java/com/ning/billing/util/tag/TestTagStore.java
index 00f9931..3cb089b 100644
--- a/util/src/test/java/com/ning/billing/util/tag/TestTagStore.java
+++ b/util/src/test/java/com/ning/billing/util/tag/TestTagStore.java
@@ -328,7 +328,7 @@ public class TestTagStore extends UtilTestSuiteWithEmbeddedDB {
assertNotNull(result.get(0).get("change_date"));
final DateTime changeDate = new DateTime(result.get(0).get("change_date"));
assertTrue(Seconds.secondsBetween(changeDate, internalCallContext.getCreatedDate()).getSeconds() < 2);
- assertEquals(result.get(0).get("changed_by"), internalCallContext.getUserName());
+ assertEquals(result.get(0).get("changed_by"), internalCallContext.getCreatedBy());
}
@Test
@@ -358,7 +358,7 @@ public class TestTagStore extends UtilTestSuiteWithEmbeddedDB {
assertNotNull(result.get(0).get("change_date"));
final DateTime changeDate = new DateTime(result.get(0).get("change_date"));
assertTrue(Seconds.secondsBetween(changeDate, internalCallContext.getUpdatedDate()).getSeconds() < 2);
- assertEquals(result.get(0).get("changed_by"), internalCallContext.getUserName());
+ assertEquals(result.get(0).get("changed_by"), internalCallContext.getCreatedBy());
}
@Test