use of org.springframework.roo.addon.web.mvc.controller.addon.responses.ControllerMVCResponseService in project spring-roo by spring-projects.
the class ControllerCommands method getInstalledControllerMVCResponseTypes.
/**
* This method gets all implementations of ControllerMVCResponseService
* interface to be able to locate all installed ControllerMVCResponseService
*
* @return Map with responseTypes identifier and the
* ControllerMVCResponseService implementation
*/
public Map<String, ControllerMVCResponseService> getInstalledControllerMVCResponseTypes() {
try {
ServiceReference<?>[] references = this.context.getAllServiceReferences(ControllerMVCResponseService.class.getName(), null);
for (ServiceReference<?> ref : references) {
ControllerMVCResponseService responseTypeService = (ControllerMVCResponseService) this.context.getService(ref);
boolean isInstalled = false;
for (Pom module : getProjectOperations().getPoms()) {
if (responseTypeService.isInstalledInModule(module.getModuleName())) {
isInstalled = true;
break;
}
}
if (isInstalled) {
responseTypes.put(responseTypeService.getResponseType(), responseTypeService);
}
}
return responseTypes;
} catch (InvalidSyntaxException e) {
LOGGER.warning("Cannot load ControllerMVCResponseService on ControllerCommands.");
return null;
}
}
use of org.springframework.roo.addon.web.mvc.controller.addon.responses.ControllerMVCResponseService in project spring-roo by spring-projects.
the class ViewCommands method getControllerMVCResponseTypes.
/**
* This method gets all implementations of ControllerMVCResponseService interface to be able
* to locate all ControllerMVCResponseService. Uses param installed to obtain only the installed
* or not installed response types.
*
* @param installed indicates if returned responseType should be installed or not.
*
* @return Map with responseTypes identifier and the ControllerMVCResponseService implementation
*/
public Map<String, ControllerMVCResponseService> getControllerMVCResponseTypes(boolean installed) {
Map<String, ControllerMVCResponseService> responseTypes = new HashMap<String, ControllerMVCResponseService>();
try {
ServiceReference<?>[] references = this.context.getAllServiceReferences(ControllerMVCResponseService.class.getName(), null);
for (ServiceReference<?> ref : references) {
ControllerMVCResponseService responseTypeService = (ControllerMVCResponseService) this.context.getService(ref);
boolean isAbleToInstall = false;
for (Pom module : getProjectOperations().getPoms()) {
if (responseTypeService.isInstalledInModule(module.getModuleName()) == installed) {
isAbleToInstall = true;
break;
}
}
if (isAbleToInstall) {
responseTypes.put(responseTypeService.getResponseType(), responseTypeService);
}
}
return responseTypes;
} catch (InvalidSyntaxException e) {
LOGGER.warning("Cannot load ControllerMVCResponseService on ViewCommands.");
return null;
}
}
use of org.springframework.roo.addon.web.mvc.controller.addon.responses.ControllerMVCResponseService in project spring-roo by spring-projects.
the class ControllerOperationsImpl method getInstalledControllerMVCResponseTypes.
/**
* This method gets all implementations of ControllerMVCResponseService
* interface to be able to locate all installed ControllerMVCResponseService
*
* @return Map with responseTypes identifier and the
* ControllerMVCResponseService implementation
*/
public Map<String, ControllerMVCResponseService> getInstalledControllerMVCResponseTypes() {
if (responseTypes.isEmpty()) {
try {
ServiceReference<?>[] references = this.context.getAllServiceReferences(ControllerMVCResponseService.class.getName(), null);
for (ServiceReference<?> ref : references) {
ControllerMVCResponseService responseTypeService = (ControllerMVCResponseService) this.context.getService(ref);
boolean isInstalled = false;
for (Pom module : getProjectOperations().getPoms()) {
if (responseTypeService.isInstalledInModule(module.getModuleName())) {
isInstalled = true;
break;
}
}
if (isInstalled) {
responseTypes.put(responseTypeService.getResponseType(), responseTypeService);
}
}
return responseTypes;
} catch (InvalidSyntaxException e) {
LOGGER.warning("Cannot load ControllerMVCResponseService on ControllerOperationsImpl.");
return null;
}
} else {
return responseTypes;
}
}
use of org.springframework.roo.addon.web.mvc.controller.addon.responses.ControllerMVCResponseService in project spring-roo by spring-projects.
the class WebFlowOperationsImpl method isWebFlowInstallationPossible.
@Override
public boolean isWebFlowInstallationPossible() {
if (getThymeleafViewResponseService() == null) {
return false;
}
// Check if Thymeleaf view support is installed in any module
boolean thymeleafInstalled = false;
List<ControllerMVCResponseService> responseServices = getThymeleafViewResponseService();
for (String moduleName : projectOperations.getModuleNames()) {
for (ControllerMVCResponseService responseService : responseServices) {
if (responseService.isInstalledInModule(moduleName)) {
thymeleafInstalled = true;
break;
}
}
}
return projectOperations.isFeatureInstalled(FeatureNames.MVC) && thymeleafInstalled;
}
use of org.springframework.roo.addon.web.mvc.controller.addon.responses.ControllerMVCResponseService in project spring-roo by spring-projects.
the class WebFinderCommands method addController.
/**
* This method provides the Command definition to be able to add
* new finder on controllers.
*
* @param controller
* @param all
* @param finder
* @param responseType
*/
@CliCommand(value = "web mvc finder", help = "Publishes existing finders to web layer, generating controllers and additional views for " + "them. It adds `@RooWebFinder` annotation to MVC controller type.")
public void addController(@CliOption(key = "entity", mandatory = false, help = "The entity owning the finders that should be published. When working on a single module " + "project, simply specify the name of the entity. If you consider it necessary, you can " + "also specify the package. Ex.: `--class ~.domain.MyEntity` (where `~` is the base " + "package). When working with multiple modules, you should specify the name of the entity " + "and the module where it is. Ex.: `--class model:~.domain.MyEntity`. If the module is not " + "specified, it is assumed that the entity is in the module which has the focus. " + "Possible values are: any of the entities in the project. " + "This option is mandatory if `--all` is not specified. Otherwise, using `--all` " + "will cause the parameter `--entity` won't be available.") JavaType entity, @CliOption(key = "all", mandatory = false, specifiedDefaultValue = "true", unspecifiedDefaultValue = "false", help = "Indicates if developer wants to publish in web layer all finders from all entities in " + "project. " + "This option is mandatory if `--entity` is not specified. Otherwise, using `--entity` " + "will cause the parameter `--all` won't be available. " + "Default if option present: `true`; default if option not present: `false`.") boolean all, @CliOption(key = "queryMethod", mandatory = false, help = "Indicates the name of the finder to add to web layer. " + "Possible values are: any of the finder names created for the entity, included in " + "`@RooJpaRepository` of the `--entity` associated repository. " + "This option is available only when `--entity` has been specified.") String queryMethod, @CliOption(key = "responseType", mandatory = false, help = "Indicates the responseType to be used by generated finder controllers. Depending on " + "the selected responseType, generated methods and views will vary. " + "Possible values are: `JSON` plus any response type installed with `web mvc view setup` " + "command. " + "This option is only available if `--all` or `--entity` parameters have been specified. " + "Default: `JSON`.") String responseType, @CliOption(key = "package", mandatory = true, unspecifiedDefaultValue = "~.web", help = "Indicates the Java package where the finder controllers should be generated. In" + " multi-module project you should specify the module name before the package name. " + "Ex.: `--package application:org.springframework.roo.web` but, if module name is not " + "present, the Roo Shell focused module will be used. " + "This option is available only if `--all` or `--entity` option has been specified. " + "Default value if not present: `~.web` package, or 'application:~.web' if multi-module " + "project.") JavaPackage controllerPackage, @CliOption(key = "pathPrefix", mandatory = false, unspecifiedDefaultValue = "", specifiedDefaultValue = "", help = "Indicates the default path value for accesing finder resources in controller, used for " + "this controller `@RequestMapping` excluding first '/'. " + "This option is available only if `--all` or `--entity` option has been specified.") String pathPrefix) {
// Getting --responseType service
Map<String, ControllerMVCResponseService> responseTypeServices = getInstalledControllerMVCResponseTypes();
// Validate that provided responseType is a valid provided
ControllerMVCResponseService controllerResponseType = null;
if (responseType != null) {
if (!responseTypeServices.containsKey(responseType)) {
LOGGER.log(Level.SEVERE, "ERROR: Provided responseType is not valid. Use autocomplete feature " + "to obtain valid responseTypes.");
return;
} else {
controllerResponseType = responseTypeServices.get(responseType);
}
} else {
controllerResponseType = responseTypeServices.get("JSON");
}
// Execute finder operation
if (!all) {
// Create queryMethods list
List<String> queryMethods = new ArrayList<String>();
if (queryMethod != null) {
queryMethods.add(queryMethod);
} else {
queryMethods = getFinders(entity, controllerResponseType);
}
webFinderOperations.createOrUpdateSearchControllerForEntity(entity, queryMethods, controllerResponseType, controllerPackage, pathPrefix);
} else {
webFinderOperations.createOrUpdateSearchControllerForAllEntities(controllerResponseType, controllerPackage, pathPrefix);
}
}
Aggregations