use of org.springframework.roo.addon.layers.repository.jpa.addon.RepositoryJpaMetadata in project spring-roo by spring-projects.
the class AbstractViewGenerationService method addListDeleteModalBatchView.
@Override
public void addListDeleteModalBatchView(String moduleName, JpaEntityMetadata entityMetadata, MemberDetails entity, ViewContext<T> ctx) {
// Get the repository related with the entity to check the default return type
RepositoryJpaMetadata repository = getRepositoryJpaLocator().getFirstRepositoryMetadata(entityMetadata.getAnnotatedEntity());
// All views should have a repository
Validate.notNull(repository, "ERROR: The provided entity should have an associated repository to be able " + "to generate the list view.");
// Obtain the defaultReturnType
JavaType defaultReturnType = repository.getDefaultReturnType();
// The defaultReturnType must not be null. If it's not an entity projection,
// it must be an entity
Validate.notNull(defaultReturnType, "ERROR: The repository associated to the provided entity should define a defaultReturnType");
// Obtain details of the provided defaultReturnType. If not exists as type, show an error
ClassOrInterfaceTypeDetails defaultReturnTypeCid = getTypeLocationService().getTypeDetails(defaultReturnType);
Validate.notNull(defaultReturnTypeCid, "ERROR: The provided defaultReturnType is not a valid type");
MemberDetails defaultReturnTypeDetails = getMemberDetailsScanner().getMemberDetails(getClass().toString(), defaultReturnTypeCid);
Validate.notNull(defaultReturnTypeDetails, "ERROR: Is not possible to obtain any detail from the " + "provided defaultReturnType.");
List<FieldMetadata> defaultReturnTypeFields = defaultReturnTypeDetails.getFields();
// all the entity fields will be used
if (defaultReturnTypeFields.isEmpty()) {
defaultReturnTypeFields = entity.getFields();
}
// Getting entity fields that should be included on view
List<FieldMetadata> entityFields = getPersistentFields(defaultReturnTypeFields);
List<FieldItem> fields = getFieldViewItems(entityMetadata, entityFields, ctx.getEntityName(), true, ctx, TABLE_SUFFIX);
// Process elements to generate
DOC newDoc = null;
// Getting new viewName
String viewName = getViewsFolder(moduleName).concat(ctx.getControllerPath()).concat("/").concat("/listDeleteModalBatch").concat(getViewsExtension());
EntityItem entityItem = createEntityItem(entityMetadata, ctx, TABLE_SUFFIX);
// Check if new view to generate exists or not
if (existsFile(viewName)) {
DOC existingDoc = loadExistingDoc(viewName);
if (!isUserManagedDocument(existingDoc)) {
newDoc = mergeListDeleteModalBatchView("listDeleteModalBatch", loadExistingDoc(viewName), ctx, entityItem, fields);
}
} else {
ctx.addExtraParameter("entity", entityItem);
ctx.addExtraParameter("fields", fields);
newDoc = process("listDeleteModalBatch", ctx);
}
// Write newDoc on disk
writeDoc(newDoc, viewName);
}
use of org.springframework.roo.addon.layers.repository.jpa.addon.RepositoryJpaMetadata in project spring-roo by spring-projects.
the class AbstractViewGenerationService method addListDeleteModalDetailBatchView.
@Override
public void addListDeleteModalDetailBatchView(String moduleName, JpaEntityMetadata entityMetadata, MemberDetails entity, ControllerMetadata controllerMetadata, ViewContext<T> ctx) {
// Get the repository related with the entity to check the default return type
RepositoryJpaMetadata repository = getRepositoryJpaLocator().getFirstRepositoryMetadata(entityMetadata.getAnnotatedEntity());
// All views should have a repository
Validate.notNull(repository, "ERROR: The provided entity should have an associated repository to be able " + "to generate the list view.");
// Obtain the defaultReturnType
JavaType defaultReturnType = repository.getDefaultReturnType();
// The defaultReturnType must not be null. If it's not an entity projection,
// it must be an entity
Validate.notNull(defaultReturnType, "ERROR: The repository associated to the provided entity should define a defaultReturnType");
// Obtain details of the provided defaultReturnType. If not exists as type, show an error
ClassOrInterfaceTypeDetails defaultReturnTypeCid = getTypeLocationService().getTypeDetails(defaultReturnType);
Validate.notNull(defaultReturnTypeCid, "ERROR: The provided defaultReturnType is not a valid type");
MemberDetails defaultReturnTypeDetails = getMemberDetailsScanner().getMemberDetails(getClass().toString(), defaultReturnTypeCid);
Validate.notNull(defaultReturnTypeDetails, "ERROR: Is not possible to obtain any detail from the " + "provided defaultReturnType.");
List<FieldMetadata> defaultReturnTypeFields = defaultReturnTypeDetails.getFields();
// all the entity fields will be used
if (defaultReturnTypeFields.isEmpty()) {
defaultReturnTypeFields = entity.getFields();
}
// Getting entity fields that should be included on view
List<FieldMetadata> entityFields = getPersistentFields(defaultReturnTypeFields);
List<FieldItem> fields = getFieldViewItems(entityMetadata, entityFields, ctx.getEntityName(), true, ctx, TABLE_SUFFIX);
// Process elements to generate
DOC newDoc = null;
// Getting new viewName
String viewName = getViewsFolder(moduleName).concat(ctx.getControllerPath()).concat("/").concat(controllerMetadata.getDetailsPathAsString("/")).concat("/listDeleteModalBatch").concat(getViewsExtension());
EntityItem entityItem = createEntityItem(entityMetadata, ctx, TABLE_SUFFIX);
// Check if new view to generate exists or not
if (existsFile(viewName)) {
DOC existingDoc = loadExistingDoc(viewName);
if (!isUserManagedDocument(existingDoc)) {
newDoc = mergeListDeleteModalBatchDetailView("listDeleteModalBatchDetail", loadExistingDoc(viewName), ctx, entityItem, fields);
}
} else {
ctx.addExtraParameter("entity", entityItem);
ctx.addExtraParameter("fields", fields);
newDoc = process("listDeleteModalBatchDetail", ctx);
}
// Write newDoc on disk
writeDoc(newDoc, viewName);
}
use of org.springframework.roo.addon.layers.repository.jpa.addon.RepositoryJpaMetadata in project spring-roo by spring-projects.
the class AbstractViewGenerationService method addListView.
@Override
public void addListView(String moduleName, JpaEntityMetadata entityMetadata, MemberDetails entity, List<T> detailsControllers, ViewContext<T> ctx) {
// Get the repository related with the entity to check the default return type
RepositoryJpaMetadata repository = getRepositoryJpaLocator().getFirstRepositoryMetadata(entityMetadata.getAnnotatedEntity());
// All views should have a repository
Validate.notNull(repository, "ERROR: The provided entity should have an associated repository to be able " + "to generate the list view.");
// Obtain the defaultReturnType
JavaType defaultReturnType = repository.getDefaultReturnType();
// The defaultReturnType must not be null. If it's not an entity projection,
// it must be an entity
Validate.notNull(defaultReturnType, "ERROR: The repository associated to the provided entity should define a defaultReturnType");
// Obtain details of the provided defaultReturnType. If not exists as type, show an error
ClassOrInterfaceTypeDetails defaultReturnTypeCid = getTypeLocationService().getTypeDetails(defaultReturnType);
Validate.notNull(defaultReturnTypeCid, "ERROR: The provided defaultReturnType is not a valid type");
MemberDetails defaultReturnTypeDetails = getMemberDetailsScanner().getMemberDetails(getClass().toString(), defaultReturnTypeCid);
Validate.notNull(defaultReturnTypeDetails, "ERROR: Is not possible to obtain any detail from the " + "provided defaultReturnType.");
List<FieldMetadata> defaultReturnTypeFields = defaultReturnTypeDetails.getFields();
// all the entity fields will be used
if (defaultReturnTypeFields.isEmpty()) {
defaultReturnTypeFields = entity.getFields();
}
// Getting entity fields that should be included on view
List<FieldMetadata> entityFields = getPersistentFields(defaultReturnTypeFields);
List<FieldItem> fields = getFieldViewItems(entityMetadata, entityFields, ctx.getEntityName(), true, ctx, TABLE_SUFFIX);
// Process elements to generate
DOC newDoc = null;
// Getting new viewName
String viewName = getViewsFolder(moduleName).concat(ctx.getControllerPath()).concat("/").concat("/list").concat(getViewsExtension());
EntityItem entityItem = createEntityItem(entityMetadata, ctx, TABLE_SUFFIX);
List<List<DetailEntityItem>> detailsLevels = new ArrayList<List<DetailEntityItem>>();
if (detailsControllers != null && !detailsControllers.isEmpty()) {
List<DetailEntityItem> details = new ArrayList<DetailEntityItem>();
for (T detailController : detailsControllers) {
DetailEntityItem detailItem = createDetailEntityItem(detailController, entity, entityMetadata, ctx.getEntityName(), ctx, DETAIL_SUFFIX, entityItem);
details.add(detailItem);
}
// Sort details by path
Collections.sort(details, new Comparator<DetailEntityItem>() {
@Override
public int compare(DetailEntityItem o1, DetailEntityItem o2) {
return o1.getPathString().compareTo(o2.getPathString());
}
});
// levels
for (DetailEntityItem detail : details) {
// Create group until item level
while (detailsLevels.size() < detail.getLevel()) {
detailsLevels.add(new ArrayList<DetailEntityItem>());
}
// Include detail in its group
detailsLevels.get(detail.getLevel() - 1).add(detail);
if (detail.getLevel() < 1) {
// Nothing more to do with detail
continue;
}
// look for parent
for (DetailEntityItem parent : details) {
if (detail.isTheParentEntity(parent)) {
// set parent
detail.setParentEntity(parent);
break;
}
}
}
}
// Check if new view to generate exists or not
if (existsFile(viewName)) {
DOC existingDoc = loadExistingDoc(viewName);
if (!isUserManagedDocument(existingDoc)) {
newDoc = mergeListView("list", existingDoc, ctx, entityItem, fields, detailsLevels);
}
} else {
ctx.addExtraParameter("entity", entityItem);
ctx.addExtraParameter("fields", fields);
ctx.addExtraParameter("detailsLevels", detailsLevels);
newDoc = process("list", ctx);
}
// Write newDoc on disk
writeDoc(newDoc, viewName);
}
use of org.springframework.roo.addon.layers.repository.jpa.addon.RepositoryJpaMetadata in project spring-roo by spring-projects.
the class RepositoryJpaIntegrationTestMetadataProviderImpl method getMetadata.
@Override
protected ItdTypeDetailsProvidingMetadataItem getMetadata(final String metadataIdentificationString, final JavaType aspectName, final PhysicalTypeMetadata governorPhysicalTypeMetadata, final String itdFilename) {
final RepositoryJpaIntegrationTestAnnotationValues annotationValues = new RepositoryJpaIntegrationTestAnnotationValues(governorPhysicalTypeMetadata);
// Find SpringJpaDataDetachableConfiguration class
Set<JavaType> jpaConfigurationClasses = getTypeLocationService().findTypesWithAnnotation(RooJavaType.ROO_JPA_REPOSITORY_CONFIGURATION);
Validate.isTrue(!jpaConfigurationClasses.isEmpty(), "Couldn't find the 'SpringDataJpaDetachableRepositoryConfiguration' on the project for '%s'", this.getClass().getName());
JavaType jpaDetachableRepositoryClass = jpaConfigurationClasses.iterator().next();
// Get repository metadata
JavaType repositoryInterface = annotationValues.getTargetClass();
ClassOrInterfaceTypeDetails repositoryDetails = getTypeLocationService().getTypeDetails(repositoryInterface);
Validate.notNull(repositoryDetails.getAnnotation(RooJavaType.ROO_REPOSITORY_JPA), "Couldn't find @RooJpaRepository in '%s'", repositoryInterface.getSimpleTypeName());
String repositoryMetadataId = RepositoryJpaMetadata.createIdentifier(repositoryDetails);
RepositoryJpaMetadata repositoryMetadata = getMetadataService().get(repositoryMetadataId);
if (repositoryMetadata == null) {
return null;
}
// Get entity identifier info
JavaType entity = repositoryMetadata.getEntity();
JavaType identifierType = getPersistenceMemberLocator().getIdentifierType(entity);
JavaSymbolName identifierAccessorMethodName = getPersistenceMemberLocator().getIdentifierAccessor(entity).getMethodName();
// Get entity metadata
ClassOrInterfaceTypeDetails entityDetails = getTypeLocationService().getTypeDetails(entity);
String jpaEntityMetadataId = JpaEntityMetadata.createIdentifier(entityDetails);
JpaEntityMetadata jpaEntityMetadata = getMetadataService().get(jpaEntityMetadataId);
if (jpaEntityMetadata == null) {
return null;
}
// Get entity read only
boolean isReadOnly = jpaEntityMetadata.isReadOnly();
// Get entity plural
String entityPlural = getPluralService().getPlural(entity);
// Get repository default return type
JavaType defaultReturnType = repositoryMetadata.getDefaultReturnType();
return new RepositoryJpaIntegrationTestMetadata(metadataIdentificationString, aspectName, governorPhysicalTypeMetadata, annotationValues, jpaDetachableRepositoryClass, identifierType, identifierAccessorMethodName, entityPlural, entity, defaultReturnType, isReadOnly);
}
use of org.springframework.roo.addon.layers.repository.jpa.addon.RepositoryJpaMetadata in project spring-roo by spring-projects.
the class ServiceImplMetadataProviderImpl method getMetadata.
@Override
protected ItdTypeDetailsProvidingMetadataItem getMetadata(final String metadataIdentificationString, final JavaType aspectName, final PhysicalTypeMetadata governorPhysicalTypeMetadata, final String itdFilename) {
final ServiceImplAnnotationValues annotationValues = new ServiceImplAnnotationValues(governorPhysicalTypeMetadata);
// Getting service interface
JavaType serviceInterface = annotationValues.getService();
ClassOrInterfaceTypeDetails serviceInterfaceDetails = getTypeLocationService().getTypeDetails(serviceInterface);
final ServiceMetadata serviceMetadata = getServiceMetadata(metadataIdentificationString, serviceInterfaceDetails);
AnnotationMetadata serviceAnnotation = serviceInterfaceDetails.getAnnotation(RooJavaType.ROO_SERVICE);
Validate.notNull(serviceAnnotation, "ERROR: Provided service should be annotated with @RooService");
JavaType entity = (JavaType) serviceAnnotation.getAttribute("entity").getValue();
ClassOrInterfaceTypeDetails entityDetails = getTypeLocationService().getTypeDetails(entity);
final String entityMetadataId = JpaEntityMetadata.createIdentifier(entityDetails.getType(), PhysicalTypeIdentifier.getPath(entityDetails.getDeclaredByMetadataId()));
final JpaEntityMetadata entityMetadata = (JpaEntityMetadata) getMetadataService().get(entityMetadataId);
// Add dependencies between modules
if (serviceMetadata != null) {
for (MethodMetadata method : serviceMetadata.getAllMethods()) {
List<JavaType> types = new ArrayList<JavaType>();
types.add(method.getReturnType());
types.addAll(method.getReturnType().getParameters());
for (AnnotatedJavaType parameter : method.getParameterTypes()) {
types.add(AnnotatedJavaType.convertFromAnnotatedJavaType(parameter));
types.addAll(AnnotatedJavaType.convertFromAnnotatedJavaType(parameter).getParameters());
}
for (JavaType parameter : types) {
getTypeLocationService().addModuleDependency(governorPhysicalTypeMetadata.getType().getModule(), parameter);
}
}
}
// Getting associated repository
ClassOrInterfaceTypeDetails repositoryDetails = getRepositoryJpaLocator().getRepository(entity);
final String repositoryMetadataId = RepositoryJpaMetadata.createIdentifier(repositoryDetails.getType(), PhysicalTypeIdentifier.getPath(repositoryDetails.getDeclaredByMetadataId()));
final RepositoryJpaMetadata repositoryMetadata = (RepositoryJpaMetadata) getMetadataService().get(repositoryMetadataId);
// Locate related services API types required by relations
Map<JavaType, ServiceMetadata> requiredServicesByEntity = new HashMap<JavaType, ServiceMetadata>();
ClassOrInterfaceTypeDetails relatedService;
for (RelationInfo info : entityMetadata.getRelationInfos().values()) {
if (info.cardinality != Cardinality.ONE_TO_ONE && !requiredServicesByEntity.containsKey(info.childType)) {
relatedService = getServiceLocator().getFirstService(info.childType);
if (relatedService != null) {
requiredServicesByEntity.put(info.childType, getServiceMetadata(metadataIdentificationString, relatedService));
}
}
}
// Get child relations info
List<Pair<FieldMetadata, RelationInfo>> childRelationsInfo = getJpaOperations().getFieldChildPartOfRelation(entityDetails);
return new ServiceImplMetadata(metadataIdentificationString, aspectName, governorPhysicalTypeMetadata, serviceInterface, repositoryDetails.getType(), repositoryMetadata, entity, entityMetadata, serviceMetadata, requiredServicesByEntity, childRelationsInfo);
}
Aggregations