use of org.springframework.roo.project.LogicalPath in project spring-roo by spring-projects.
the class PluralMetadataProviderImpl method getGovernorPhysicalTypeIdentifier.
@Override
protected String getGovernorPhysicalTypeIdentifier(final String metadataIdentificationString) {
final JavaType javaType = PluralMetadata.getJavaType(metadataIdentificationString);
final LogicalPath path = PluralMetadata.getPath(metadataIdentificationString);
return PhysicalTypeIdentifier.createIdentifier(javaType, path);
}
use of org.springframework.roo.project.LogicalPath in project spring-roo by spring-projects.
the class PluralServiceImpl method getPlural.
@Override
public String getPlural(ClassOrInterfaceTypeDetails cid, Locale locale) {
Validate.notNull(cid, "ERROR: You must provide a valid ClassOrInterfaceTypeDetails");
Validate.notNull(locale, "ERROR: You must provide a valid Locale");
final JavaType javaType = cid.getType();
final LogicalPath logicalPath = PhysicalTypeIdentifier.getPath(cid.getDeclaredByMetadataId());
final String pluralMetadataKey = PluralMetadata.createIdentifier(javaType, logicalPath);
final PluralMetadata pluralMetadata = (PluralMetadata) getMetadataService().get(pluralMetadataKey);
if (pluralMetadata != null) {
final String plural = pluralMetadata.getPlural();
if (plural.equalsIgnoreCase(javaType.getSimpleTypeName())) {
return plural + "Items";
} else {
return plural;
}
}
return getPlural(javaType.getSimpleTypeName(), locale);
}
use of org.springframework.roo.project.LogicalPath in project spring-roo by spring-projects.
the class ThymeleafMainControllerMetadataProviderImpl method getGovernorPhysicalTypeIdentifier.
@Override
protected String getGovernorPhysicalTypeIdentifier(final String metadataIdentificationString) {
final JavaType javaType = ThymeleafMainControllerMetadata.getJavaType(metadataIdentificationString);
final LogicalPath path = ThymeleafMainControllerMetadata.getPath(metadataIdentificationString);
return PhysicalTypeIdentifier.createIdentifier(javaType, path);
}
use of org.springframework.roo.project.LogicalPath in project spring-roo by spring-projects.
the class ControllerOperationsImpl method createOrUpdateControllerForEntity.
@Override
public void createOrUpdateControllerForEntity(JavaType entity, ControllerMVCResponseService responseType, JavaPackage controllerPackage, String pathPrefix) {
// Getting entity details to obtain information about it
ClassOrInterfaceTypeDetails entityDetails = getTypeLocationService().getTypeDetails(entity);
AnnotationMetadata entityAnnotation = entityDetails.getAnnotation(RooJavaType.ROO_JPA_ENTITY);
if (entityAnnotation == null) {
LOGGER.log(Level.INFO, String.format("ERROR: The provided class %s is not a valid entity. It should be annotated with @RooEntity", entity.getSimpleTypeName()));
return;
}
JpaEntityMetadata entityMetadata = getMetadataService().get(JpaEntityMetadata.createIdentifier(entityDetails));
if (entityMetadata.isCompositionChild()) {
// Don't generate Controller for composition Child entities
LOGGER.log(Level.INFO, String.format("INFO: The provided class %s is composition child part of a relationship. No controller is needed as it's managed form parent controller", entity.getSimpleTypeName()));
return;
}
// Getting related service
JavaType service = null;
ClassOrInterfaceTypeDetails serviceDetails = getServiceLocator().getService(entity);
if (serviceDetails == null) {
// Is necessary at least one service to generate controller
LOGGER.log(Level.INFO, String.format("ERROR: You must generate a service to '%s' entity before to generate a new controller.", entity.getFullyQualifiedTypeName()));
return;
}
service = serviceDetails.getName();
Collection<ClassOrInterfaceTypeDetails> controllers = getControllerLocator().getControllers(entity);
// Check controllersPackage value
if (controllerPackage == null) {
controllerPackage = getDefaultControllerPackage();
if (controllerPackage == null) {
return;
}
}
ControllerAnnotationValues values;
for (ClassOrInterfaceTypeDetails existingController : controllers) {
values = new ControllerAnnotationValues(existingController);
if ((values.getType() == ControllerType.COLLECTION || values.getType() == ControllerType.ITEM)) {
if (StringUtils.equals(values.getPathPrefix(), pathPrefix) && existingController.getAnnotation(responseType.getAnnotation()) != null) {
LOGGER.log(Level.INFO, String.format("ERROR: Already exists a controller associated to entity '%s' with the " + "pathPrefix '%s' for this responseType. Specify different one " + "using --pathPrefix or --responseType parameter.", entity.getSimpleTypeName(), pathPrefix));
return;
}
}
}
// Generate Collection controller JavaType
String entityPluralCapitalized = StringUtils.capitalize(getPluralService().getPlural(entity));
JavaType collectionController = new JavaType(String.format("%s.%sCollection%sController", controllerPackage.getFullyQualifiedPackageName(), entityPluralCapitalized, responseType.getControllerNameModifier()), controllerPackage.getModule());
ClassOrInterfaceTypeDetails collectionControllerDetails = getTypeLocationService().getTypeDetails(collectionController);
if (collectionControllerDetails == null) {
List<AnnotationMetadataBuilder> annotations = new ArrayList<AnnotationMetadataBuilder>();
annotations.add(getRooControllerAnnotation(entity, pathPrefix, ControllerType.COLLECTION));
// Add responseType annotation. Don't use responseTypeService
// annotate to
// prevent multiple
// updates of the .java file. Annotate operation will be used during
// controller update.
annotations.add(new AnnotationMetadataBuilder(responseType.getAnnotation()));
final LogicalPath controllerPath = getPathResolver().getPath(collectionController.getModule(), Path.SRC_MAIN_JAVA);
final String resourceIdentifier = getTypeLocationService().getPhysicalTypeCanonicalPath(collectionController, controllerPath);
final String declaredByMetadataId = PhysicalTypeIdentifier.createIdentifier(collectionController, getPathResolver().getPath(resourceIdentifier));
ClassOrInterfaceTypeDetailsBuilder cidBuilder = new ClassOrInterfaceTypeDetailsBuilder(declaredByMetadataId, Modifier.PUBLIC, collectionController, PhysicalTypeCategory.CLASS);
cidBuilder.setAnnotations(annotations);
getTypeManagementService().createOrUpdateTypeOnDisk(cidBuilder.build());
// Create LinkFactory class
if (responseType.getName().equals("THYMELEAF")) {
createLinkFactoryClass(cidBuilder.getName());
}
} else {
LOGGER.log(Level.INFO, String.format("ERROR: The controller %s already exists.", collectionController.getFullyQualifiedTypeName()));
return;
}
// Same operation to itemController
// Generate Item Controller JavaType
JavaType itemController = new JavaType(String.format("%s.%sItem%sController", controllerPackage.getFullyQualifiedPackageName(), entityPluralCapitalized, responseType.getControllerNameModifier()), controllerPackage.getModule());
ClassOrInterfaceTypeDetails itemControllerDetails = getTypeLocationService().getTypeDetails(itemController);
if (itemControllerDetails == null) {
List<AnnotationMetadataBuilder> annotations = new ArrayList<AnnotationMetadataBuilder>();
annotations = new ArrayList<AnnotationMetadataBuilder>();
annotations.add(getRooControllerAnnotation(entity, pathPrefix, ControllerType.ITEM));
// Add responseType annotation. Don't use responseTypeService
// annotate to
// prevent multiple
// updates of the .java file. Annotate operation will be used during
// controller update.
annotations.add(new AnnotationMetadataBuilder(responseType.getAnnotation()));
final LogicalPath controllerPathItem = getPathResolver().getPath(itemController.getModule(), Path.SRC_MAIN_JAVA);
final String resourceIdentifierItem = getTypeLocationService().getPhysicalTypeCanonicalPath(itemController, controllerPathItem);
final String declaredByMetadataIdItem = PhysicalTypeIdentifier.createIdentifier(itemController, getPathResolver().getPath(resourceIdentifierItem));
ClassOrInterfaceTypeDetailsBuilder cidBuilder = new ClassOrInterfaceTypeDetailsBuilder(declaredByMetadataIdItem, Modifier.PUBLIC, itemController, PhysicalTypeCategory.CLASS);
cidBuilder.setAnnotations(annotations);
getTypeManagementService().createOrUpdateTypeOnDisk(cidBuilder.build());
// Create LinkFactory class
if (responseType.getName().equals("THYMELEAF")) {
createLinkFactoryClass(cidBuilder.getName());
}
} else {
LOGGER.log(Level.INFO, String.format("ERROR: The controller %s already exists.", collectionController.getFullyQualifiedTypeName()));
return;
}
// Check if requires Deserializer
if (responseType.requiresJsonDeserializer()) {
createJsonDeserializersIfDontExists(entity, itemController.getModule(), controllerPackage);
}
if (responseType.requiresJsonMixin()) {
createJsonMixinIfDontExists(entity, entityMetadata, itemController.getModule(), controllerPackage);
}
// Check multimodule project
if (getProjectOperations().isMultimoduleProject()) {
getProjectOperations().addModuleDependency(collectionController.getModule(), service.getModule());
getProjectOperations().addModuleDependency(itemController.getModule(), service.getModule());
}
}
use of org.springframework.roo.project.LogicalPath in project spring-roo by spring-projects.
the class JSONMetadataProviderImpl method getGovernorPhysicalTypeIdentifier.
@Override
protected String getGovernorPhysicalTypeIdentifier(final String metadataIdentificationString) {
final JavaType javaType = JSONMetadata.getJavaType(metadataIdentificationString);
final LogicalPath path = JSONMetadata.getPath(metadataIdentificationString);
return PhysicalTypeIdentifier.createIdentifier(javaType, path);
}
Aggregations