use of org.springframework.roo.classpath.details.ClassOrInterfaceTypeDetails in project spring-roo by spring-projects.
the class ControllerOperationsImpl method checkDetailControllerExists.
/**
* Check if detail controller exists for the values entity, responseType,
* controllerPackage, pathPrefix and relationField provided by parameters
*
* @param entity
* Detail controller entity
* @param responseType
* @param controllerPackage
* @param pathPrefix
* @param relationField
* @return
*/
private boolean checkDetailControllerExists(JavaType entity, ControllerMVCResponseService responseType, JavaPackage controllerPackage, String pathPrefix, String relationField) {
Collection<ClassOrInterfaceTypeDetails> detailControllers = getControllerLocator().getControllers(entity, ControllerType.DETAIL, responseType.getAnnotation());
for (ClassOrInterfaceTypeDetails existingController : detailControllers) {
if (existingController.getType().getPackage().equals(controllerPackage)) {
ControllerAnnotationValues values = new ControllerAnnotationValues(existingController);
AnnotationAttributeValue<String> relationFieldAttr = existingController.getAnnotation(RooJavaType.ROO_DETAIL).getAttribute("relationField");
if (StringUtils.equals(pathPrefix, values.getPathPrefix())) {
if (relationFieldAttr == null) {
LOGGER.warning(String.format("Controller %s is defined as @%.type = DETAIL but @%s is missing!", existingController.getType().getFullyQualifiedTypeName(), RooJavaType.ROO_CONTROLLER, RooJavaType.ROO_DETAIL));
} else if (relationField.equals(relationFieldAttr.getValue())) {
return true;
}
}
}
}
return false;
}
use of org.springframework.roo.classpath.details.ClassOrInterfaceTypeDetails in project spring-roo by spring-projects.
the class ControllerOperationsImpl method exportOperation.
/**
* Generate the operations selected in the controller indicated
*
* @param controller
* Controller where the operations will be created
* @param operations
* Service operations names that will be created
*/
public void exportOperation(JavaType controller, List<String> operations) {
ClassOrInterfaceTypeDetails controllerDetails = getTypeLocationService().getTypeDetails(controller);
// Check if provided controller exists on current project
Validate.notNull(controllerDetails, "ERROR: You must provide an existing controller");
// Check if provided controller has been annotated with @RooController
Validate.notNull(controllerDetails.getAnnotation(RooJavaType.ROO_CONTROLLER), "ERROR: You must provide a controller annotated with @RooController");
// Check parameter operations
Validate.notEmpty(operations, "INFO: Don't exist operations to publish");
ClassOrInterfaceTypeDetailsBuilder controllerBuilder = new ClassOrInterfaceTypeDetailsBuilder(controllerDetails);
AnnotationMetadata operationsAnnotation = controllerDetails.getAnnotation(RooJavaType.ROO_OPERATIONS);
// Create an array with new attributes array
List<StringAttributeValue> operationsToAdd = new ArrayList<StringAttributeValue>();
if (operationsAnnotation == null) {
// Add Operations annotation
AnnotationMetadataBuilder opAnnotation = new AnnotationMetadataBuilder(RooJavaType.ROO_OPERATIONS);
controllerBuilder.addAnnotation(opAnnotation);
// set operations from command
for (String operation : operations) {
operationsToAdd.add(new StringAttributeValue(new JavaSymbolName("value"), operation));
}
opAnnotation.addAttribute(new ArrayAttributeValue<StringAttributeValue>(new JavaSymbolName("operations"), operationsToAdd));
// Write changes on provided controller
getTypeManagementService().createOrUpdateTypeOnDisk(controllerBuilder.build());
} else {
List<String> operationsNames = new ArrayList<String>();
boolean operationsAdded = false;
AnnotationAttributeValue<Object> attributeOperations = operationsAnnotation.getAttribute("operations");
if (attributeOperations != null) {
List<StringAttributeValue> existingOperations = (List<StringAttributeValue>) attributeOperations.getValue();
Iterator<StringAttributeValue> it = existingOperations.iterator();
// new ones
while (it.hasNext()) {
StringAttributeValue attributeValue = (StringAttributeValue) it.next();
operationsToAdd.add(attributeValue);
operationsNames.add(attributeValue.getValue());
}
// Add new finders to new attributes array
for (String operation : operations) {
if (!operationsNames.contains(operation)) {
operationsToAdd.add(new StringAttributeValue(new JavaSymbolName("value"), operation));
operationsAdded = true;
}
}
if (operationsAdded) {
AnnotationMetadataBuilder opAnnotation = new AnnotationMetadataBuilder(operationsAnnotation);
opAnnotation.addAttribute(new ArrayAttributeValue<StringAttributeValue>(new JavaSymbolName("operations"), operationsToAdd));
controllerBuilder.updateTypeAnnotation(opAnnotation);
// Write changes on provided controller
getTypeManagementService().createOrUpdateTypeOnDisk(controllerBuilder.build());
}
}
}
}
use of org.springframework.roo.classpath.details.ClassOrInterfaceTypeDetails in project spring-roo by spring-projects.
the class ControllerOperationsImpl method getRelationInfoFor.
@Override
public List<RelationInfoExtended> getRelationInfoFor(final JavaType entity, final String path) {
Validate.notNull(entity, "entity is required");
Validate.notBlank(path, "path is required");
ClassOrInterfaceTypeDetails cid = getTypeLocationService().getTypeDetails(entity);
Validate.notNull(cid, "%s not found", entity.getFullyQualifiedTypeName());
JpaEntityMetadata entityMetada = getMetadataService().get(JpaEntityMetadata.createIdentifier(cid));
Validate.notNull(entityMetada, "Can't get Entity metadata information for %s", entity.getFullyQualifiedTypeName());
return getRelationInfoFor(entityMetada, path);
}
use of org.springframework.roo.classpath.details.ClassOrInterfaceTypeDetails in project spring-roo by spring-projects.
the class JsonControllerIntegrationTestMetadataProviderImpl method getMetadata.
@Override
protected ItdTypeDetailsProvidingMetadataItem getMetadata(final String metadataIdentificationString, final JavaType aspectName, final PhysicalTypeMetadata governorPhysicalTypeMetadata, final String itdFilename) {
final JsonControllerIntegrationTestAnnotationValues annotationValues = new JsonControllerIntegrationTestAnnotationValues(governorPhysicalTypeMetadata);
// Get JSON controller target class
final JavaType jsonController = annotationValues.getTargetClass();
// Get the controller managed entity
ClassOrInterfaceTypeDetails controllerCid = getTypeLocationService().getTypeDetails(jsonController);
AnnotationMetadata rooControllerAnnotation = controllerCid.getAnnotation(RooJavaType.ROO_CONTROLLER);
Validate.notNull(rooControllerAnnotation, "The target class must be annotated with @RooController.");
Validate.notNull(rooControllerAnnotation.getAttribute("entity"), "The @RooController must have an 'entity' attribute, targeting managed entity.");
final JavaType managedEntity = (JavaType) rooControllerAnnotation.getAttribute("entity").getValue();
// Get the entity factory of managed entity
final JavaType entityFactory = getJpaEntityFactoryLocator().getFirstJpaEntityFactoryForEntity(managedEntity);
// Get the service related to managed entity
final JavaType entityService = getServiceLocator().getFirstService(managedEntity).getType();
return new JsonControllerIntegrationTestMetadata(metadataIdentificationString, aspectName, governorPhysicalTypeMetadata, annotationValues, jsonController, managedEntity, entityFactory, entityService);
}
use of org.springframework.roo.classpath.details.ClassOrInterfaceTypeDetails in project spring-roo by spring-projects.
the class ThymeleafMVCViewResponseService method annotate.
/**
* This operation annotates a controller with the THYMELEAF annotation
*
* @param controller JavaType with the controller to be annotated.
*/
@Override
public void annotate(JavaType controller) {
Validate.notNull(controller, "ERROR: You must provide a valid controller");
ClassOrInterfaceTypeDetails controllerDetails = getTypeLocationService().getTypeDetails(controller);
// Check if provided controller exists on current project
Validate.notNull(controllerDetails, "ERROR: You must provide an existing controller");
// Check if provided controller has been annotated with @RooController
Validate.notNull(controllerDetails.getAnnotation(RooJavaType.ROO_CONTROLLER), "ERROR: You must provide a controller annotated with @RooController");
// Add Thymeleaf annotation
ClassOrInterfaceTypeDetailsBuilder typeBuilder = new ClassOrInterfaceTypeDetailsBuilder(controllerDetails);
typeBuilder.addAnnotation(new AnnotationMetadataBuilder(getAnnotation()));
// Write changes on provided controller
getTypeManagementService().createOrUpdateTypeOnDisk(typeBuilder.build());
}
Aggregations