public List<RelationInfoExtended> getRelationInfoFor(final JpaEntityMetadata entityMetadata, final String path) { Validate.notNull(entityMetadata, "entity metadata is required"); Validate.notBlank(path, "path is required"); List<RelationInfoExtended> infos = new ArrayList<RelationInfoExtended>(); String[] split = StringUtils.split(path, '.'); RelationInfo info = entityMetadata.getRelationInfos().get(split[0]); Validate.notNull(info, "%s.%s not found or not a relation field", entityMetadata.getDestination(), split[0]); ClassOrInterfaceTypeDetails childCid = getTypeLocationService().getTypeDetails(info.childType); JpaEntityMetadata childMetadata = getMetadataService().get(JpaEntityMetadata.createIdentifier(childCid)); infos.add(new RelationInfoExtended(info, entityMetadata, childMetadata)); if (split.length > 1) { infos .addAll(getRelationInfoFor(childMetadata, StringUtils.join(split, '.', 1, split.length))); } return infos; }
} else { .getType().getFullyQualifiedTypeName()); getMetadataService().get(JpaEntityMetadata.createIdentifier(entityDetails)); getPluralService().getPlural(entityMetadata.getCurrentIndentifierField().getFieldName()); ClassOrInterfaceTypeDetails childEntityDetails; JpaEntityMetadata childEntityMetadata; for (RelationInfo info : entityMetadata.getRelationInfos().values()) { if (info.cardinality == Cardinality.ONE_TO_ONE && info.type == JpaRelationType.COMPOSITION) { childEntityDetails = getTypeLocationService().getTypeDetails(info.childType); childEntityMetadata = getMetadataService().get(JpaEntityMetadata.createIdentifier(childEntityDetails)); compositionRelationOneToOne.add(Pair.of(info, childEntityMetadata)); String finderName = serviceFinder.getMethodName().getSymbolName(); if (finders.contains(finderName)) { findersToAdd.put(finderName, serviceFinder); types.add(serviceFinder.getReturnType()); types.addAll(serviceFinder.getReturnType().getParameters()); for (AnnotatedJavaType parameter : serviceFinder.getParameterTypes()) { types.add(parameter.getJavaType()); types.addAll(parameter.getJavaType().getParameters());
/** * Constructs a DetailEntityItem using the fieldName and suffixId * * @param fieldName * the fieldName that represents the relationship * @param suffixId * used to generate field id */ public DetailEntityItem(JpaEntityMetadata childEntityMetadata, ControllerMetadata controllerMetadata, String controllerPath, String detailSuffix, EntityItem rootEntity) { super(childEntityMetadata.getDestination().getSimpleTypeName(), detailSuffix, childEntityMetadata.isReadOnly()); this.level = controllerMetadata.getDetailsFieldInfo().size(); this.rootEntity = rootEntity; this.fieldInfo = controllerMetadata.getLastDetailsInfo(); this.fieldName = fieldInfo.fieldName; this.fieldNameCapitalized = StringUtils.capitalize(fieldName); this.tabLinkCode = null; this.pathString = controllerMetadata.getDetailsPathAsString("-"); this.pathStringFieldNames = controllerMetadata.getDetailsPathAsString("."); this.controllerPath = controllerPath; this.templatePath = StringUtils.removeStart(controllerPath, "/"); this.z = calculateZ(); buildDetailItemId(detailSuffix); }
protected EntityItem createEntityItem(JpaEntityMetadata entityMetadata, ViewContext<T> ctx, String suffix) { String versionFieldName = null; if (entityMetadata.getCurrentVersionField() != null) { versionFieldName = entityMetadata.getCurrentVersionField().getFieldName().getSymbolName(); } return new EntityItem(ctx.getEntityName(), ctx.getIdentifierField(), ctx.getControllerPath(), suffix, entityMetadata.isReadOnly(), versionFieldName); }
String[] relationPath = StringUtils.split(relationField, '.'); for (String relName : relationPath) { curInfo = null; if (curEntity.getRelationInfos() != null) { curInfo = curEntity.getRelationInfos().get(relName); curEntity.getRelationInfos(), "ERROR: In %s controller, @RooDetail: Invalid value '%s': Can't get relation information about '%s' on %s entity", controller, relationField, relName, curEntity.getDestination()); Validate .isTrue( "ERROR: In %s controller, @RooDetail '%s' [%s] has unsupported type (%s) on '%s' entity: should be ONE_TO_MANY or MANY_TO_MANY", controller, relName, relationField, curInfo.cardinality.name(), curEntity.getDestination()); info.add(curInfo);
final List<JavaSymbolName> parameterNames = new ArrayList<JavaSymbolName>(1); if (cardinality != Cardinality.ONE_TO_ONE) { parameterTypes.add(JavaType.iterableOf(childType)); parameterNames.add(new JavaSymbolName(field.getFieldName().getSymbolName() + REMOVE_PARAMETER_SUFFIX)); MethodMetadata existingMethod = getGovernorMethod(removeMethodName, parameterTypes); if (existingMethod != null) { return existingMethod; buildRemoveOneToOneBody(field, mappedBy, builder); } else if (cardinality == Cardinality.ONE_TO_MANY) { buildRemoveOneToManyBody(field, mappedBy, parameterNames.get(0), childType, builder, importResolver); } else { buildRemoveManyToManyBody(field, mappedBy, parameterNames.get(0), childType, builder, importResolver); return new MethodMetadataBuilder(getId(), Modifier.PUBLIC, removeMethodName, JavaType.VOID_PRIMITIVE, AnnotatedJavaType.convertFromJavaTypes(parameterTypes), parameterNames, builder).build();
.format( "ERROR: The provided class %s is not a valid entity. It should be annotated with @RooJpaEntity", entity.getSimpleTypeName())); if (existingController.getType().getPackage().equals(controllerPackage)) { ControllerAnnotationValues values = new ControllerAnnotationValues(existingController); AnnotationMetadata responseTypeAnnotation = .format( "INFO: Doesn't exist parent controller in the package %s with the response type %s for the entity %s. Please, use 'web mvc controller' command to create them.", controllerPackage, responseType.getName(), entity.getSimpleTypeName())); getMetadataService().get(JpaEntityMetadata.createIdentifier(entityDetails)); if (StringUtils.isNotBlank(relationField)) { for (RelationInfo info : entityMetadata.getRelationInfos().values()) { if (info.cardinality == Cardinality.ONE_TO_MANY || info.cardinality == Cardinality.MANY_TO_MANY) {
MemberDetails entityMemberDetails = getMemberDetailsScanner().getMemberDetails(this.getClass().getName(), entityDetails); final String entityMetadataId = JpaEntityMetadata.createIdentifier(entityDetails); final JpaEntityMetadata entityMetadata = getMetadataService().get(entityMetadataId); if (entityMetadata.isReadOnly()) { ROO_REPOSITORY_JPA_CUSTOM.getSimpleTypeName(), entity.getSimpleTypeName()); Validate.isTrue(repositoryCustomList.size() == 1, "More than one interface annotated with @%s(entity=%s): %s", ROO_REPOSITORY_JPA_CUSTOM.getSimpleTypeName(), entity.getSimpleTypeName(), StringUtils.join(repositoryCustomList, ",")); new FinderMethod(returnType, new JavaSymbolName(finderName), Arrays.asList(new FinderParameter(formBean, new JavaSymbolName(StringUtils .uncapitalize(formBean.getSimpleTypeName()))))); findersToAddInCustom.add(Pair.of(finderMethod, finder));
final String entityMetadataId = JpaEntityMetadata.createIdentifier(entityDetails); registerDependency(entityMetadataId, metadataIdentificationString); final JpaEntityMetadata entityMetadata = getMetadataService().get(entityMetadataId); Validate.isTrue(StringUtils.isNotBlank(detailAnnotaionFieldValue), "ERROR: In %s controller, @RooDetail annotation must have relationField value", controller); registerDependency(info.childEntityMetadata.getId(), metadataIdentificationString); for (String fieldName : entityMetadata.getRelationInfos().keySet()) { RelationInfoExtended info = getControllerOperations().getRelationInfoFor(entityMetadata, fieldName).get(0);
for (RelationInfo relationInfo : entityMetadata.getRelationInfos().values()) { if (relationInfo.type == JpaRelationType.COMPOSITION && relationInfo.cardinality == Cardinality.ONE_TO_ONE) { BeanInfoUtils.getAccessorMethodName(field.getValue()).getSymbolName(); bodyBuilder.appendIndent(); bodyBuilder.appendFormalLine(String.format("if (%s.%s() != null) {", SpringJavaType.ASSERT.getNameIncludingTypeParameters(false, importResolver), referencedFieldParamName, referencedFieldParamName)); bodyBuilder.newLine(); if (referencedField.getAnnotation(JpaJavaType.MANY_TO_MANY) != null) { while (iterator.hasNext()) { Entry<String, FieldMetadata> field = iterator.next(); String fieldName = field.getValue().getFieldName().getSymbolName(); toAppend.add(entityVariable + "." + fieldName); bodyBuilder.append(StringUtils.join(toAppend, ',')); bodyBuilder.append("};"); bodyBuilder.newLine();
RelationInfo info = entityMetadata.getRelationInfos().get(relationField[level]); if (info == null) { return null; currentPathList.add(relationField[i]); String currentPath = StringUtils.join(currentPathList, '.'); JpaEntityMetadata childEntity = getMetadataService().get( JpaEntityMetadata.createIdentifier(getTypeLocationService().getTypeDetails( info.childType))); List<RelationInfo> subPath = if (LOGGER.isLoggable(Level.INFO)) { LOGGER.info(String.format("Details controller is required for %s befor can create %s", currentPath, StringUtils.join(Arrays.asList(relationField), ',')));
.format( "ERROR: The provided class %s is not a valid entity. It should be annotated with @RooEntity", entity.getSimpleTypeName())); getMetadataService().get(JpaEntityMetadata.createIdentifier(entityDetails)); if (entityMetadata.isCompositionChild()) { if (LOGGER.isLoggable(Level.INFO)) { .format( "INFO: The provided class %s is composition child part of a relationship. No controller is needed as it's managed form parent controller", entity.getSimpleTypeName())); .format( "ERROR: You must generate a service to '%s' entity before to generate a new controller.", entity.getFullyQualifiedTypeName())); values = new ControllerAnnotationValues(existingController); if ((values.getType() == ControllerType.COLLECTION || values.getType() == ControllerType.ITEM) && (StringUtils.equals(values.getPathPrefix(), pathPrefix) && existingController .getAnnotation(responseType.getAnnotation()) != null)) { String entityPluralCapitalized = StringUtils.capitalize(getPluralService().getPlural(entity)); JavaType collectionController = new JavaType(String.format("%s.%sCollection%sController",
JpaEntityMetadata.createIdentifier(getTypeLocationService().getTypeDetails(entity))); if (entityMetadata != null && entityMetadata.isReadOnly()) { isReadOnly = true; if (StringUtils.startsWith(finderName, "count")) { finderPath = StringUtils.removeStart(finderName, "count"); } else if (StringUtils.startsWith(finderName, "find")) { finderPath = StringUtils.removeStart(finderName, "find"); } else if (StringUtils.startsWith(finderName, "query")) { String keyThatRepresentsEntry = pathPrefix.concat(entity.getSimpleTypeName()); createMenuEntry(entity.getSimpleTypeName(), path, pathPrefix, FieldItem.buildLabel(entity.getSimpleTypeName(), ""), FieldItem.buildLabel(entity.getSimpleTypeName(), "plural"), finderNamesAndPaths, false, false, false);
String pathVariableUncapitalized = StringUtils.uncapitalize(pathVariable); new JavaSymbolName("get" + StringUtils.capitalize(pathVariable)); serviceMetadata.getCurrentFindOneMethod().getParameterTypes().get(0).getJavaType(); final JavaSymbolName idName = serviceMetadata.getCurrentFindOneMethod().getParameterNames().get(0); final JavaType entityType = serviceMetadata.getCurrentFindOneMethod().getReturnType(); pathVariableAnnotation.addStringAttribute("value", pathVariableUncapitalized); parameterTypes.add(new AnnotatedJavaType(idType, pathVariableAnnotation.build())); parameterTypes.add(LOCALE_PARAM); parameterTypes.add(new AnnotatedJavaType(SpringJavaType.HTTP_METHOD)); if (this.entityMetadata.isReadOnly()) { pathVariableUncapitalized, serviceField.getFieldName(), serviceMetadata .getCurrentFindOneMethod().getMethodName(), idName); "String message = %s.getMessage(\"error_NotFound\", new Object[] " + "{\"%s\", %s}, \"The record couldn't be found\", %s);", MESSAGE_SOURCE, this.entity.getSimpleTypeName(), idName, LOCALE_PARAM_NAME.getSymbolName()); .getFieldName().getSymbolName(), FIN_ONE_FOR_UPDATE_METHOD_NAME.getSymbolName(), idName); .getFieldName().getSymbolName(), serviceMetadata.getCurrentFindOneMethod() .getMethodName().getSymbolName(), idName);
new AnnotationMetadataBuilder(REQUEST_PARAM); requestParamIdsAnnotation.addStringAttribute("value", "ids"); parameterTypes.add(new AnnotatedJavaType(JavaType.wrapperOf(JavaType.LIST, entityMetadata .getCurrentIndentifierField().getFieldType()), requestParamIdsAnnotation.build())); parameterTypes.add(DATATABLES_COLUMNS_PARAM); parameterTypes.add(GLOBAL_SEARCH_PARAM); AnnotationMetadataBuilder requestParamAnnotation = new AnnotationMetadataBuilder(REQUEST_PARAM); requestParamAnnotation.addStringAttribute("value", "draw"); parameterTypes.add(new AnnotatedJavaType(JavaType.INT_OBJECT, requestParamAnnotation.build())); AnnotatedJavaType.convertFromAnnotatedJavaTypes(parameterTypes)); if (existingMethod != null) { return existingMethod; final String itemNames = StringUtils.uncapitalize(this.entityPlural); JavaType defaultReturnType = findAllMethod.getReturnType().getParameters().get(0); getAccessorMethod(this.controllerMetadata.getServiceField()).getMethodName(), findAllMethod.getMethodName()); final String totalVarName = "total" + StringUtils.capitalize(this.entityPlural) + "Count"; JavaType.wrapperOf(RESPONSE_ENTITY, JavaType.wrapperOf( SpringletsJavaType.SPRINGLETS_CONVERTED_DATATABLES_DATA, defaultReturnType));
private MethodMetadata getUpdateDetailMethod() { final JavaSymbolName methodName = new JavaSymbolName("update"); final JavaType entity = info.childType; final JpaEntityMetadata entityMetadata = info.childEntityMetadata; final FieldMetadata entityIdentifier = entityMetadata.getCurrentIndentifierField(); final String entityItemName = StringUtils.uncapitalize(entity.getSimpleTypeName()); final ServiceMetadata serviceMetadata = controllerMetadata.getServiceMetadataForEntity(entity); parameterTypes.add(new AnnotatedJavaType(parentEntity, ANN_MODEL_ATTRIBUTE)); parameterTypes.add(new AnnotatedJavaType(entity, ANN_MODEL_ATTRIBUTE)); parameterTypes .add(new AnnotatedJavaType(entity, ANN_METADATA_VALID, ANN_METADATA_REQUEST_BODY)); parameterTypes.add(new AnnotatedJavaType(SpringJavaType.BINDING_RESULT)); final String storedName = "stored".concat(entity.getSimpleTypeName()); parameterNames.add(new JavaSymbolName( StringUtils.uncapitalize(parentEntity.getSimpleTypeName()))); parameterNames.add(new JavaSymbolName(storedName)); parameterNames.add(new JavaSymbolName(entityItemName)); parameterNames.add(new JavaSymbolName("result")); .getFieldName().getSymbolNameCapitalisedFirstLetter(), storedName, entityIdentifier .getFieldName().getSymbolNameCapitalisedFirstLetter()); getAccessorMethod(controllerMetadata.getLastDetailServiceField()).getMethodName(), serviceMetadata.getCurrentSaveMethod().getMethodName(), entityItemName);
.addConfigurationElement("referencedEntity", typeDetails.getType().getSimpleTypeName()); controller.getAnnotation(RooJavaType.ROO_CONTROLLER); AnnotationAttributeValue<String> prefixAttr = controllerAnnotation.getAttribute("pathPrefix"); if (StringUtils.equals(values.getPathPrefix(), controllerPrefix)) { getTypeLocationService().getTypeDetails(typeDetails.getType()); JpaEntityMetadata relatedEntityMetadata = getMetadataService().get(JpaEntityMetadata.createIdentifier(relatedEntityCid)); fieldItem.addConfigurationElement("identifierField", relatedEntityMetadata .getCurrentIndentifierField().getFieldName().getSymbolName()); break;
parameterTypes.add(new AnnotatedJavaType(this.entity, ANN_METADATA_VALID, ANN_METADATA_MODEL_ATTRIBUTE)); parameterTypes.add(new AnnotatedJavaType(SpringJavaType.BINDING_RESULT)); if (this.entityMetadata.getCurrentVersionField() != null) { AnnotationMetadataBuilder requestParamAnnotation = new AnnotationMetadataBuilder(REQUEST_PARAM); requestParamAnnotation.addStringAttribute("value", VERSION_PARAM_NAME.getSymbolName()); parameterTypes.add(new AnnotatedJavaType(this.entityMetadata.getCurrentVersionField() .getFieldType(), requestParamAnnotation.build())); parameterNames.add(new JavaSymbolName(entityItemName)); parameterNames.add(new JavaSymbolName("result")); if (this.entityMetadata.getCurrentVersionField() != null) { parameterNames.add(this.entityMetadata.getCurrentVersionField().getFieldName()); bodyBuilder.appendFormalLine("%s(model);", populateFormMethod.getMethodName()); getNameOfJavaType(SpringJavaType.MODEL_AND_VIEW), getEditViewPathMethod.getMethodName()); String savedVarName = "saved" + entity.getSimpleTypeName(); if (this.entityMetadata.getCurrentVersionField() != null) { getAccessorMethod(this.itemMethodLinkBuilderFactoryField).getMethodName(), getNameOfJavaType(relatedItemLinkFactory), this.entityItemName, savedVarName, getAccessorMethod(this.entityMetadata.getCurrentIndentifierField()).getMethodName());
final JavaSymbolName param0 = methodToBeImplemented.getParameterNames().get(0); Map<String, RelationInfo> relationInfos = entityMetadata.getRelationInfos(); for (Entry<String, RelationInfo> entry : relationInfos.entrySet()) { RelationInfo info = entry.getValue(); commentAdded = true; bodyBuilder.appendFormalLine("%s.%s(%s.get%s());", param0, info.addMethod.getMethodName(), param0, StringUtils.capitalize(entry.getKey())); bodyBuilder.newLine(); methodToBeImplemented.getReturnType().equals(JavaType.VOID_PRIMITIVE) ? "" : "return", getAccessorMethod(repositoryFieldMetadata).getMethodName(), methodToBeImplemented .getMethodName().getSymbolName(), param0); return bodyBuilder;
final JavaSymbolName param0 = methodToBeImplemented.getParameterNames().get(0); final JavaType childType = relationInfo.childType; final FieldMetadata childServideField = requiredServiceFieldByEntity.get(childType); final String childTypeNameJavaType = getNameOfJavaType(childType); final JavaSymbolName param1 = methodToBeImplemented.getParameterNames().get(1); final String saveMethod = serviceMetadata.getCurrentSaveMethod().getMethodName().getSymbolName(); getNameOfJavaType(relationInfo.fieldMetadata.getFieldType()), param0, relationInfo.fieldMetadata.getFieldName().getSymbolNameCapitalisedFirstLetter()); final String itemName = "next".concat(StringUtils.capitalize(childType.getSimpleTypeName())); if (this.entityMetadata.getCurrentVersionField() != null) {