use of org.springframework.roo.classpath.details.ClassOrInterfaceTypeDetailsBuilder in project spring-roo by spring-projects.
the class MailOperationsImpl method installReceiveEmailSupport.
@Override
public void installReceiveEmailSupport(String host, String port, String protocol, String username, String password, Boolean starttls, String jndiName, String profile, Pom module, JavaType service, boolean force) {
// Include springlets-boot-starter-mail in module
getProjectOperations().addDependency(module.getModuleName(), DEPENDENCY_SPRINGLETS_STARTER_MAIL);
// Include property version
getProjectOperations().addProperty("", PROPERTY_SPRINGLETS_VERSION);
// check if exists any property
if (getApplicationConfigService().existsSpringConfigFile(module.getModuleName(), profile) && areDefinedReceiveEmailProperties(module.getModuleName(), profile) && !force) {
// Send error message to user. He needs to set --force parameter
String profileStr = "profile " + profile;
if (profile == null) {
profileStr = "default profile";
}
String moduleStr = " and module " + module.getModuleName();
if (StringUtils.isEmpty(module.getModuleName())) {
moduleStr = "";
}
LOGGER.log(Level.INFO, String.format("There are defined the mail properties to %s" + "%s. Using this command with '--force' " + "will overwrite the current values.", profileStr, moduleStr));
} else {
Map<String, String> propertiesFormattedToInsert = getReceiveEmailPropertiesFormattedToInsert(host, port, protocol, username, password, starttls, jndiName);
// Set properties in file
getApplicationConfigService().addProperties(module.getModuleName(), propertiesFormattedToInsert, profile, force);
}
if (service != null) {
// Add dependency springlets-mail to the module of the selected Service
if (!service.getModule().equals(StringUtils.EMPTY)) {
getProjectOperations().addDependency(service.getModule(), DEPENDENCY_SPRINGLETS_MAIL);
}
// Add MailReceiverService to service
final ClassOrInterfaceTypeDetails serviceTypeDetails = 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);
// Create the field
cidBuilder.addField(new FieldMetadataBuilder(declaredByMetadataId, PRIVATE, Arrays.asList(new AnnotationMetadataBuilder(AUTOWIRED)), new JavaSymbolName("mailReceiver"), SpringletsJavaType.SPRINGLETS_MAIL_RECEIVER_SERVICE));
getTypeManagementService().createOrUpdateTypeOnDisk(cidBuilder.build());
}
}
use of org.springframework.roo.classpath.details.ClassOrInterfaceTypeDetailsBuilder in project spring-roo by spring-projects.
the class MailOperationsImpl method installSendEmailSupport.
@Override
public void installSendEmailSupport(String host, String port, String protocol, String username, String password, Boolean starttls, String jndiName, String profile, Pom module, JavaType service, boolean force) {
// Include spring-boot-starter-mail in module
getProjectOperations().addDependency(module.getModuleName(), DEPENDENCY_SPRING_BOOT_STARTER_MAIL);
// check if exists any property
if (getApplicationConfigService().existsSpringConfigFile(module.getModuleName(), profile) && areDefinedSendEmailProperties(module.getModuleName(), profile) && !force) {
// Send error message to user. He needs to set --force parameter
String profileStr = "profile " + profile;
if (profile == null) {
profileStr = "default profile";
}
String moduleStr = " and module " + module.getModuleName();
if (StringUtils.isEmpty(module.getModuleName())) {
moduleStr = "";
}
LOGGER.log(Level.INFO, String.format("There are defined the mail properties to %s" + "%s. Using this command with '--force' " + "will overwrite the current values.", profileStr, moduleStr));
} else {
Map<String, String> propertiesFormattedToInsert = getSendEmailPropertiesFormattedToInsert(host, port, protocol, username, password, starttls, jndiName);
// Set properties in file
getApplicationConfigService().addProperties(module.getModuleName(), propertiesFormattedToInsert, profile, force);
}
if (service != null) {
// Add dependency spring-context-support to the module of the selected Service
getProjectOperations().addDependency(service.getModule(), DEPENDENCY_SPRING_CONTEXT_SUPPORT);
// Add JavaMailSender to service
final ClassOrInterfaceTypeDetails serviceTypeDetails = 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);
// Create the field
cidBuilder.addField(new FieldMetadataBuilder(declaredByMetadataId, PRIVATE, Arrays.asList(new AnnotationMetadataBuilder(AUTOWIRED)), new JavaSymbolName("mailSender"), SpringJavaType.JAVA_MAIL_SENDER));
getTypeManagementService().createOrUpdateTypeOnDisk(cidBuilder.build());
}
}
use of org.springframework.roo.classpath.details.ClassOrInterfaceTypeDetailsBuilder in project spring-roo by spring-projects.
the class DbreDatabaseListenerImpl method createNewManagedEntityFromTable.
/**
* Creates a new DBRE-managed entity from the given table
*
* @param javaType the name of the entity to be created (required)
* @param table the table from which to create the entity (required)
* @return the newly created entity
*/
private ClassOrInterfaceTypeDetails createNewManagedEntityFromTable(final JavaType javaType, final Table table) {
// Create type annotations for new entity
final List<AnnotationMetadataBuilder> annotations = new ArrayList<AnnotationMetadataBuilder>();
annotations.add(new AnnotationMetadataBuilder(ROO_JAVA_BEAN));
annotations.add(new AnnotationMetadataBuilder(ROO_TO_STRING));
// Find primary key from db metadata and add identifier attributes to
// @RooJpaEntity
final AnnotationMetadataBuilder jpaAnnotationBuilder = new AnnotationMetadataBuilder(ROO_JPA_ENTITY);
manageIdentifier(javaType, jpaAnnotationBuilder, new HashSet<JavaSymbolName>(), table);
if (!hasVersionField(table)) {
jpaAnnotationBuilder.addStringAttribute(VERSION_FIELD, "");
}
if (table.isDisableGeneratedIdentifiers()) {
jpaAnnotationBuilder.addStringAttribute(SEQUENCE_NAME_FIELD, "");
}
jpaAnnotationBuilder.addStringAttribute("table", table.getName());
if (!DbreModelService.NO_SCHEMA_REQUIRED.equals(table.getSchema().getName())) {
jpaAnnotationBuilder.addStringAttribute("schema", table.getSchema().getName());
}
annotations.add(jpaAnnotationBuilder);
// Add @RooDbManaged
annotations.add(getRooDbManagedAnnotation());
final JavaType superclass = OBJECT;
final List<JavaType> extendsTypes = new ArrayList<JavaType>();
extendsTypes.add(superclass);
// Create entity class
final String declaredByMetadataId = PhysicalTypeIdentifier.createIdentifier(javaType, getProjectOperations().getPathResolver().getFocusedPath(Path.SRC_MAIN_JAVA));
final ClassOrInterfaceTypeDetailsBuilder cidBuilder = new ClassOrInterfaceTypeDetailsBuilder(declaredByMetadataId, Modifier.PUBLIC, javaType, PhysicalTypeCategory.CLASS);
cidBuilder.setExtendsTypes(extendsTypes);
cidBuilder.setAnnotations(annotations);
final ClassOrInterfaceTypeDetails entity = cidBuilder.build();
getTypeManagementService().createOrUpdateTypeOnDisk(entity);
getShell().flash(Level.FINE, "Created " + javaType.getFullyQualifiedTypeName(), DbreDatabaseListenerImpl.class.getName());
getShell().flash(Level.FINE, "", DbreDatabaseListenerImpl.class.getName());
return entity;
}
use of org.springframework.roo.classpath.details.ClassOrInterfaceTypeDetailsBuilder in project spring-roo by spring-projects.
the class DbreDatabaseListenerImpl method createIdentifierClass.
private void createIdentifierClass(final JavaType identifierType) {
final List<AnnotationMetadataBuilder> identifierAnnotations = new ArrayList<AnnotationMetadataBuilder>();
final AnnotationMetadataBuilder identifierBuilder = new AnnotationMetadataBuilder(ROO_IDENTIFIER);
identifierBuilder.addBooleanAttribute(DB_MANAGED.getSymbolName(), true);
identifierAnnotations.add(identifierBuilder);
// Produce identifier itself
final String declaredByMetadataId = PhysicalTypeIdentifier.createIdentifier(identifierType, getProjectOperations().getPathResolver().getFocusedPath(Path.SRC_MAIN_JAVA));
final ClassOrInterfaceTypeDetailsBuilder cidBuilder = new ClassOrInterfaceTypeDetailsBuilder(declaredByMetadataId, Modifier.PUBLIC | Modifier.FINAL, identifierType, PhysicalTypeCategory.CLASS);
cidBuilder.setAnnotations(identifierAnnotations);
getTypeManagementService().createOrUpdateTypeOnDisk(cidBuilder.build());
getShell().flash(Level.FINE, "Created " + identifierType.getFullyQualifiedTypeName(), DbreDatabaseListenerImpl.class.getName());
getShell().flash(Level.FINE, "", DbreDatabaseListenerImpl.class.getName());
}
use of org.springframework.roo.classpath.details.ClassOrInterfaceTypeDetailsBuilder in project spring-roo by spring-projects.
the class DbreMetadata method excludeFieldsInToStringAnnotation.
// XXX DiSiD: Invoke this method when add non other fields to builder
// http://projects.disid.com/issues/7455
private void excludeFieldsInToStringAnnotation(final String fieldName) {
if (toStringAnnotation == null) {
return;
}
final List<AnnotationAttributeValue<?>> attributes = new ArrayList<AnnotationAttributeValue<?>>();
final List<StringAttributeValue> ignoreFields = new ArrayList<StringAttributeValue>();
// Copy the existing attributes, excluding the "ignoreFields" attribute
boolean alreadyAdded = false;
AnnotationAttributeValue<?> value = toStringAnnotation.getAttribute(new JavaSymbolName("excludeFields"));
if (value == null) {
value = new ArrayAttributeValue<StringAttributeValue>(new JavaSymbolName("excludeFields"), new ArrayList<StringAttributeValue>());
}
// Ensure we have an array of strings
final String errMsg = "@RooToString attribute 'excludeFields' must be an array of strings";
Validate.isInstanceOf(ArrayAttributeValue.class, value, errMsg);
final ArrayAttributeValue<?> arrayVal = (ArrayAttributeValue<?>) value;
for (final Object obj : arrayVal.getValue()) {
Validate.isInstanceOf(StringAttributeValue.class, obj, errMsg);
final StringAttributeValue sv = (StringAttributeValue) obj;
if (sv.getValue().equals(fieldName)) {
alreadyAdded = true;
}
ignoreFields.add(sv);
}
// Add the desired field to ignore to the end
if (!alreadyAdded) {
ignoreFields.add(new StringAttributeValue(new JavaSymbolName("ignored"), fieldName));
}
attributes.add(new ArrayAttributeValue<StringAttributeValue>(new JavaSymbolName("excludeFields"), ignoreFields));
final AnnotationMetadataBuilder toStringAnnotationBuilder = new AnnotationMetadataBuilder(ROO_TO_STRING, attributes);
updatedGovernorBuilder = new ClassOrInterfaceTypeDetailsBuilder(governorTypeDetails);
toStringAnnotation = toStringAnnotationBuilder.build();
updatedGovernorBuilder.updateTypeAnnotation(toStringAnnotation, new HashSet<JavaSymbolName>());
}
Aggregations