use of org.springframework.roo.classpath.scanner.MemberDetails in project spring-roo by spring-projects.
the class LinkFactoryMetadataProviderImpl method getMetadata.
@Override
protected ItdTypeDetailsProvidingMetadataItem getMetadata(final String metadataIdentificationString, final JavaType aspectName, final PhysicalTypeMetadata governorPhysicalTypeMetadata, final String itdFilename) {
// Get controller JavaType from @RooLinkFactory
LinkFactoryAnnotationValues annotationValues = new LinkFactoryAnnotationValues(governorPhysicalTypeMetadata);
JavaType controller = annotationValues.getController();
// Check if it is a valid controller
ClassOrInterfaceTypeDetails controllerDetails = getTypeLocationService().getTypeDetails(controller);
// Get ControllerMetadata to get info from it
String controllerMetadataKey = ControllerMetadata.createIdentifier(controllerDetails);
final ControllerMetadata controllerMetadata = getMetadataService().get(controllerMetadataKey);
// Get the controller methods
List<MethodMetadata> controllerMethods = new ArrayList<MethodMetadata>();
MemberDetails controllerMemberDetails = getMemberDetails(controllerDetails);
for (MethodMetadata method : controllerMemberDetails.getMethods()) {
// Check if is a @RequestMapping method
if (method.getAnnotation(SpringJavaType.GET_MAPPING) != null || method.getAnnotation(SpringJavaType.POST_MAPPING) != null || method.getAnnotation(SpringJavaType.PUT_MAPPING) != null || method.getAnnotation(SpringJavaType.DELETE_MAPPING) != null || method.getAnnotation(SpringJavaType.REQUEST_MAPPING) != null) {
controllerMethods.add(method);
}
}
return new LinkFactoryMetadata(metadataIdentificationString, aspectName, governorPhysicalTypeMetadata, controller, controllerMetadata, controllerMethods);
}
use of org.springframework.roo.classpath.scanner.MemberDetails in project spring-roo by spring-projects.
the class AbstractViewGenerationService method createDetailEntityItem.
/**
* Create a new instance of {@link DetailEntityItem}. Implementation can
* override this method to include it own information or extend defaults.
*
* @param detailController
* @param detailSuffix
* @param ctx
* @param string
* @param entityMetadata
* @param entity
* @return
*/
protected DetailEntityItem createDetailEntityItem(T detailController, MemberDetails entityMembers, JpaEntityMetadata entityMetadata, String entityName, ViewContext<T> ctx, String detailSuffix, EntityItem rootEntity) {
ControllerMetadata controllerMetadata = detailController.getControllerMetadata();
RelationInfoExtended last = controllerMetadata.getLastDetailsInfo();
ClassOrInterfaceTypeDetails childEntityDetails = getTypeLocationService().getTypeDetails(last.childType);
JpaEntityMetadata childEntityMetadata = last.childEntityMetadata;
String controllerPath = getControllerOperations().getBasePathForController(controllerMetadata.getDestination());
DetailEntityItem detailItem = new DetailEntityItem(childEntityMetadata, controllerMetadata, controllerPath, detailSuffix, rootEntity);
// Saving necessary configuration
detailItem.addConfigurationElement("referencedFieldType", last.childType.getSimpleTypeName());
// Getting identifier field
detailItem.addConfigurationElement("identifierField", childEntityMetadata.getCurrentIndentifierField().getFieldName().getSymbolName());
// Getting referencedfield label plural
detailItem.addConfigurationElement("referencedFieldLabel", FieldItem.buildLabel(entityName, last.fieldName));
// Getting all referenced fields
List<FieldMetadata> referencedFields = null;
// Get the repository related with the child entity to check the default return type
RepositoryJpaMetadata repository = getRepositoryJpaLocator().getFirstRepositoryMetadata(childEntityMetadata.getAnnotatedEntity());
// All views should have a repository
Validate.notNull(repository, "ERROR: The provided child 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();
if (defaultReturnTypeFields.isEmpty()) {
referencedFields = getEditableFields(getMemberDetailsScanner().getMemberDetails(getClass().toString(), childEntityDetails).getFields());
} else {
referencedFields = getEditableFields(defaultReturnTypeFields);
}
detailItem.addConfigurationElement("referenceFieldFields", getFieldViewItems(childEntityMetadata, referencedFields, entityName + "." + last.fieldName, true, ctx, StringUtils.EMPTY));
detailItem.addConfigurationElement("fields", getFieldViewItems(childEntityMetadata, referencedFields, detailItem.getEntityName(), true, ctx, StringUtils.EMPTY));
return detailItem;
}
use of org.springframework.roo.classpath.scanner.MemberDetails in project spring-roo by spring-projects.
the class AbstractViewGenerationService method addListDeleteModalView.
@Override
public void addListDeleteModalView(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("/listDeleteModal").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 = mergeListDeleteModalView("listDeleteModal", existingDoc, ctx, entityItem, fields);
}
} else {
ctx.addExtraParameter("entity", entityItem);
ctx.addExtraParameter("fields", fields);
newDoc = process("listDeleteModal", ctx);
}
// Write newDoc on disk
writeDoc(newDoc, viewName);
}
use of org.springframework.roo.classpath.scanner.MemberDetails in project spring-roo by spring-projects.
the class AbstractViewGenerationService method addListDeleteModalDetailView.
@Override
public void addListDeleteModalDetailView(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("/listDeleteModal").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 = mergeListDeleteModalDetailView("listDeleteModalDetail", existingDoc, ctx, entityItem, fields);
}
} else {
ctx.addExtraParameter("entity", entityItem);
ctx.addExtraParameter("fields", fields);
newDoc = process("listDeleteModalDetail", ctx);
}
// Write newDoc on disk
writeDoc(newDoc, viewName);
}
use of org.springframework.roo.classpath.scanner.MemberDetails in project spring-roo by spring-projects.
the class PersistenceMemberLocatorImpl method updateCache.
private void updateCache(final JavaType domainType) {
if (!haveAssociatedTypesChanged(domainType)) {
return;
}
final ClassOrInterfaceTypeDetails domainTypeDetails = typeLocationService.getTypeDetails(domainType);
if (domainTypeDetails == null || !domainTypeDetails.getCustomData().keySet().contains(CustomDataKeys.PERSISTENT_TYPE)) {
return;
}
final MemberDetails memberDetails = getMemberDetails(domainTypeDetails);
// Update normal persistence ID fields cache
populateIdTypes(memberDetails, domainType);
// Update normal persistence ID cache
populateIdFields(memberDetails, domainType);
// Update embedded ID fields cache
populateEmbeddedIdFields(memberDetails, domainType);
// Update ID accessor cache
populateIdAccessors(memberDetails, domainType);
// Update version field cache
populateVersionField(memberDetails, domainType);
// Update version accessor cache
populateVersionAccessor(memberDetails, domainType);
}
Aggregations