private JavaType filterControllerByPackageAndPrefix( Collection<ClassOrInterfaceTypeDetails> itemControllers, JavaPackage controllerPackage, String pathPrefix) { for (ClassOrInterfaceTypeDetails controller : itemControllers) { ControllerAnnotationValues values = new ControllerAnnotationValues(controller); if (controllerPackage.equals(controller.getType().getPackage()) && (StringUtils.isBlank(pathPrefix) && StringUtils.isBlank(values.getPathPrefix()) || StringUtils .equals(pathPrefix, values.getPathPrefix()))) { return controller.getType(); } } return null; }
@Override public String getBasePathForController(ClassOrInterfaceTypeDetails controller) { Validate.notNull(controller, "controller is required"); Validate.notNull(controller.getAnnotation(RooJavaType.ROO_CONTROLLER), "%s must be annotated with @%s", controller.getType(), RooJavaType.ROO_CONTROLLER.getSimpleTypeName()); ControllerAnnotationValues values = new ControllerAnnotationValues(controller); StringBuilder sbuilder = getBasePathStringBuilder(controller, values); // Before continue, check if the controller has a custom @RequestMapping annotation AnnotationMetadata requestMappingAnnotation = controller.getAnnotation(SpringJavaType.REQUEST_MAPPING); if (requestMappingAnnotation != null) { String customPath = ""; if (requestMappingAnnotation.getAttribute("value") != null) { String path = (String) requestMappingAnnotation.getAttribute("value").getValue(); // Only the base path should be returned customPath = path.split("\\{")[0]; if (customPath.endsWith("/")) { customPath = customPath.substring(0, customPath.length() - 1); } } // If some path has been specified and is different of the calculated one, return this one if (StringUtils.isNotEmpty(customPath) && !customPath.equals(sbuilder.toString())) { return customPath; } } return sbuilder.toString(); }
private String getSuffix(final List<MemberHoldingTypeDetails> memberHoldingTypeDetailsList, final boolean singular, final Map<String, String> pluralMap) { final ClassOrInterfaceTypeDetails cid = getMostConcreteClassOrInterfaceTypeDetails(memberHoldingTypeDetailsList); if (singular) { return cid.getName().getSimpleTypeName(); } String plural = pluralMap.get(cid.getDeclaredByMetadataId()); for (final AnnotationMetadata annotationMetadata : cid.getAnnotations()) { if (annotationMetadata.getAnnotationType().getFullyQualifiedTypeName() .equals(ROO_PLURAL.getFullyQualifiedTypeName())) { final AnnotationAttributeValue<?> annotationAttributeValue = annotationMetadata.getAttribute(new JavaSymbolName("value")); if (annotationAttributeValue != null) { plural = annotationAttributeValue.getValue().toString(); } break; } } if (StringUtils.isNotBlank(plural)) { plural = StringUtils.capitalize(plural); } return plural; }
private void init(final ClassOrInterfaceTypeDetails existing) { name = existing.getName(); physicalTypeCategory = existing.getPhysicalTypeCategory(); if (existing.getSuperclass() != null) { superclass = new ClassOrInterfaceTypeDetailsBuilder(existing.getSuperclass()); } enumConstants.addAll(existing.getEnumConstants()); registeredImports.clear(); registeredImports.addAll(existing.getRegisteredImports()); }
public void cacheType(final String typeFilePath, final ClassOrInterfaceTypeDetails cid) { Validate.notBlank(typeFilePath, "Module name required"); Validate.notNull(cid, "Type details required"); midToTypeDetailsMap.put(cid.getDeclaredByMetadataId(), cid); typeFilePathToMidMap.put(typeFilePath, cid.getDeclaredByMetadataId()); typeIdentifierToFilePathMap.put(cid.getDeclaredByMetadataId(), typeFilePath); types.add(cid.getName()); final String fullyQualifiedTypeName = cid.getName().getFullyQualifiedTypeName(); final String simpleTypeName = cid.getName().getSimpleTypeName(); typeNameToMidMap.put(fullyQualifiedTypeName, cid.getDeclaredByMetadataId()); if (!simpleTypeNameTypesMap.containsKey(simpleTypeName)) { simpleTypeNameTypesMap.put(simpleTypeName, new HashSet<String>()); } simpleTypeNameTypesMap.get(simpleTypeName).add(fullyQualifiedTypeName); }
@Override protected void onAddImplementType(final JavaType type) { Validate .isTrue( !governor.getImplementsTypes().contains(type), "Type '%s' already declared in implements types list in target type '%s' (ITD target '%s')", type, governor.getName().getFullyQualifiedTypeName(), aspect.getFullyQualifiedTypeName()); Validate.isTrue(!getImplementsTypes().contains(type), "Type '%s' already declared in implements types list in ITD (ITD target '%s')", type, aspect.getFullyQualifiedTypeName()); }
if (StringUtils.isEmpty(module.getModuleName())) { moduleStr = ""; 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); .asList(new AnnotationMetadataBuilder(AUTOWIRED)), new JavaSymbolName("mailReceiver"), SpringletsJavaType.SPRINGLETS_MAIL_RECEIVER_SERVICE));
String javaTypeFullyQualilfiedName = cid.getType().getFullyQualifiedTypeName(); String javaTypeString = ""; String topLevelPackageString = ""; if (StringUtils.isNotBlank(cid.getType().getModule())) { javaTypeString = cid.getType().getModule().concat(LogicalPath.MODULE_PATH_SEPARATOR); topLevelPackageString = projectOperations.getTopLevelPackage(cid.getType().getModule()) .getFullyQualifiedPackageName(); } else { return javaTypeString.concat(StringUtils.replace(javaTypeFullyQualilfiedName, topLevelPackageString, "~"));
/** * Obtains the "toString" method for this type, if available. * <p> * If the user provided a non-default name for "toString", that method will * be returned. * * @return the "toString" method declared on this type or that will be * introduced (or null if undeclared and not introduced) */ private MethodMetadataBuilder getToStringMethod() { if (StringUtils.isBlank(annotationValues.getToStringMethod())) { return null; } // Compute the relevant toString method name final JavaSymbolName methodName = new JavaSymbolName(annotationValues.getToStringMethod()); // See if the type itself declared the method if (governorHasMethod(methodName)) { return null; } return generateToStringMethod(getId(), governorTypeDetails.getType(), annotationValues, fields); }
/** * Returns the JPA @Inheritance annotation to be applied to the entity, if * applicable * * @param annotationValues the values of the {@link RooJpaEntity} annotation * (required) * @return <code>null</code> if it's already present or not required */ private AnnotationMetadata getInheritanceAnnotation() { if (governorTypeDetails.getAnnotation(INHERITANCE) != null) { return null; } if (StringUtils.isNotBlank(annotationValues.getInheritanceType())) { final AnnotationMetadataBuilder inheritanceBuilder = new AnnotationMetadataBuilder(INHERITANCE); inheritanceBuilder.addEnumAttribute("strategy", new EnumDetails(INHERITANCE_TYPE, new JavaSymbolName(annotationValues.getInheritanceType()))); return inheritanceBuilder.build(); } return null; }
private JavaSymbolName getUserDefinedMethod( final List<MemberHoldingTypeDetails> memberHoldingTypeDetailsList, final Map<String, String> pluralMap) { if (catalystAnnotationType == null || userDefinedNameAttribute == null) { return null; } final String suffix = suffixPlural || suffixSingular ? getSuffix(memberHoldingTypeDetailsList, suffixSingular, pluralMap) : ""; final ClassOrInterfaceTypeDetails cid = getMostConcreteClassOrInterfaceTypeDetails(memberHoldingTypeDetailsList); for (final AnnotationMetadata annotationMetadata : cid.getAnnotations()) { if (annotationMetadata.getAnnotationType().getFullyQualifiedTypeName() .equals(catalystAnnotationType.getFullyQualifiedTypeName())) { final AnnotationAttributeValue<?> annotationAttributeValue = annotationMetadata.getAttribute(userDefinedNameAttribute); if (annotationAttributeValue != null && StringUtils.isNotBlank(annotationAttributeValue.getValue().toString())) { return new JavaSymbolName(annotationAttributeValue.getValue().toString() + suffix); } break; } } return defaultName == null ? null : new JavaSymbolName(defaultName + suffix); }
@Override public Pair<FieldMetadata, RelationInfo> getFieldChildPartOfCompositionRelation( ClassOrInterfaceTypeDetails entityCdi) { JavaType domainType = entityCdi.getType(); List<Pair<FieldMetadata, RelationInfo>> relations = getFieldChildPartOfRelation(entityCdi); if (relations.isEmpty()) { return null; } JpaEntityMetadata parent; JavaType parentType; RelationInfo info; List<Pair<FieldMetadata, RelationInfo>> compositionRelation = new ArrayList<Pair<FieldMetadata, RelationInfo>>(); for (Pair<FieldMetadata, RelationInfo> field : relations) { if (field.getRight().type == JpaRelationType.COMPOSITION) { compositionRelation.add(field); } } Validate.isTrue(compositionRelation.size() <= 1, "Entity %s has more than one relations of composition as child part: ", domainType, StringUtils.join(getFieldNamesOfRelationList(compositionRelation), ",")); if (compositionRelation.isEmpty()) { return null; } return compositionRelation.get(0); }
Validate.notNull(compilationUnit.getImports(), "Compilation unit imports should be non-null when producing type '%s'", cid.getName()); for (final ImportMetadata importType : cid.getRegisteredImports()) { ImportDeclaration importDeclaration; final int javaParserModifier = JavaParserUtils.getJavaParserModifier(cid.getModifier()); TypeDeclaration typeDeclaration; ClassOrInterfaceDeclaration classOrInterfaceDeclaration; for (final JavaType current : cid.getImplementsTypes()) { implementsList.add(JavaParserUtils.getResolvedName(cid.getName(), current, compilationUnit)); if (cid.getPhysicalTypeCategory() == PhysicalTypeCategory.INTERFACE || cid.getPhysicalTypeCategory() == PhysicalTypeCategory.CLASS) { final boolean isInterface = cid.getPhysicalTypeCategory() == PhysicalTypeCategory.INTERFACE; new ClassOrInterfaceDeclaration(javaParserModifier, isInterface, cid.getName() .getNameIncludingTypeParameters() .replace(cid.getName().getPackage().getFullyQualifiedPackageName() + ".", "")); classOrInterfaceDeclaration = (ClassOrInterfaceDeclaration) typeDeclaration; } else { new ClassOrInterfaceDeclaration(javaParserModifier, isInterface, cid.getName() if (cid.getName().getParameters().size() > 0) { classOrInterfaceDeclaration.setTypeParameters(new ArrayList<TypeParameter>()); for (final JavaType param : cid.getName().getParameters()) { NameExpr pNameExpr =
@Override public String getBaseUrlForController(ClassOrInterfaceTypeDetails controller) { Validate.notNull(controller, "controller is required"); Validate.notNull(controller.getAnnotation(RooJavaType.ROO_CONTROLLER), "%s must be annotated with @%s", controller.getType(), RooJavaType.ROO_CONTROLLER.getSimpleTypeName()); return sbuilder.toString(); } else if (values.getType() == ControllerType.ITEM) { return sbuilder.append("/{").append(StringUtils.uncapitalize(entity.getSimpleTypeName())) .append("}").toString(); } else if (values.getType() == ControllerType.SEARCH) { return sbuilder.append("/search").toString(); Validate.isTrue(values.getType() == ControllerType.DETAIL || values.getType() == ControllerType.DETAIL_ITEM, "Unsupported @%s.type '%s' on %s", RooJavaType.ROO_CONTROLLER, values.getType(), controller.getType()); controller.getAnnotation(RooJavaType.ROO_DETAIL).getAttribute(RELATION_FIELD_KEY); Validate.notNull(relationFieldAttr, "ERROR: In %s controller, @RooDetail annotation must have relationField value", controller.getType()); Validate.isTrue(detailsFieldInfo != null && detailsFieldInfo.size() > 0, "Missing details information for %s", controller.getType()); for (RelationInfo info : detailsFieldInfo) { sbuilder.append("/{").append(StringUtils.uncapitalize(info.entityType.getSimpleTypeName())) .append("}/").append(info.fieldName);
@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); }
Validate.notNull(entity, "Entity to produce a data on demand provider for is required"); Validate.notNull(name, "Name of the new data on demand provider is required"); final LogicalPath path = LogicalPath.getInstance(Path.SRC_TEST_JAVA, name.getModule()); Validate.notNull(path, "Location of the new data on demand provider is required"); projectOperations.addDependency(name.getModule(), VALIDATION_API_DEPENDENCY); Validate.isTrue(cid.getPhysicalTypeCategory() == PhysicalTypeCategory.CLASS, "Type %s is not a class", entity.getFullyQualifiedTypeName()); Validate.isTrue(!Modifier.isAbstract(cid.getModifier()), "Type %s is abstract", entity.getFullyQualifiedTypeName()); final List<AnnotationAttributeValue<?>> dodConfig = new ArrayList<AnnotationAttributeValue<?>>(); dodConfig.add(new ClassAttributeValue(new JavaSymbolName("entity"), entity)); annotations.add(new AnnotationMetadataBuilder(RooJavaType.ROO_JPA_DATA_ON_DEMAND, dodConfig)); typeManagementService.createOrUpdateTypeOnDisk(dodClassCid); return cid.getName();
projectOperations = getProjectOperations(); Validate.notNull(projectOperations, "ProjectOperations is required"); ClassOrInterfaceTypeDetails entityDetails = getTypeLocationService().getTypeDetails(entity); Map<String, FieldMetadata> relationsAsChild = new HashMap<String, FieldMetadata>(); for (FieldMetadata field : entityDetails.getDeclaredFields()) { if (field.getAnnotation(RooJavaType.ROO_JPA_RELATION) != null) { fieldsParent.add(field); || field.getAnnotation(JpaJavaType.MANY_TO_ONE) != null || field.getAnnotation(JpaJavaType.MANY_TO_MANY) != null) { relationsAsChild.put(field.getFieldName().getSymbolName(), field); List<FieldMetadata> identifierFields = entityDetails.getFieldsWithAnnotation(ID); List<FieldMetadata> embeddedIdentifierFields = entityDetails.getFieldsWithAnnotation(EMBEDDED_ID); Validate.isTrue(!(identifierFields.isEmpty() && embeddedIdentifierFields.isEmpty()), String .format("ERROR: The annotated entity '%s' doesn't contain any identifier field.", entityDetails.getType().getFullyQualifiedTypeName())); List<FieldMetadata> versionFields = entityDetails.getFieldsWithAnnotation(VERSION);
final InheritanceType inheritanceType, final List<AnnotationMetadataBuilder> annotations) { Validate.notNull(name, "Entity name required"); Validate.isTrue(!JdkJavaType.isPartOfJavaLang(name.getSimpleTypeName()), "Entity name '%s' must not be part of java.lang", name.getSimpleTypeName()); getProjectOperations().setModule(getProjectOperations().getPomFromModuleName(name.getModule())); if (!superclass.equals(OBJECT)) { final ClassOrInterfaceTypeDetails superclassClassOrInterfaceTypeDetails = getTypeLocationService().getTypeDetails(superclass); if (superclassClassOrInterfaceTypeDetails != null) { cidBuilder.setSuperclass(new ClassOrInterfaceTypeDetailsBuilder( final Set<JavaType> implementsTypes = new LinkedHashSet<JavaType>(); final ClassOrInterfaceTypeDetails typeDetails = getTypeLocationService().getTypeDetails(declaredByMetadataId); if (typeDetails != null) { implementsTypes.addAll(typeDetails.getImplementsTypes());
/** * Get controller path from GvNIXMapViewer annotated controllers * * @param controller * @return */ private String getControllerPathFromViewerController(JavaType controller) { final ClassOrInterfaceTypeDetails cidController = getTypeLocationService() .getTypeDetails(controller); Validate.notNull(cidController, "The type specified, '%s', doesn't exist", cidController); // Only for @GvNIXMapViewer annotated controllers final AnnotationMetadata controllerAnnotation = MemberFindingUtils .getAnnotationOfType(cidController.getAnnotations(), new JavaType(GvNIXMapViewer.class.getName())); Validate.isTrue(controllerAnnotation != null, "Operation for @GvNIXMapViewer annotated controllers only."); String controllerPath = (String) cidController .getAnnotation(SpringJavaType.REQUEST_MAPPING) .getAttribute(VALUE).getValue(); controllerPath = controllerPath.replaceAll("/", "").trim(); return controllerPath; }
.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; getPathResolver().getPath(klass.getModule(), path)); if (!memberHoldingTypeDetails.getType().equals(classDetails.getType())) { continue; .getFullyQualifiedTypeName()) && !method.getDeclaredByMetadataId().equals(declaredByMetadataId)) { classDetails = getTypeLocationService().getTypeDetails(detailsBuilder.build().getType()); classDetails.getDeclaredConstructor(parameterTypes); for (AnnotationMetadata annotation : allDeclaredAnnotations) { classDetails = getTypeLocationService().getTypeDetails(detailsBuilder.build().getType()); List<AnnotationMetadata> javaDeclaredAnnotations = classDetails.getAnnotations(); boolean annotationExists = false; for (AnnotationMetadata javaAnnotation : javaDeclaredAnnotations) { if (javaAnnotation.getAnnotationType().getFullyQualifiedTypeName() .equals(annotation.getAnnotationType().getFullyQualifiedTypeName())) { annotationExists = true;