@Override public String getBaseUrlControllerForFinder(JavaType controller, String finder) { ClassOrInterfaceTypeDetails cid = getTypeLocationService().getTypeDetails(controller); Validate.notNull(cid, "%s not found", controller.getFullyQualifiedTypeName()); return getBaseUrlControllerForFinder(cid, finder); }
private JavaType getEntityDeserializerFor(JavaType entity) { Set<ClassOrInterfaceTypeDetails> deserializers = getTypeLocationService().findClassesOrInterfaceDetailsWithAnnotation( RooJavaType.ROO_DESERIALIZER); for (ClassOrInterfaceTypeDetails deserializer : deserializers) { AnnotationMetadata annotation = deserializer.getAnnotation(RooJavaType.ROO_DESERIALIZER); AnnotationAttributeValue<JavaType> annotationValue = annotation.getAttribute("entity"); if (entity.equals(annotationValue.getValue())) { return deserializer.getType(); } } return null; }
private boolean isModuleVisible(ShellContext shellContext) { if (typeLocationService.getModuleNames(ModuleFeatureName.APPLICATION).size() > 1) { return true; } return false; }
@Override public void createIntegrationTest(JavaType type, Pom module) { Validate.notNull(type, "Class to produce an integration test class for is required"); ClassOrInterfaceTypeDetails cid = typeLocationService.getTypeDetails(type); Validate.notNull(cid.getAnnotation(RooJavaType.ROO_CONTROLLER), "Type must be a Roo controller."); Validate.notNull(cid.getAnnotation(RooJavaType.ROO_THYMELEAF), "Type must be a Roo Thymeleaf controller."); projectOperations.addProperty("", SPRINGLETS_VERSION_PROPERTY); projectOperations .addDependency(module.getModuleName(), SPRINGLETS_BOOT_STARTER_TEST_DEPENDENCY); new JavaType(managedEntity.getFullyQualifiedTypeName(), managedEntity.getArray(), managedEntity.getDataType(), managedEntity.getArgName(), managedEntity.getParameters(), typeLocationService.getTypeDetails(managedEntity).getType().getModule()); if (projectOperations.isMultimoduleProject()) { String managedEntityModuleName = managedEntity.getModule(); Pom managedEntityModule = projectOperations.getPomFromModuleName(managedEntityModuleName); new ClassOrInterfaceTypeDetailsBuilder(declaredByMetadataId, Modifier.PUBLIC, name, PhysicalTypeCategory.CLASS); cidBuilder.addAnnotation(rooIntegrationTestAnnotation); typeManagementService.createOrUpdateTypeOnDisk(cidBuilder.build());
String usernames) { getPushInOperations().pushIn(klass.getPackage(), klass, methodName, false); new NestedAnnotationAttributeValue(new JavaSymbolName("value"), getRooSecurityAuthorizationsAnnotation(method.getMethodName().getSymbolName(), lstParamTypes, roles, usernames).build()); ClassOrInterfaceTypeDetails serviceDetails = getTypeLocationService().getTypeDetails(klass); ClassOrInterfaceTypeDetailsBuilder cidBuilder = new ClassOrInterfaceTypeDetailsBuilder(serviceDetails); serviceDetails.getAnnotation(RooJavaType.ROO_SECURITY_AUTHORIZATIONS); AnnotationMetadataBuilder annotationAuthorizationsMetadataBuilder; annotationAuthorizations.getAttribute("authorizations"); List<?> values = (List<?>) attributeAuthorizations.getValue(); if (values != null && !values.isEmpty()) { cidBuilder.removeAnnotation(RooJavaType.ROO_SECURITY_AUTHORIZATIONS); cidBuilder.addAnnotation(annotationAuthorizationsMetadataBuilder); getTypeManagementService().createOrUpdateTypeOnDisk(cidBuilder.build()); getProjectOperations().addDependency(klass.getModule(), SPRING_SECURITY_CORE, false);
@Override public MemberDetails getEntityDetails(JavaType entity) { Validate.notNull(entity, "ERROR: Entity should be provided"); if (entitiesDetails.containsKey(entity)) { return entitiesDetails.get(entity); } // We know the file exists, as there's already entity metadata for it final ClassOrInterfaceTypeDetails cid = getTypeLocationService().getTypeDetails(entity); if (cid == null) { return null; } if (cid.getAnnotation(RooJavaType.ROO_JPA_ENTITY) == null) { LOGGER.warning("Unable to find the entity annotation on '" + entity + "'"); return null; } entitiesDetails.put(entity, getMemberDetailsScanner().getMemberDetails(getClass().getName(), cid)); return entitiesDetails.get(entity); }
/** * 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()); }
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 JavaType(String.format("%s.%sDeserializer", controllerPackage.getFullyQualifiedPackageName(), entity.getSimpleTypeName()), module); getTypeLocationService().getPhysicalTypeCanonicalPath(deserializerClass, deserializerPath); final String declaredByMetadataIdItem = cidBuilder.addExtendsTypes(JavaType.wrapperOf(JSON_OBJECT_DESERIALIZER, entity)); cidBuilder.addConstructor(constructor); getTypeManagementService().createOrUpdateTypeOnDisk(cidBuilder.build());
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 Validate.notNull(domainType, "ERROR: Domain type required to generate service"); ClassOrInterfaceTypeDetails entityDetails = typeLocationService.getTypeDetails(domainType); Validate.notNull(entityDetails.getAnnotation(RooJavaType.ROO_JPA_ENTITY), "ERROR: Provided entity should be annotated with @RooJpaEntity"); interfaceAnnotationMetadata.addAttribute(new ClassAttributeValue(new JavaSymbolName("entity"), domainType)); JavaType.wrapperOf(SpringletsJavaType.SPRINGLETS_ENTITY_RESOLVER, domainType, idType); interfaceTypeBuilder.addExtendsTypes(entityResolver); JavaType.wrapperOf(SpringletsJavaType.SPRINGLETS_VALIDATOR_SERVICE, domainType); interfaceTypeBuilder.addExtendsTypes(validatorServiceEntity); typeManagementService.createOrUpdateTypeOnDisk(interfaceTypeBuilder.build()); projectOperations.addModuleDependency(interfaceType.getModule(), domainType.getModule()); projectOperations.addDependency(interfaceType.getModule(), new Dependency("io.springlets", "springlets-data-commons", null));
@Override public List<RelationInfoExtended> getRelationInfoFor(final JavaType entity, final String path) { Validate.notNull(entity, "entity is required"); Validate.notBlank(path, "path is required"); ClassOrInterfaceTypeDetails cid = getTypeLocationService().getTypeDetails(entity); Validate.notNull(cid, "%s not found", entity.getFullyQualifiedTypeName()); JpaEntityMetadata entityMetada = getMetadataService().get(JpaEntityMetadata.createIdentifier(cid)); Validate.notNull(entityMetada, "Can't get Entity metadata information for %s", entity.getFullyQualifiedTypeName()); return getRelationInfoFor(entityMetada, path); }
@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()); }
getTypeLocationService().findClassesOrInterfaceDetailsWithAnnotation( SpringJavaType.SPRING_BOOT_APPLICATION); for (ClassOrInterfaceTypeDetails applicationCid : applicationCids) { getProjectOperations().getPomFromModuleName(applicationCid.getType().getModule()); new JavaType(String.format("%s.config.SpringDataJpaDetachableRepositoryConfiguration", getTypeLocationService().getTopLevelPackageForModule(module)), module.getModuleName()); Validate.notNull(repositoryConfigurationClass.getModule(), "ERROR: Module name is required to generate a valid JavaType"); new ClassOrInterfaceTypeDetailsBuilder(mid, PUBLIC, repositoryConfigurationClass, PhysicalTypeCategory.CLASS); typeBuilder.addAnnotation(repositoryCondigurationAnnotation); getTypeManagementService().createOrUpdateTypeOnDisk(typeBuilder.build());
@Override public void addService(final JavaType domainType, JavaType repositoryType, JavaType interfaceType, JavaType implType) { Validate.notNull(domainType, "ERROR: Domain type required to be able to generate service."); if (projectOperations.isMultimoduleProject()) { Validate .notNull(repositoryType, "ERROR: You must specify a repository type to be able to generate service on multimodule projects."); Validate .notNull(interfaceType, "ERROR: You must specify a interface type to be able to generate service on multimodule projects."); .format( "ERROR: You must generate a repository to '%s' entity before to generate a new service.", domainType.getFullyQualifiedTypeName())); return; repositoryType = repository.getName(); } else { repository = typeLocationService.getTypeDetails(repositoryType); new JavaType(String.format("%s.service.api.%s%s", projectOperations.getFocusedTopLevelPackage(), domainType.getSimpleTypeName(), implType == null ? "Service" : implType.getSimpleTypeName().concat("Api")), ""); implType = new JavaType(String.format("%s.service.impl.%sServiceImpl", projectOperations.getFocusedTopLevelPackage(), domainType.getSimpleTypeName()), interfaceType.getModule());
.addDependency(module.getModuleName(), DEPENDENCY_SPRINGLETS_STARTER_MAIL); getProjectOperations().addProperty("", PROPERTY_SPRINGLETS_VERSION); if (!service.getModule().equals(StringUtils.EMPTY)) { getProjectOperations().addDependency(service.getModule(), DEPENDENCY_SPRINGLETS_MAIL); getTypeLocationService().getTypeDetails(service); Validate.isTrue(serviceTypeDetails != null, "Cannot locate source for '%s'", service.getFullyQualifiedTypeName()); final String declaredByMetadataId = serviceTypeDetails.getDeclaredByMetadataId(); final ClassOrInterfaceTypeDetailsBuilder cidBuilder = new ClassOrInterfaceTypeDetailsBuilder(serviceTypeDetails); cidBuilder.addField(new FieldMetadataBuilder(declaredByMetadataId, PRIVATE, Arrays .asList(new AnnotationMetadataBuilder(AUTOWIRED)), new JavaSymbolName("mailReceiver"), SpringletsJavaType.SPRINGLETS_MAIL_RECEIVER_SERVICE)); getTypeManagementService().createOrUpdateTypeOnDisk(cidBuilder.build());
/** * Creates the Factory class of the child entity of relationship, only if parent entity has JPA unit tests. * * @param childType * @param parentType */ private void createChildEntityFactory(JavaType childType, JavaType parentType) { // Find current JPA unit tests Set<JavaType> unitTestTypes = typeLocationService.findTypesWithAnnotation(RooJavaType.ROO_JPA_UNIT_TEST); for (JavaType unitTestType : unitTestTypes) { // Get the annotation @RooJpaUnitTest ClassOrInterfaceTypeDetails cid = typeLocationService.getTypeDetails(unitTestType); AnnotationMetadata rooUnitTestAnnotation = cid.getAnnotation(RooJavaType.ROO_JPA_UNIT_TEST); // Check if parent entity has JPA unit test class AnnotationAttributeValue<Object> targetClass = rooUnitTestAnnotation.getAttribute("targetClass"); Validate.notNull(targetClass, String.format( "'targetClass' attribute can't be found for annotation @RooJpaUnitTest in class %s", unitTestType.getSimpleTypeName())); if (parentType.equals(targetClass.getValue())) { if (jpaEntityFactoryLocator.getFirstJpaEntityFactoryForEntity(childType) == null) { // Create factory class for child entity if doesn't exist dataOnDemandCreatorProvider.createEntityFactory(childType); } break; } } }
@Override public void createConstructor(final JavaType name, final Set<String> fields) { final ClassOrInterfaceTypeDetails javaTypeDetails = typeLocationService.getTypeDetails(name); Validate.notNull(javaTypeDetails, "The type specified, '%s', doesn't exist", name.getFullyQualifiedTypeName()); pathResolver.getFocusedPath(Path.SRC_MAIN_JAVA)); final List<FieldMetadata> constructorFields = new ArrayList<FieldMetadata>(); final List<? extends FieldMetadata> declaredFields = javaTypeDetails.getDeclaredFields(); if (fields != null) { for (final String field : fields) { declared: for (final FieldMetadata declaredField : declaredFields) { if (field.equals(declaredField.getFieldName().getSymbolName())) { constructorFields.add(declaredField); break declared; final ConstructorMetadata result = javaTypeDetails.getDeclaredConstructor(parameterTypes); if (result != null) { bodyBuilder.appendFormalLine("super();"); for (final FieldMetadata field : constructorFields) { final String fieldName = field.getFieldName().getSymbolName(); bodyBuilder.appendFormalLine("this." + fieldName + " = " + fieldName + ";"); parameterNames.add(field.getFieldName()); new ClassOrInterfaceTypeDetailsBuilder(javaTypeDetails); cidBuilder.addConstructor(constructorBuilder); typeManagementService.createOrUpdateTypeOnDisk(cidBuilder.build());
private boolean isExceptionAnnotatedWithResponseStatus(JavaType exception) { ClassOrInterfaceTypeDetails exceptionCid = typeLocationService.getTypeDetails(exception); Validate.notNull(exceptionCid, String.format("Can't found class: %s", exception.getFullyQualifiedTypeName())); AnnotationMetadata annotation = exceptionCid.getAnnotation(SpringJavaType.RESPONSE_STATUS); if (annotation == null) { return false; } return true; }
@Override protected ItdTypeDetailsProvidingMetadataItem getMetadata( final String metadataIdentificationString, final JavaType aspectName, final PhysicalTypeMetadata governorPhysicalTypeMetadata, final String itdFilename) { // Getting annotated class details ClassOrInterfaceTypeDetails endpoint = governorPhysicalTypeMetadata.getMemberHoldingTypeDetails(); AnnotationMetadata seiImplAnnotation = endpoint.getAnnotation(ROO_SEI_IMPL); AnnotationAttributeValue<?> seiAttr = seiImplAnnotation.getAttribute(new JavaSymbolName("sei")); Validate.notNull(seiAttr, "ERROR: You must provide a valid SEI to be able to generate a Endpoint."); // Getting SEI from annotation JavaType seiType = (JavaType) seiAttr.getValue(); // Getting SEI details ClassOrInterfaceTypeDetails seiTypeDetails = getTypeLocationService().getTypeDetails(seiType); // Getting SEI Metadata final String seiMetadataId = SeiMetadata.createIdentifier(seiTypeDetails.getType(), PhysicalTypeIdentifier.getPath(seiTypeDetails.getDeclaredByMetadataId())); final SeiMetadata seiMetadata = (SeiMetadata) getMetadataService().get(seiMetadataId); // Getting SEI methods from service and save it Map<MethodMetadata, MethodMetadata> seiMethods = seiMetadata.getSeiMethods(); // Registering dependency between SeiMetadata and this one, to be able to // update Endpoint if SEI changes final String seiMetadataKey = SeiMetadata.createIdentifier(seiTypeDetails); registerDependency(seiMetadataKey, metadataIdentificationString); return new SeiImplMetadata(metadataIdentificationString, aspectName, governorPhysicalTypeMetadata, getProjectOperations().getTopLevelPackage(""), endpoint, seiType, seiMetadata.getService(), seiMethods); }
/** * Returns the {@link ClassOrInterfaceTypeDetails} for the provided entity. * * @param entity * the entity to lookup required * @return the ClassOrInterfaceTypeDetails type details (never null; throws * an exception if it cannot be obtained or parsed) */ private ClassOrInterfaceTypeDetails getEntityDetails(final JavaType entity) { final ClassOrInterfaceTypeDetails cid = typeLocationService.getTypeDetails(entity); Validate.notNull(cid, "Java source code details unavailable for type '%s'", entity); return cid; }
@Override public void focus(final JavaType type) { Validate.notNull(type, "Specify the type to focus on"); final String physicalTypeIdentifier = typeLocationService.getPhysicalTypeIdentifier(type); Validate.notNull(physicalTypeIdentifier, "Cannot locate the type %s", type.getFullyQualifiedTypeName()); final PhysicalTypeMetadata ptm = (PhysicalTypeMetadata) metadataService.get(physicalTypeIdentifier); Validate.notNull(ptm, "Class %s does not exist", PhysicalTypeIdentifier.getFriendlyName(physicalTypeIdentifier)); }