Skip to content
This repository has been archived by the owner on Aug 2, 2019. It is now read-only.

Commit

Permalink
Fixed JpaBatchMetadata when executing 'jpa audit add'
Browse files Browse the repository at this point in the history
  • Loading branch information
sclaresmt committed Oct 19, 2015
1 parent 5fc461b commit bee48c1
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 23 deletions.
Expand Up @@ -128,7 +128,6 @@ public static boolean isValid(String metadataIdentificationString) {
}

private final JpaBatchAnnotationValues annotationValues;
private final JpaActiveRecordMetadata activeRecordMetadata;
private final JavaType entity;
private final FieldMetadata entityIdentifier;
private final JavaType listOfIdentifiersType;
Expand All @@ -155,9 +154,7 @@ public static boolean isValid(String metadataIdentificationString) {
public JpaBatchMetadata(String identifier, JavaType aspectName,
PhysicalTypeMetadata governorPhysicalTypeMetadata,
JpaBatchAnnotationValues annotationValues,
List<FieldMetadata> identifiers,
JpaActiveRecordMetadata entityActiveRecordMetadata,
JpaCrudAnnotationValues crudAnnotationValues,
List<FieldMetadata> identifiers, String entityPlural,
JpaAuditMetadata auditMetada, boolean hasEntityListeners) {
super(identifier, aspectName, governorPhysicalTypeMetadata);
Validate.isTrue(isValid(identifier), "Metadata identification string '"
Expand All @@ -175,9 +172,6 @@ public JpaBatchMetadata(String identifier, JavaType aspectName,
// Roo only use one field for pk
this.entityIdentifier = identifiers.iterator().next();

// Store jpa ActiveRecord info
this.activeRecordMetadata = entityActiveRecordMetadata;

// Store auditMetadata
this.auditMetadata = auditMetada;

Expand All @@ -190,10 +184,10 @@ public JpaBatchMetadata(String identifier, JavaType aspectName,
&& !this.hasEntityListeners;

// Get entity name
this.entityName = StringUtils.isBlank(this.activeRecordMetadata
.getEntityName()) ? entity.getSimpleTypeName()
: this.activeRecordMetadata.getEntityName();
this.entityPlural = entityActiveRecordMetadata.getPlural();
this.entityName = entity.getSimpleTypeName();

// Get entity plural name
this.entityPlural = entityPlural;

this.listOfIdentifiersType = new JavaType(
LIST.getFullyQualifiedTypeName(), 0, DataType.TYPE, null,
Expand Down
Expand Up @@ -34,6 +34,7 @@
import org.osgi.service.component.ComponentContext;
import org.springframework.roo.addon.jpa.addon.activerecord.JpaActiveRecordMetadata;
import org.springframework.roo.addon.jpa.addon.activerecord.JpaCrudAnnotationValues;
import org.springframework.roo.addon.plural.addon.PluralMetadata;
import org.springframework.roo.classpath.PhysicalTypeIdentifier;
import org.springframework.roo.classpath.PhysicalTypeMetadata;
import org.springframework.roo.classpath.details.ClassOrInterfaceTypeDetails;
Expand Down Expand Up @@ -145,20 +146,10 @@ protected ItdTypeDetailsProvidingMetadataItem getMetadata(
List<FieldMetadata> identifiers = getPersistenceMemberLocator()
.getIdentifierFields(targetEntity);

JpaActiveRecordMetadata entityMetadata = (JpaActiveRecordMetadata) getMetadataService()
.get(entityMetadataKey);

if (entityMetadata == null) {
return null;
}

// register downstream dependency (entityActiveRecord --> jpaBatch)
getMetadataDependencyRegistry().registerDependency(entityMetadataKey,
metadataIdentificationString);

JpaCrudAnnotationValues crudAnnotationValues = new JpaCrudAnnotationValues(
entityMetadata);

// check if entity use audit
String auditMetatadaKey = JpaAuditMetadata.createIdentifier(
targetEntity, path);
Expand All @@ -172,11 +163,20 @@ protected ItdTypeDetailsProvidingMetadataItem getMetadata(
boolean hasEntityListeners = getEntityListenerOperations()
.hasAnyListener(targetEntity);

// Getting plural
final String pluralId = PluralMetadata.createIdentifier(targetEntity,
path);
final PluralMetadata pluralMetadata = (PluralMetadata) getMetadataService()
.get(pluralId);
if (pluralMetadata == null) {
// Can't acquire the plural
return null;
}

// TODO get more data
return new JpaBatchMetadata(metadataIdentificationString, aspectName,
governorPhysicalTypeMetadata, annotationValues, identifiers,
entityMetadata, crudAnnotationValues, auditMetada,
hasEntityListeners);
pluralMetadata.getPlural(), auditMetada, hasEntityListeners);
}

/**
Expand Down

0 comments on commit bee48c1

Please sign in to comment.