use of org.springframework.roo.classpath.details.ClassOrInterfaceTypeDetails in project spring-roo by spring-projects.
the class ThymeleafMVCViewResponseService method addWebMVCThymeleafUIConfiguration.
/**
* This method adds new WebMVCThymeleafUIConfiguration.java class inside .config
* package of generated project
*
* @param module
*/
private void addWebMVCThymeleafUIConfiguration(Pom module) {
// Obtain the class annotated with @RooWebMvcConfiguration
Set<ClassOrInterfaceTypeDetails> webMvcConfigurationSet = getTypeLocationService().findClassesOrInterfaceDetailsWithAnnotation(RooJavaType.ROO_WEB_MVC_CONFIGURATION);
if (webMvcConfigurationSet == null || webMvcConfigurationSet.isEmpty()) {
throw new RuntimeException(String.format("ERROR: Can't found configuration class annotated with @%s.", RooJavaType.ROO_WEB_MVC_CONFIGURATION));
}
ClassOrInterfaceTypeDetails webMvcConfiguration = webMvcConfigurationSet.iterator().next();
// Prevent to include the @RooWebMvcThymeleafUIConfiguration more than once
if (webMvcConfiguration.getAnnotation(RooJavaType.ROO_WEB_MVC_THYMELEAF_UI_CONFIGURATION) == null) {
AnnotationMetadataBuilder thymeleaftConfigurationAnnotation = new AnnotationMetadataBuilder(RooJavaType.ROO_WEB_MVC_THYMELEAF_UI_CONFIGURATION);
ClassOrInterfaceTypeDetailsBuilder cidBuilder = new ClassOrInterfaceTypeDetailsBuilder(webMvcConfiguration);
;
cidBuilder.addAnnotation(thymeleaftConfigurationAnnotation);
getTypeManagementService().createOrUpdateTypeOnDisk(cidBuilder.build());
}
}
use of org.springframework.roo.classpath.details.ClassOrInterfaceTypeDetails in project spring-roo by spring-projects.
the class ThymeleafMVCViewResponseService method hasResponseType.
/**
* This operation will check if some controller has the @RooThymeleaf annotation
*
* @param controller JavaType with controller to check
* @return true if provided controller has the THYMELEAF 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 ThymeleafControllerIntegrationTestMetadataProviderImpl method getMetadata.
@Override
protected ItdTypeDetailsProvidingMetadataItem getMetadata(final String metadataIdentificationString, final JavaType aspectName, final PhysicalTypeMetadata governorPhysicalTypeMetadata, final String itdFilename) {
final ThymeleafControllerIntegrationTestAnnotationValues annotationValues = new ThymeleafControllerIntegrationTestAnnotationValues(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);
if (rooControllerAnnotation == null) {
LOGGER.warning(String.format("Ignoring %s of %s as missing %s annotation in %s", ROO_THYMELEAF_CONTROLLER_INTEGRATION_TEST.getSimpleTypeName(), governorPhysicalTypeMetadata.getType().getFullyQualifiedTypeName(), RooJavaType.ROO_CONTROLLER.getSimpleTypeName(), jsonController.getSimpleTypeName()));
return null;
}
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 metadata
String jpaEntityIdentifier = JpaEntityMetadata.createIdentifier(getTypeLocationService().getTypeDetails(managedEntity));
JpaEntityMetadata entityMetadata = getMetadataService().get(jpaEntityIdentifier);
if (entityMetadata == null) {
return null;
}
// Get child related entities
Collection<RelationInfo> relatioInfos = entityMetadata.getRelationInfos().values();
Set<JavaType> relatedEntities = new TreeSet<JavaType>();
// First, add managed entity
relatedEntities.add(managedEntity);
for (RelationInfo relationInfo : relatioInfos) {
if (relationInfo.cardinality == Cardinality.ONE_TO_ONE && relationInfo.type == JpaRelationType.COMPOSITION) {
// OneToOne composition is managed by owner's service
continue;
}
relatedEntities.add(relationInfo.childType);
}
// Get the entity factory of managed entity
final JavaType entityFactory = getJpaEntityFactoryLocator().getFirstJpaEntityFactoryForEntity(managedEntity);
// Get the services related to managed entity
List<JavaType> relatedServices = new ArrayList<JavaType>();
for (JavaType entity : relatedEntities) {
final ClassOrInterfaceTypeDetails serviceDetails = getServiceLocator().getFirstService(entity);
if (serviceDetails == null) {
LOGGER.warning(String.format("Couldn't find service of related entity %s in %s", entity.getSimpleTypeName(), this.getClass().getName()));
} else {
if (!relatedServices.contains(serviceDetails.getType())) {
relatedServices.add(serviceDetails.getType());
}
}
}
return new ThymeleafControllerIntegrationTestMetadata(metadataIdentificationString, aspectName, governorPhysicalTypeMetadata, annotationValues, jsonController, managedEntity, entityFactory, relatedServices);
}
use of org.springframework.roo.classpath.details.ClassOrInterfaceTypeDetails in project spring-roo by spring-projects.
the class WebFinderCommands method getEntityValues.
@CliOptionAutocompleteIndicator(param = "entity", command = "web mvc finder", help = "--entity parameter should be completed with classes annotated with @RooJpaEntity.")
public List<String> getEntityValues(ShellContext context) {
// Get current value of class
String currentText = context.getParameters().get("entity");
// Create results to return
List<String> results = new ArrayList<String>();
for (JavaType entity : getTypeLocationService().findTypesWithAnnotation(RooJavaType.ROO_JPA_ENTITY)) {
ClassOrInterfaceTypeDetails repository = repositoryJpaLocator.getFirstRepository(entity);
if (repository == null) {
continue;
}
AnnotationMetadata repositoryAnnotation = repository.getAnnotation(RooJavaType.ROO_REPOSITORY_JPA);
if (repositoryAnnotation.getAttribute("finders") == null) {
continue;
}
String name = replaceTopLevelPackageString(entity, currentText);
if (!results.contains(name)) {
results.add(name);
}
}
if (results.isEmpty()) {
results.add("");
}
return results;
}
use of org.springframework.roo.classpath.details.ClassOrInterfaceTypeDetails in project spring-roo by spring-projects.
the class I18nOperationsImpl method installLanguage.
@Override
public void installLanguage(final I18n language, final boolean useAsDefault, final Pom module) {
// Check if provided module match with application modules features
Validate.isTrue(getTypeLocationService().hasModuleFeature(module, ModuleFeatureName.APPLICATION), "ERROR: Provided module doesn't match with application modules features. " + "Execute this operation again and provide a valid application module.");
Validate.notNull(language, "ERROR: You should provide a valid language code.");
if (language.getLocale() == null) {
LOGGER.warning("ERROR: Provided language is not valid.");
return;
}
final LogicalPath resourcesPath = LogicalPath.getInstance(Path.SRC_MAIN_RESOURCES, module.getModuleName());
final String targetDirectory = getPathResolver().getIdentifier(resourcesPath, "");
// Getting message.properties file
String messageBundle = "";
if (language.getLocale().equals(Locale.ENGLISH)) {
messageBundle = targetDirectory + "messages.properties";
} else {
messageBundle = targetDirectory.concat("messages_").concat(language.getLocale().getLanguage().concat(".properties"));
}
if (!getFileManager().exists(messageBundle)) {
InputStream inputStream = null;
OutputStream outputStream = null;
try {
inputStream = language.getMessageBundle();
outputStream = getFileManager().createFile(messageBundle).getOutputStream();
IOUtils.copy(inputStream, outputStream);
} catch (final Exception e) {
throw new IllegalStateException("Encountered an error during copying of message bundle MVC JSP addon.", e);
} finally {
IOUtils.closeQuietly(inputStream);
IOUtils.closeQuietly(outputStream);
}
}
// Install flag
final String flagGraphic = targetDirectory.concat("static/public/img/").concat(language.getLocale().getLanguage()).concat(".png");
if (!getFileManager().exists(flagGraphic)) {
InputStream inputStream = null;
OutputStream outputStream = null;
try {
inputStream = language.getFlagGraphic();
outputStream = getFileManager().createFile(flagGraphic).getOutputStream();
IOUtils.copy(inputStream, outputStream);
} catch (final Exception e) {
throw new IllegalStateException("Encountered an error during copying of flag graphic for MVC JSP addon.", e);
} finally {
IOUtils.closeQuietly(inputStream);
IOUtils.closeQuietly(outputStream);
}
}
// attribute
if (useAsDefault) {
// Obtain all existing configuration classes annotated with
// @RooWebMvcConfiguration
Set<ClassOrInterfaceTypeDetails> configurationClasses = getTypeLocationService().findClassesOrInterfaceDetailsWithAnnotation(RooJavaType.ROO_WEB_MVC_CONFIGURATION);
for (ClassOrInterfaceTypeDetails configurationClass : configurationClasses) {
// If configuration class is located in the provided module
if (configurationClass.getType().getModule().equals(module.getModuleName())) {
ClassOrInterfaceTypeDetailsBuilder cidBuilder = new ClassOrInterfaceTypeDetailsBuilder(configurationClass);
AnnotationMetadataBuilder annotation = cidBuilder.getDeclaredTypeAnnotation(RooJavaType.ROO_WEB_MVC_CONFIGURATION);
annotation.addStringAttribute("defaultLanguage", language.getLocale().getLanguage());
// Update configuration class
getTypeManagementService().createOrUpdateTypeOnDisk(cidBuilder.build());
}
}
LOGGER.log(Level.INFO, String.format("INFO: Default language of your project has been changed to %s.", language.getLanguage()));
}
// Get all controllers and update its message bundles
Set<ClassOrInterfaceTypeDetails> controllers = getTypeLocationService().findClassesOrInterfaceDetailsWithAnnotation(RooJavaType.ROO_CONTROLLER);
for (ClassOrInterfaceTypeDetails controller : controllers) {
getMetadataService().evictAndGet(ControllerMetadata.createIdentifier(controller));
}
// Add application property
getApplicationConfigService().addProperty(module.getModuleName(), "spring.messages.fallback-to-system-locale", "false", "", true);
}
Aggregations