use of org.springframework.roo.classpath.details.ClassOrInterfaceTypeDetails in project spring-roo by spring-projects.
the class SecurityCommands method getAllServiceClassesAndInterfacesForAuthorize.
@CliOptionAutocompleteIndicator(command = "security authorize", param = "class", help = "You must select a valid Service class", validate = true)
public List<String> getAllServiceClassesAndInterfacesForAuthorize(ShellContext context) {
List<String> results = new ArrayList<String>();
Set<ClassOrInterfaceTypeDetails> services = typeLocationService.findClassesOrInterfaceDetailsWithAnnotation(RooJavaType.ROO_SERVICE, RooJavaType.ROO_SERVICE_IMPL);
for (ClassOrInterfaceTypeDetails service : services) {
results.add(replaceTopLevelPackageString(service, context.getParameters().get("class")));
}
return results;
}
use of org.springframework.roo.classpath.details.ClassOrInterfaceTypeDetails in project spring-roo by spring-projects.
the class SecurityCommands method getAllServiceClassesAndInterfacesForFiltering.
@CliOptionAutocompleteIndicator(command = "security filtering", param = "class", help = "You must select a valid Service class", validate = true)
public List<String> getAllServiceClassesAndInterfacesForFiltering(ShellContext context) {
List<String> results = new ArrayList<String>();
Set<ClassOrInterfaceTypeDetails> services = typeLocationService.findClassesOrInterfaceDetailsWithAnnotation(RooJavaType.ROO_SERVICE, RooJavaType.ROO_SERVICE_IMPL);
for (ClassOrInterfaceTypeDetails service : services) {
results.add(replaceTopLevelPackageString(service, context.getParameters().get("class")));
}
return results;
}
use of org.springframework.roo.classpath.details.ClassOrInterfaceTypeDetails in project spring-roo by spring-projects.
the class JSONMVCResponseService method hasResponseType.
/**
* This operation will check if some controller has the @RooJSON annotation
*
* @param controller JavaType with controller to check
* @return true if provided controller has the JSON responseType.
* If not, return false.
*/
@Override
public boolean hasResponseType(JavaType controller) {
Validate.notNull(controller, "ERROR: You must provide a valid controller");
ClassOrInterfaceTypeDetails controllerDetails = getTypeLocationService().getTypeDetails(controller);
if (controllerDetails == null) {
return false;
}
return controllerDetails.getAnnotation(getAnnotation()) != null;
}
use of org.springframework.roo.classpath.details.ClassOrInterfaceTypeDetails in project spring-roo by spring-projects.
the class JsonControllerTestCreator method createIntegrationTest.
@Override
public void createIntegrationTest(JavaType type, Pom module) {
Validate.notNull(type, "Class to produce an integration test class for is required");
// Check if provided JavaType is a JSON Controller
ClassOrInterfaceTypeDetails cid = typeLocationService.getTypeDetails(type);
Validate.notNull(cid.getAnnotation(RooJavaType.ROO_CONTROLLER), "Type must be a Roo controller.");
Validate.notNull(cid.getAnnotation(RooJavaType.ROO_JSON), "Type must be a Roo JSON controller.");
// Add springlets-boot-starter-test dependency
projectOperations.addProperty("", SPRINGLETS_VERSION_PROPERTY);
projectOperations.addDependency(module.getModuleName(), SPRINGLETS_BOOT_STARTER_TEST_DEPENDENCY);
// Get the controller managed entity
ControllerAnnotationValues controllerAnnotationValues = new ControllerAnnotationValues(cid);
JavaType managedEntity = controllerAnnotationValues.getEntity();
// Workaround to get a JavaType with not null module when recovering it
// from a ClassAttributeValue
managedEntity = new JavaType(managedEntity.getFullyQualifiedTypeName(), managedEntity.getArray(), managedEntity.getDataType(), managedEntity.getArgName(), managedEntity.getParameters(), typeLocationService.getTypeDetails(managedEntity).getType().getModule());
// Create Data On Demand artifacts for managed entity
List<DataOnDemandCreatorProvider> dodCreators = getValidDataOnDemandCreatorsForType(managedEntity);
Validate.isTrue(!dodCreators.isEmpty(), "Couldn't find any 'DataOnDemandCreatorProvider' for JSON controllers.");
Validate.isTrue(dodCreators.size() == 1, "More than 1 valid 'DataOnDemandCreatorProvider' found for JSON controllers. %s can't decide which one to use.", this.getClass().getName());
DataOnDemandCreatorProvider creator = dodCreators.get(0);
creator.createDataOnDemand(managedEntity);
// Add module dependency with test-jar dependency
if (projectOperations.isMultimoduleProject()) {
String managedEntityModuleName = managedEntity.getModule();
Pom managedEntityModule = projectOperations.getPomFromModuleName(managedEntityModuleName);
projectOperations.addDependency(module.getModuleName(), new Dependency(managedEntityModule.getGroupId(), managedEntityModule.getArtifactId(), "${project.version}", DependencyType.valueOfTypeCode("test-jar"), DependencyScope.TEST), true, true);
}
// Create integration test class
final JavaType name = new JavaType(type + "IT", module.getModuleName());
final String declaredByMetadataId = PhysicalTypeIdentifier.createIdentifier(name, Path.SRC_TEST_JAVA.getModulePathId(module.getModuleName()));
if (metadataService.get(declaredByMetadataId) != null) {
// The file already exists
return;
}
// Add @RooJsonControllerIntegrationTest to source file
AnnotationMetadataBuilder rooIntegrationTestAnnotation = new AnnotationMetadataBuilder(RooJavaType.ROO_JSON_CONTROLLER_INTEGRATION_TEST);
rooIntegrationTestAnnotation.addClassAttribute("targetClass", type);
// Create integration test class
final ClassOrInterfaceTypeDetailsBuilder cidBuilder = new ClassOrInterfaceTypeDetailsBuilder(declaredByMetadataId, Modifier.PUBLIC, name, PhysicalTypeCategory.CLASS);
cidBuilder.addAnnotation(rooIntegrationTestAnnotation);
// Write changes to disk
typeManagementService.createOrUpdateTypeOnDisk(cidBuilder.build());
}
use of org.springframework.roo.classpath.details.ClassOrInterfaceTypeDetails in project spring-roo by spring-projects.
the class EmbeddableFieldCreatorProvider method createEmbeddedField.
@Override
public void createEmbeddedField(JavaType typeName, JavaType fieldType, JavaSymbolName fieldName, boolean permitReservedWords, List<AnnotationMetadataBuilder> extraAnnotations) {
// Check if the requested entity is a JPA @Entity
final ClassOrInterfaceTypeDetails javaTypeDetails = typeLocationService.getTypeDetails(typeName);
Validate.notNull(javaTypeDetails, "The type specified, '%s', doesn't exist", typeName);
final String physicalTypeIdentifier = javaTypeDetails.getDeclaredByMetadataId();
final PhysicalTypeMetadata targetTypeMetadata = (PhysicalTypeMetadata) metadataService.get(physicalTypeIdentifier);
Validate.notNull(targetTypeMetadata, "The specified target '--class' does not exist or can not be found. Please create this type first.");
final PhysicalTypeDetails targetPtd = targetTypeMetadata.getMemberHoldingTypeDetails();
Validate.isInstanceOf(MemberHoldingTypeDetails.class, targetPtd);
final ClassOrInterfaceTypeDetails targetTypeCid = (ClassOrInterfaceTypeDetails) targetPtd;
final MemberDetails memberDetails = memberDetailsScanner.getMemberDetails(this.getClass().getName(), targetTypeCid);
Validate.isTrue(memberDetails.getAnnotation(ENTITY) != null || memberDetails.getAnnotation(PERSISTENT) != null, "The field embedded command is only applicable to JPA @Entity or Spring Data @Persistent target types.");
final EmbeddedField fieldDetails = new EmbeddedField(physicalTypeIdentifier, fieldType, fieldName);
if (extraAnnotations != null && !extraAnnotations.isEmpty()) {
fieldDetails.addAnnotations(extraAnnotations);
}
insertField(fieldDetails, permitReservedWords, false);
}
Aggregations