ClassOrInterfaceTypeDetails cid = typeLocationService.getTypeDetails(type); Validate.notNull(cid.getAnnotation(RooJavaType.ROO_REPOSITORY_JPA), "Type must be a Roo JPA Repository type."); new JavaType(managedEntity.getFullyQualifiedTypeName(), managedEntity.getArray(), managedEntity.getDataType(), managedEntity.getArgName(), managedEntity.getParameters(), typeLocationService.getTypeDetails(managedEntity).getType().getModule()); 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) { new AnnotationMetadataBuilder(RooJavaType.ROO_REPOSITORY_JPA_INTEGRATION_TEST); rooIntegrationTestAnnotation.addClassAttribute("targetClass", type); rooIntegrationTestAnnotation.addClassAttribute("dodConfigurationClass", creator.getDataOnDemandConfiguration()); rooIntegrationTestAnnotation.addClassAttribute("dodClass", new ClassOrInterfaceTypeDetailsBuilder(declaredByMetadataId, Modifier.PUBLIC, name, PhysicalTypeCategory.CLASS); cidBuilder.addAnnotation(rooIntegrationTestAnnotation); typeManagementService.createOrUpdateTypeOnDisk(cidBuilder.build());
Validate.isTrue(!JdkJavaType.isPartOfJavaLang(name.getSimpleTypeName()), "Entity name '%s' must not be part of java.lang", name.getSimpleTypeName()); getProjectOperations().setModule(getProjectOperations().getPomFromModuleName(name.getModule())); PhysicalTypeIdentifier.createIdentifier(name, getPathResolver().getFocusedPath(Path.SRC_MAIN_JAVA)); final ClassOrInterfaceTypeDetailsBuilder cidBuilder = new ClassOrInterfaceTypeDetailsBuilder(declaredByMetadataId, modifier, name, PhysicalTypeCategory.CLASS); final Set<JavaType> implementsTypes = new LinkedHashSet<JavaType>(); final ClassOrInterfaceTypeDetails typeDetails = getTypeLocationService().getTypeDetails(declaredByMetadataId); if (typeDetails != null) { implementsTypes.addAll(typeDetails.getImplementsTypes()); ClassOrInterfaceTypeDetails entityDetails = cidBuilder.build(); getTypeManagementService().createOrUpdateTypeOnDisk(entityDetails); if (superclass.equals(OBJECT)) { getTypeManagementService().addField( getIdentifierField(name, identifierField, identifierType, identifierColumn, sequenceName, identifierStrategy, inheritanceType), true); getTypeManagementService().addField( getVersionField(name, versionField, versionType, versionColumn), true);
@Override public void enumConstant(final JavaType name, final JavaSymbolName fieldName, final boolean permitReservedWords) { if (!permitReservedWords) { // No need to check the "name" as if the class exists it is assumed // it is a legal name ReservedWords.verifyReservedWordsNotPresent(fieldName); } final String declaredByMetadataId = PhysicalTypeIdentifier.createIdentifier(name, pathResolver.getFocusedPath(Path.SRC_MAIN_JAVA)); typeManagementService.addEnumConstant(declaredByMetadataId, fieldName); }
@Override public void createUnitTest(final JavaType entity) { Validate.notNull(entity, "Class to produce an unit test class for is required"); // Check if provided JavaType is a Repository ClassOrInterfaceTypeDetails cid = typeLocationService.getTypeDetails(entity); Validate.notNull(cid.getAnnotation(RooJavaType.ROO_JPA_ENTITY), "Type must be a Roo JPA Entity type."); // Create JPA DataOnDemand artifacts List<DataOnDemandCreatorProvider> dodCreators = getValidDataOnDemandCreatorsForType(entity); for (DataOnDemandCreatorProvider dodCreator : dodCreators) { dodCreator.createDataOnDemand(entity); } final JavaType name = new JavaType(entity + "Test", entity.getModule()); final String declaredByMetadataId = PhysicalTypeIdentifier.createIdentifier(name, Path.SRC_TEST_JAVA.getModulePathId(entity.getModule())); if (metadataService.get(declaredByMetadataId) != null) { // The file already exists return; } // Add @RooUnitTest to source file AnnotationMetadataBuilder rooUnitTestAnnotation = new AnnotationMetadataBuilder(RooJavaType.ROO_JPA_UNIT_TEST); rooUnitTestAnnotation.addClassAttribute("targetClass", entity); final ClassOrInterfaceTypeDetailsBuilder cidBuilder = new ClassOrInterfaceTypeDetailsBuilder(declaredByMetadataId, Modifier.PUBLIC, name, PhysicalTypeCategory.CLASS); cidBuilder.addAnnotation(rooUnitTestAnnotation); typeManagementService.createOrUpdateTypeOnDisk(cidBuilder.build()); }
String module, JavaPackage controllerPackage) { Set<ClassOrInterfaceTypeDetails> allJsonMixin = getTypeLocationService().findClassesOrInterfaceDetailsWithAnnotation( RooJavaType.ROO_JSON_MIXIN); values = new JSONMixinAnnotationValues(mixin); if (entity.equals(values.getEntity())) { new AnnotationMetadataBuilder(RooJavaType.ROO_JSON_MIXIN); mixinAnnotation.addClassAttribute(ENTITY_KEY, entity); annotations.add(mixinAnnotation); new JavaType(String.format("%s.%sJsonMixin", controllerPackage.getFullyQualifiedPackageName(), entity.getSimpleTypeName()), module); getTypeLocationService().getPhysicalTypeCanonicalPath(mixinClass, mixinPath); final String declaredByMetadataIdItem = PhysicalTypeIdentifier.createIdentifier(mixinClass, getPathResolver().getPath(resourceIdentifierItem)); ClassOrInterfaceTypeDetailsBuilder cidBuilder = new ClassOrInterfaceTypeDetailsBuilder(declaredByMetadataIdItem, Modifier.PUBLIC + Modifier.ABSTRACT, mixinClass, PhysicalTypeCategory.CLASS); cidBuilder.setAnnotations(annotations); getTypeManagementService().createOrUpdateTypeOnDisk(cidBuilder.build());
ClassOrInterfaceTypeDetails classDetails = getTypeLocationService().getTypeDetails(klass); Validate .notNull(klass, "ERROR: You must specify a valid class to continue with push-in action"); classDetails.getAnnotation(RooJavaType.ROO_JPA_UNIT_TEST) == null ? Path.SRC_MAIN_JAVA : Path.SRC_TEST_JAVA; PhysicalTypeIdentifier.createIdentifier(klass, getPathResolver().getPath(klass.getModule(), path)); new ClassOrInterfaceTypeDetailsBuilder(classDetails); if (!memberHoldingTypeDetails.getType().equals(classDetails.getType())) { continue; .getFullyQualifiedTypeName()) && !method.getDeclaredByMetadataId().equals(declaredByMetadataId)) { detailsBuilder.addMethod(newMethod); detailsBuilder.addField(newField); classDetails = getTypeLocationService().getTypeDetails(detailsBuilder.build().getType()); for (AnnotationMetadata annotation : allDeclaredAnnotations) { getTypeManagementService().createOrUpdateTypeOnDisk(detailsBuilder.build());
getTypeLocationService().getTypeDetails(service); Validate.notNull(serviceTypeDetails, "ERROR: Provide an existing service"); serviceTypeDetails.getAnnotation(RooJavaType.ROO_SERVICE); Validate .notNull(serviceAnnotation, "ERROR: Provide a valid service annotated with @RooService"); new JavaType(String.format("%sEndpoint", sei.getFullyQualifiedTypeName()), sei.getModule()); getTypeLocationService().getTypeDetails(configClass); if (configClassDetails == null) { isNewConfigClass = true; new AnnotationMetadataBuilder(new JavaType(RooSei.class)); seiAnnotation.addClassAttribute("service", service); cidBuilderSEI.addAnnotation(seiAnnotation); getTypeManagementService().createOrUpdateTypeOnDisk(cidBuilderSEI.build()); new AnnotationMetadataBuilder(new JavaType(RooSeiImpl.class)); getTypeManagementService().createOrUpdateTypeOnDisk(cidBuilderEndpoint.build()); getTypeManagementService().createOrUpdateTypeOnDisk(cidBuilderConfig.build());
String pathPrefixController, String viewsList) { JavaType detailController = new JavaType(String.format("%s.%s", controllerPackage.getFullyQualifiedPackageName(), controllerName), controllerPackage.getModule()); getTypeLocationService().getTypeDetails(detailController); if (detailControllerDetails != null) { if (LOGGER.isLoggable(Level.INFO)) { LOGGER.log(Level.INFO, String.format( "ERROR: Class '%s' already exists inside your generated project.", detailController.getFullyQualifiedTypeName())); annotations.add(new AnnotationMetadataBuilder(responseType.getAnnotation())); getPathResolver().getPath(detailController.getModule(), Path.SRC_MAIN_JAVA); final String resourceIdentifierItem = getTypeLocationService().getPhysicalTypeCanonicalPath(detailController, detailControllerPathItem); final String declaredByMetadataId = PhysicalTypeIdentifier.createIdentifier(detailController, getPathResolver().getPath(resourceIdentifierItem)); ClassOrInterfaceTypeDetailsBuilder cidBuilder = new ClassOrInterfaceTypeDetailsBuilder(declaredByMetadataId, Modifier.PUBLIC, detailController, PhysicalTypeCategory.CLASS); cidBuilder.setAnnotations(annotations); getTypeManagementService().createOrUpdateTypeOnDisk(cidBuilder.build());
getTypeLocationService().findClassesOrInterfaceDetailsWithAnnotation( RooJavaType.ROO_DESERIALIZER); for (JavaType entity : entitiesToCreateSerializers) { values = new EntityDeserializerAnnotationValues(deserializer); if (entity.equals(values.getEntity())) { Validate.notNull(serviceDetails, "Can't found service for Entity %s to generate " + "Serializer. If it is a related entity with the one to generate " + "controller, it needs a service.", entity.getFullyQualifiedTypeName()); new AnnotationMetadataBuilder(RooJavaType.ROO_DESERIALIZER); deserializerAnnotation.addClassAttribute(ENTITY_KEY, entity); annotations.add(deserializerAnnotation); new JavaType(String.format("%s.%sDeserializer", controllerPackage.getFullyQualifiedPackageName(), entity.getSimpleTypeName()), module); cidBuilder.addExtendsTypes(JavaType.wrapperOf(JSON_OBJECT_DESERIALIZER, entity)); cidBuilder.addConstructor(constructor); getTypeManagementService().createOrUpdateTypeOnDisk(cidBuilder.build());
Validate.notNull(finderName, "ERROR: Finder name required to generate finder."); final String id = getTypeLocationService().getPhysicalTypeIdentifier(entity); if (id == null) { LOGGER.warning("Cannot locate source for '" + entity.getFullyQualifiedTypeName() + "'"); return; ClassOrInterfaceTypeDetails entityDetails = getTypeLocationService().getTypeDetails(entity); AnnotationMetadata entityAnnotation = entityDetails.getAnnotation(RooJavaType.ROO_JPA_ENTITY); repository.getAnnotation(RooJavaType.ROO_REPOSITORY_JPA); AnnotationMetadataBuilder repositoryAnnotationBuilder = new AnnotationMetadataBuilder(repositoryAnnotation); new AnnotationMetadataBuilder(RooJavaType.ROO_FINDER); singleFinderAnnotation.addStringAttribute("value", finderName.getSymbolName()); if (returnType.getModule() != null) { getProjectOperations().addModuleDependency(repository.getName().getModule(), returnType.getModule()); new ClassOrInterfaceTypeDetailsBuilder(repository); cidBuilder.updateTypeAnnotation(repositoryAnnotationBuilder); getTypeManagementService().createOrUpdateTypeOnDisk(cidBuilder.build());
Validate.isTrue(cid.getPhysicalTypeCategory() == PhysicalTypeCategory.CLASS, "Type %s is not a class", currentEntity.getFullyQualifiedTypeName()); Validate.isTrue(!Modifier.isAbstract(cid.getModifier()), "Type %s is abstract", currentEntity.getFullyQualifiedTypeName()); final AnnotationMetadata entityAnnotation = memberDetails.getAnnotation(ENTITY); Validate.isTrue(entityAnnotation != null, "Type %s must be a JPA entity type", currentEntity.getFullyQualifiedTypeName()); PhysicalTypeIdentifier.createIdentifier(factoryClass, path); if (metadataService.get(declaredByMetadataId) != null) { new ClassOrInterfaceTypeDetailsBuilder(declaredByMetadataId, Modifier.PUBLIC, factoryClass, PhysicalTypeCategory.CLASS); new AnnotationMetadataBuilder(RooJavaType.ROO_JPA_ENTITY_FACTORY); entityFactoryAnnotation.addClassAttribute("entity", entity); cidBuilder.addAnnotation(entityFactoryAnnotation); typeManagementService.createOrUpdateTypeOnDisk(cidBuilder.build());
Validate.notNull(interfaceType, "ERROR: Interface should be provided to be able to generate its implementation"); Validate.notNull(interfaceType.getModule(), "ERROR: Interface module is required"); Validate.notNull(domainType, "ERROR: Domain type required to generate service"); new JavaType(String.format("%sImpl", interfaceType.getFullyQualifiedTypeName()), interfaceType.getModule()); new AnnotationMetadataBuilder(ROO_SERVICE_IMPL); implAnnotationMetadata.addAttribute(new ClassAttributeValue(new JavaSymbolName("service"), interfaceType)); implTypeBuilder.addAnnotation(implAnnotationMetadata.build()); implTypeBuilder.addImplementsType(interfaceType); PhysicalTypeIdentifier.createIdentifier(implTypeBuilder.build().getType(), pathResolver.getPath(implType.getModule(), Path.SRC_MAIN_JAVA)); typeManagementService.createOrUpdateTypeOnDisk(implTypeBuilder.build()); projectOperations.addModuleDependency(implType.getModule(), interfaceType.getModule()); projectOperations.addModuleDependency(implType.getModule(), repository.getName().getModule()); projectOperations.addModuleDependency(implType.getModule(), domainType.getModule());
Validate.notNull(interfaceType.getModule(), "JavaType %s does not have a module", domainType); pathResolver.getCanonicalPath(interfaceType.getModule(), Path.SRC_MAIN_JAVA, interfaceType); if (fileManager.exists(interfaceIdentifier)) { return; // Type already exists - nothing to do ClassOrInterfaceTypeDetails entityDetails = typeLocationService.getTypeDetails(domainType); Validate.notNull(entityDetails.getAnnotation(RooJavaType.ROO_JPA_ENTITY), "ERROR: Provided entity should be annotated with @RooJpaEntity"); new AnnotationMetadataBuilder(ROO_SERVICE); interfaceAnnotationMetadata.addAttribute(new ClassAttributeValue(new JavaSymbolName("entity"), domainType)); for (FieldMetadata field : entityDetails.getDeclaredFields()) { if (field.getAnnotation(JpaJavaType.ID) != null) { idType = field.getFieldType(); JavaType.wrapperOf(SpringletsJavaType.SPRINGLETS_ENTITY_RESOLVER, domainType, idType); interfaceTypeBuilder.addExtendsTypes(entityResolver); JavaType.wrapperOf(SpringletsJavaType.SPRINGLETS_VALIDATOR_SERVICE, domainType); interfaceTypeBuilder.addExtendsTypes(validatorServiceEntity); interfaceTypeBuilder.addAnnotation(interfaceAnnotationMetadata.build()); typeManagementService.createOrUpdateTypeOnDisk(interfaceTypeBuilder.build());
Validate .notNull( typeLocationService.getTypeDetails(entity).getAnnotation(RooJavaType.ROO_JPA_ENTITY), "The provided JavaType %s must be annotated with @RooJpaEntity", entity.getSimpleTypeName()); LOGGER.log(Level.INFO, String.format( "ERROR: Provided finder '%s' doesn't exists on the repository '%s' " + "related to entity '%s'", finder, relatedRepositoryDetails.getType() .getSimpleTypeName(), entity.getSimpleTypeName())); return; return; relatedService = service.getType(); controllerBuilder = new ClassOrInterfaceTypeDetailsBuilder(controllerToUpdateOrCreate); .addAnnotation(new AnnotationMetadataBuilder(responseType.getAnnotation())); controllerBuilder.build()); typeManagementService.createOrUpdateTypeOnDisk(controllerBuilder.build());
String name = controller.getSimpleTypeName().concat("LinkFactory"); if (name.contains("Controller")) { name = name.replace("Controller", ""); new JavaType(controller.getPackage().getFullyQualifiedPackageName().concat(".") .concat(name), controller.getModule()); linkFactoryJavaType); final String mid = PhysicalTypeIdentifier.createIdentifier(linkFactoryJavaType, getPathResolver().getPath(linkFactoryPathIdentifier)); new ClassOrInterfaceTypeDetailsBuilder(mid, PUBLIC, linkFactoryJavaType, PhysicalTypeCategory.CLASS); new AnnotationMetadataBuilder(RooJavaType.ROO_LINK_FACTORY); annotationBuilder.addAttribute(new ClassAttributeValue(new JavaSymbolName("controller"), controller)); typeBuilder.addAnnotation(annotationBuilder); getTypeManagementService().createOrUpdateTypeOnDisk(typeBuilder.build());
/** * 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()); }
ClassOrInterfaceTypeDetails classDetails = getTypeLocationService().getTypeDetails(klass); Validate .notNull(klass, "ERROR: You must specify a valid class to continue with push-in action"); classDetails.getAnnotation(RooJavaType.ROO_JPA_UNIT_TEST) == null ? Path.SRC_MAIN_JAVA : Path.SRC_TEST_JAVA; PhysicalTypeIdentifier.createIdentifier(klass, getPathResolver().getPath(klass.getModule(), path)); new ClassOrInterfaceTypeDetailsBuilder(classDetails); classDetails.getAnnotation(RooJavaType.ROO_REPOSITORY_JPA_CUSTOM_IMPL); JavaType relatedRepositoryCustom = null; if (rooRepositoryCustomImplAnnotation != null) { detailsBuilder.addImplementsType(relatedRepositoryCustom); pushedElements.add(relatedRepositoryCustom); if (!memberHoldingTypeDetails.getType().equals(classDetails.getType())) { continue; detailsBuilder.addMethod(newMethod); getTypeManagementService().createOrUpdateTypeOnDisk(detailsBuilder.build());
new JavaType(String.format("%s.web.MainController", getProjectOperations() .getTopLevelPackage(module.getModuleName())), module.getModuleName()); getTypeLocationService().getTypeDetails(mainController); mainControllerDetails.getAnnotation(getMainControllerAnnotation()); getPathResolver().getPath(mainController.getModule(), Path.SRC_MAIN_JAVA); final String resourceIdentifier = getTypeLocationService().getPhysicalTypeCanonicalPath(mainController, controllerPath); final String declaredByMetadataId = PhysicalTypeIdentifier.createIdentifier(mainController, getPathResolver().getPath(resourceIdentifier)); annotations.add(new AnnotationMetadataBuilder(getMainControllerAnnotation())); new ClassOrInterfaceTypeDetailsBuilder(declaredByMetadataId, Modifier.PUBLIC, mainController, PhysicalTypeCategory.CLASS); cidBuilder.setAnnotations(annotations); getTypeManagementService().createOrUpdateTypeOnDisk(cidBuilder.build());
getPushInOperations().pushIn(klass.getPackage(), klass, methodName, false); new NestedAnnotationAttributeValue(new JavaSymbolName("value"), getRooSecurityAuthorizationsAnnotation(method.getMethodName().getSymbolName(), lstParamTypes, roles, usernames).build()); rooSecurityAuthorizationsToAdd.add(newFilter); ClassOrInterfaceTypeDetails serviceDetails = getTypeLocationService().getTypeDetails(klass); ClassOrInterfaceTypeDetailsBuilder cidBuilder = new ClassOrInterfaceTypeDetailsBuilder(serviceDetails); serviceDetails.getAnnotation(RooJavaType.ROO_SECURITY_AUTHORIZATIONS); AnnotationMetadataBuilder annotationAuthorizationsMetadataBuilder; new AnnotationMetadataBuilder(annotationAuthorizations); cidBuilder.removeAnnotation(RooJavaType.ROO_SECURITY_AUTHORIZATIONS); new AnnotationMetadataBuilder(RooJavaType.ROO_SECURITY_AUTHORIZATIONS); cidBuilder.addAnnotation(annotationAuthorizationsMetadataBuilder); getTypeManagementService().createOrUpdateTypeOnDisk(cidBuilder.build()); getProjectOperations().addDependency(klass.getModule(), SPRING_SECURITY_CORE, false);
getPathResolver().getCanonicalPath(controllerAdviceClass.getModule(), Path.SRC_MAIN_JAVA, controllerAdviceClass); PhysicalTypeIdentifier.createIdentifier(controllerAdviceClass, getPathResolver().getPath(controllerAdviceClassIdentifier)); final ClassOrInterfaceTypeDetailsBuilder typeBuilder = new ClassOrInterfaceTypeDetailsBuilder(mid, PUBLIC, controllerAdviceClass, PhysicalTypeCategory.CLASS); typeBuilder.addAnnotation(new AnnotationMetadataBuilder(SpringJavaType.CONTROLLER_ADVICE) .build()); getTypeManagementService().createOrUpdateTypeOnDisk(typeBuilder.build()); } else { typeLocationService.getTypeDetails(controllerAdviceClass); AnnotationMetadata annotation = typeDetails.getAnnotation(SpringJavaType.CONTROLLER_ADVICE); if (annotation == null) { LOGGER.warning("Class must be annotated with @ControllerAdvice");