final FieldMetadata identifierField, final boolean hasJavaBeanAnnotation) { super(identifier, aspectName, governorPhysicalTypeMetadata); Validate.isTrue(isValid(identifier), "Metadata id '%s' is invalid", identifier); Validate.notNull(annotationValues, "Annotation values required"); Validate.notNull(identifierField, "Couldn't find any identifier field for %s", this.destination.getSimpleTypeName()); ensureGovernorHasMethod(new MethodMetadataBuilder(getEqualsMethod())); ensureGovernorHasMethod(new MethodMetadataBuilder(getHashCodeMethod())); itdTypeDetails = builder.build();
private InvocableMemberBodyBuilder getEntityCollectionAccessorBody(final FieldMetadata field, final JavaSymbolName entityIdsFieldName) { final String entityCollectionName = field.getFieldName().getSymbolName(); final String entityIdsName = entityIdsFieldName.getSymbolName(); final String localEnitiesName = "local" + StringUtils.capitalize(entityCollectionName); final JavaType collectionElementType = field.getFieldType().getParameters().get(0); final String simpleCollectionElementTypeName = collectionElementType.getSimpleTypeName(); builder.getImportRegistrationResolver().addImport(collectionType); field.getFieldType().getNameIncludingTypeParameters() .replace(field.getFieldType().getPackage().getFullyQualifiedPackageName() + ".", ""); String instantiableCollection = collectionName; builder.getImportRegistrationResolver().addImport(collectionType);
/** * Constructor * * @param identifier * @param aspectName * @param governorPhysicalTypeMetadata * @param annotationValues * @param fields * @param hasJavaBeanAnnotation */ public ToStringMetadata(final String identifier, final JavaType aspectName, final PhysicalTypeMetadata governorPhysicalTypeMetadata, final ToStringAnnotationValues annotationValues, List<FieldMetadata> fields, boolean hasJavaBeanAnnotation) { super(identifier, aspectName, governorPhysicalTypeMetadata); Validate.isTrue(isValid(identifier), "Metadata identification string '%s' does not appear to be a valid", identifier); Validate.notNull(annotationValues, "Annotation values required"); this.annotationValues = annotationValues; this.fields = fields; if (!hasJavaBeanAnnotation && !fields.isEmpty()) { // Generate the toString() method builder.addMethod(getToStringMethod()); } // Create a representation of the desired output ITD itdTypeDetails = builder.build(); }
public ConfigurableMetadata(final String identifier, final JavaType aspectName, final PhysicalTypeMetadata governorPhysicalTypeMetadata) { super(identifier, aspectName, governorPhysicalTypeMetadata); Validate.isTrue(isValid(identifier), "Metadata identification string '%s' does not appear to be a valid", identifier); if (!isValid()) { return; } builder.addAnnotation(getConfigurableAnnotation()); // Create a representation of the desired output ITD itdTypeDetails = builder.build(); }
builder.setDeclarePrecedence(aspectName); new AnnotationMetadataBuilder(SpringJavaType.PRE_AUTHORIZE); preauthorizeAnnotation.addStringAttribute("value", entry.getValue()); DeclaredMethodAnnotationDetails preauthorizeAnnotationInGetterMethod = new DeclaredMethodAnnotationDetails(entry.getKey(), preauthorizeAnnotation.build()); builder.addMethodAnnotation(preauthorizeAnnotationInGetterMethod); itdTypeDetails = builder.build();
final String collaboratingFieldName = getCollaboratingFieldName(entityNeedingCollaborator, entityFactoryClasses) .getSymbolName(); final JavaSymbolName fieldSymbolName = new JavaSymbolName(collaboratingFieldName); final FieldMetadata candidate = governorTypeDetails.getField(fieldSymbolName); if (candidate != null) { .isTrue(candidate.getFieldType().equals(collaboratorType), "Field '%s' on '%s' must be of type '%s'", collaboratingFieldName, destination.getFullyQualifiedTypeName(), collaboratorType.getFullyQualifiedTypeName()); Validate.isTrue(Modifier.isPrivate(candidate.getModifier()), "Field '%s' on '%s' must be private", collaboratingFieldName, destination.getFullyQualifiedTypeName()); Validate.notNull( MemberFindingUtils.getAnnotationOfType(candidate.getAnnotations(), AUTOWIRED), "Field '%s' on '%s' must be @Autowired", collaboratingFieldName, annotations.add(new AnnotationMetadataBuilder(AUTOWIRED)); builder.addField(new FieldMetadataBuilder(getId(), 0, annotations, fieldSymbolName, collaboratorType)); fields.add(fieldSymbolName);
final List<Identifier> identifierServiceResult) { super(identifier, aspectName, governorPhysicalTypeMetadata); Validate.isTrue(isValid(identifier), "Metadata identification string '" + identifier + "' does not appear to be a valid"); Validate.notNull(annotationValues, "Annotation values required"); builder.addAnnotation(getEmbeddableAnnotation()); builder.addField(field); builder.addConstructor(getParameterizedConstructor(fields)); builder.addConstructor(getNoArgConstructor()); builder.addMethod(accessor); builder.addMethod(mutator); builder.putCustomData(IDENTIFIER_TYPE, null);
List<String> declaredFinderNames) { super(identifier, aspectName, governorPhysicalTypeMetadata); Validate.notNull(annotationValues, "Annotation values required"); for (Pair<FieldMetadata, RelationInfo> fieldInfo : relationsAsChild) { countMethod = getCountMethodByField(fieldInfo.getLeft(), fieldInfo.getRight()); ensureGovernorHasMethod(new MethodMetadataBuilder(countMethod)); countMethodByReferencedFields.put(fieldInfo.getLeft(), countMethod); ensureGovernorExtends(JavaType.wrapperOf(interfaceType, annotationValues.getEntity(), identifierType)); new AnnotationMetadataBuilder(SpringJavaType.TRANSACTIONAL); transactionalAnnotation.addBooleanAttribute("readOnly", true); ensureGovernorIsAnnotated(transactionalAnnotation); if (!StringUtils.startsWith(finderMethod.getMethodName().getSymbolName(), "count")) { countMethod = getCountMethod(finderMethod).build(); if (!isAlreadyDeclaredMethod(countMethod, countMethodsTmp)) { itdTypeDetails = builder.build();
final AnnotationMetadataBuilder runWithBuilder = new AnnotationMetadataBuilder(RUN_WITH); runWithBuilder.addClassAttribute("value", "org.springframework.test.context.junit4.SpringJUnit4ClassRunner"); builder.addAnnotation(runWithBuilder); SpringJavaType.ACTIVE_PROFILES) == null) { final AnnotationMetadataBuilder activeProfilesBuilder = new AnnotationMetadataBuilder(SpringJavaType.ACTIVE_PROFILES); activeProfilesBuilder.addStringAttribute("value", "dev"); builder.addAnnotation(activeProfilesBuilder); builder.addAnnotation(webAppConfigurationBuilder); builder.addAnnotation(springBootTestBuilder); new JavaSymbolName("dod"), dataOnDemandType); builder.addField(fieldBuilder); Validate.isTrue(fieldRepo.getFieldType().equals(repository), Validate.notNull( MemberFindingUtils.getAnnotationOfType(fieldRepo.getAnnotations(), AUTOWIRED), "Field 'repository' on '%s' must be annotated with @Autowired", builder.addField(fieldBuilderRepo); builder.getImportRegistrationResolver().addImport(ASSERT);
List<Pair<FieldMetadata, RelationInfo>> relationsAsChild) { super(identifier, aspectName, governorPhysicalTypeMetadata); Validate.notNull(annotationValues, "Annotation values required"); Validate.notNull(repositoryMetadata, "Referenced fields could be empty but not null"); if (referencedField.getRight().type == JpaRelationType.COMPOSITION) { Validate.isTrue(!composition, "Entity %s has defined more than one relations as child part whit type composition.", aspectName); ensureGovernorHasMethod(new MethodMetadataBuilder(method)); tempTeferencedFieldsFindAllMethods.put(referencedField.getLeft(), method); ensureGovernorHasMethod(new MethodMetadataBuilder(findAllGlobalSearchMethod)); findAllByIdsInGlobalSearchMethod = getFindAllByIdsInGlobalSearchMethod(); ensureGovernorHasMethod(new MethodMetadataBuilder(findAllByIdsInGlobalSearchMethod)); } else { findAllGlobalSearchMethod = null; if (!StringUtils.startsWith(finderMethod.getMethodName().getSymbolName(), "count")) { countMethod = getCustomCount(fromBean, finderMethod.getMethodName()); if (!isAlreadyDeclaredMethod(countMethod, allCountMethods)) { itdTypeDetails = builder.build();
List<FieldMetadata> toStringFields) { super(identifier, aspectName, governorPhysicalTypeMetadata); Validate.isTrue(isValid(identifier), "Metadata identification string '%s' does not appear to be a valid", identifier); Validate.notNull(annotationValues, "Annotation values required"); Validate.notNull(declaredFields, "Declared fields required"); equalsAnnotationValues, equalsFields, builder.getImportRegistrationResolver())); itdTypeDetails = builder.build();
.addAnnotation(annotationValues.isMappedSuperclass() ? getTypeAnnotation(MAPPED_SUPERCLASS) : getEntityAnnotation()); builder.addAnnotation(getTableAnnotation()); builder.addAnnotation(getInheritanceAnnotation()); builder.addAnnotation(getDiscriminatorColumnAnnotation()); builder.addAnnotation(getEntityFormatAnnotation()); ImportRegistrationResolver importResolver = builder.getImportRegistrationResolver(); fieldName = field.getFieldName().getSymbolName(); childType = field.getFieldType(); } else { childType = field.getFieldType().getBaseType(); importResolver); ensureGovernorHasMethod(new MethodMetadataBuilder(addMethod)); ensureGovernorHasMethod(new MethodMetadataBuilder(removeMethod)); getMappedByInfoKey(field.getFieldType().getBaseType(), mappedBy), info); itdTypeDetails = builder.build();
final Map<JavaType, Boolean> typesAreProjections) { super(identifier, aspectName, governorPhysicalTypeMetadata); Validate.notNull(annotationValues, "Annotation values required"); this.importResolver = builder.getImportRegistrationResolver(); this.entity = domainType; this.entityMetadata = entityMetadata; new AnnotationMetadataBuilder(SpringJavaType.TRANSACTIONAL); transactionalAnnotation.addBooleanAttribute("readOnly", true); ensureGovernorIsAnnotated(transactionalAnnotation); FieldMetadata newConstant = getConstantForField(field.getFieldName().getSymbolName()); if (!addedFields.contains(newConstant.getFieldName())) { ensureGovernorHasField(new FieldMetadataBuilder(newConstant)); ensureGovernorHasMethod(new MethodMetadataBuilder(getFindAllImpl(findAllGlobalSearchMethod, idField, validFields))); ensureGovernorHasMethod(new MethodMetadataBuilder(getFindAllByIdsInImpl( findAllByIdsInGlobalSearchMethod, idField, validFields))); ensureGovernorHasMethod(new MethodMetadataBuilder(getFindByReferencedFieldsImpl( method.getKey(), method.getValue(), referencedPathFieldName, validFields))); itdTypeDetails = builder.build();
@Override protected void onAddMethod(final MethodMetadataBuilder md) { Validate.isTrue( MemberFindingUtils.getDeclaredMethod(governor, md.getMethodName(), AnnotatedJavaType.convertFromAnnotatedJavaTypes(md.getParameterTypes())) == null, "Method '%s' already defined in target type '%s' (ITD target '%s')", md.getMethodName(), governor.getName().getFullyQualifiedTypeName(), aspect.getFullyQualifiedTypeName()); Validate.isTrue( MemberFindingUtils.getDeclaredMethod(build(), md.getMethodName(), AnnotatedJavaType.convertFromAnnotatedJavaTypes(md.getParameterTypes())) == null, "Method '%s' already defined in ITD (ITD target '%s')", md.getMethodName(), aspect.getFullyQualifiedTypeName()); if (!Modifier.isAbstract(md.getModifier()) && md.getReturnType() != JavaType.VOID_PRIMITIVE) { Validate.notBlank(md.getBody(), "Method '%s' failed to provide a body, despite being identified for ITD inclusion", md); } } }
Set<ClassOrInterfaceTypeDetails> entityFactoryClasses, final EmbeddedIdHolder embeddedIdHolder) { super(identifier, aspectName, governorPhysicalTypeMetadata); Validate.notNull(locatedFields, "Located fields map required"); Validate.notNull(embeddedHolders, "Embedded holders list required"); this.locatedFields = locatedFields; builder.addMethod(getCreateMethod()); builder.addMethod(getEmbeddedClassMutatorMethod(embeddedHolder)); addEmbeddedClassFieldMutatorMethodsToBuilder(embeddedHolder, entityFactoryClasses); builder.addMethod(fieldInitializerMethod); builder.addMethod(getEmbeddedIdMutatorMethod(entityFactoryClasses)); itdTypeDetails = builder.build();
@Override protected void onAddConstructor(final ConstructorMetadataBuilder md) { Validate.isTrue(governor.getDeclaredConstructor(AnnotatedJavaType .convertFromAnnotatedJavaTypes(md.getParameterTypes())) == null, "Constructor with %d parameters already defined in target type '%s' (ITD target '%s')", md .getParameterTypes().size(), governor.getName().getFullyQualifiedTypeName(), aspect .getFullyQualifiedTypeName()); Validate.isTrue( build().getDeclaredConstructor( AnnotatedJavaType.convertFromAnnotatedJavaTypes(md.getParameterTypes())) == null, "Constructor with %d parameters already defined in ITD (ITD target '%s')", md .getParameterTypes().size(), aspect.getFullyQualifiedTypeName()); Validate .notBlank( md.getBody(), "Constructor '%s' failed to provide a body, despite being identified for ITD inclusion", md); }
public WSExportExceptionMetadata(String identifier, JavaType aspectName, PhysicalTypeMetadata governorPhysicalTypeMetadata) { super(identifier, aspectName, governorPhysicalTypeMetadata); Validate.isTrue(isValid(identifier), "Metadata identification string '" + identifier + "' does not appear to be a valid"); if (!isValid()) { return; } // Create the metadata. AnnotationMetadata annotationMetadata = governorTypeDetails .getTypeAnnotation(new JavaType(GvNIXWebFault.class.getName())); // Add @javax.jws.WebFault annotation to ITD. AnnotationMetadata webFaultAnnotationMetadata = getTypeAnnotation(annotationMetadata); if (webFaultAnnotationMetadata != null) { builder.addAnnotation(webFaultAnnotationMetadata); } // Create a representation of the desired output ITD itdTypeDetails = builder.build(); }
if (fieldType.equals(DATE)) { if (MemberFindingUtils.getAnnotationOfType(field.getAnnotations(), PAST) != null) { builder.getImportRegistrationResolver().addImport(DATE); initializer = "new Date(new Date().getTime() - 10000000L)"; } else if (MemberFindingUtils.getAnnotationOfType(field.getAnnotations(), FUTURE) != null) { builder.getImportRegistrationResolver().addImport(DATE); initializer = "new Date(new Date().getTime() + 10000000L)"; } else { builder.getImportRegistrationResolver().addImports(CALENDAR, GREGORIAN_CALENDAR); initializer = "new GregorianCalendar(Calendar.getInstance().get(Calendar.YEAR), \n\t\t\tCalendar.getInstance().get(Calendar.MONTH), \n\t\t\tCalendar.getInstance().get(Calendar.DAY_OF_MONTH), \n\t\t\tCalendar.getInstance().get(Calendar.HOUR_OF_DAY), \n\t\t\tCalendar.getInstance().get(Calendar.MINUTE), \n\t\t\tCalendar.getInstance().get(Calendar.SECOND) + \n\t\t\tnew Double(Math.random() * 1000).intValue()).getTime()"; } else if (fieldType.equals(CALENDAR)) { builder.getImportRegistrationResolver().addImports(CALENDAR, GREGORIAN_CALENDAR); initializer = "Calendar.getInstance()"; } else if (fieldType.equals(TIMESTAMP)) { builder.getImportRegistrationResolver().addImports(CALENDAR, GREGORIAN_CALENDAR, TIMESTAMP); initializer = "new Timestamp(new GregorianCalendar(Calendar.getInstance().get(Calendar.YEAR), \n\t\t\tCalendar.getInstance().get(Calendar.MONTH), \n\t\t\tCalendar.getInstance().get(Calendar.DAY_OF_MONTH), \n\t\t\tCalendar.getInstance().get(Calendar.HOUR_OF_DAY), \n\t\t\tCalendar.getInstance().get(Calendar.MINUTE), \n\t\t\tCalendar.getInstance().get(Calendar.SECOND) + \n\t\t\tnew Double(Math.random() * 1000).intValue()).getTime().getTime())"; builder.getImportRegistrationResolver().addImport(BIG_DECIMAL); builder.getImportRegistrationResolver().addImport(BIG_INTEGER); builder.getImportRegistrationResolver().addImport(fieldType);
@Override protected void onAddAnnotation(final AnnotationMetadataBuilder md) { Validate.isTrue(governor.getAnnotation(md.getAnnotationType()) == null, "Type annotation '%s' already defined in target type '%s' (ITD target '%s')", md.getAnnotationType(), governor.getName().getFullyQualifiedTypeName(), aspect.getFullyQualifiedTypeName()); Validate.isTrue(build().getAnnotation(md.getAnnotationType()) == null, "Type annotation '%s' already defined in ITD (ITD target '%s')", md.getAnnotationType(), aspect.getFullyQualifiedTypeName()); }
/** * Constructor * * @param identifier * @param aspectName * @param governorPhysicalTypeMetadata */ public EntityProjectionMetadata(final String identifier, final JavaType aspectName, final PhysicalTypeMetadata governorPhysicalTypeMetadata, final EntityProjectionAnnotationValues annotationValues, final List<FieldMetadata> fields) { super(identifier, aspectName, governorPhysicalTypeMetadata); Validate .isTrue( isValid(identifier), "Metadata identification string '%s' does not appear to be a valid physical type identifier", identifier); this.fields = fields; this.annotationValues = annotationValues; this.type = governorPhysicalTypeMetadata.getType(); ConstructorMetadataBuilder constructorMetadata = getConstructor(); if (!constructorMetadata.getParameterTypes().isEmpty()) { ensureGovernorHasConstructor(constructorMetadata); } // ROO-3868: New entity visualization support using a new format annotation ensureGovernorIsAnnotated(new AnnotationMetadataBuilder(getEntityFormatAnnotation())); // Build ITD itdTypeDetails = builder.build(); }