List of usage examples for org.apache.commons.lang3 StringUtils uncapitalize
public static String uncapitalize(final String str)
Uncapitalizes a String, changing the first letter to lower case as per Character#toLowerCase(char) .
From source file:com.neatresults.mgnltweaks.neatu2b.ui.form.field.U2BField.java
private TextField createTextField(String label, PropertysetItem newValue) { return createTextField(label, newValue, StringUtils.uncapitalize(label)); }
From source file:com.sap.research.connectivity.gw.GWOperationsUtils.java
public void addRemoteFieldInPersistenceMethods(JavaSourceFileEditor entityClassFile, Map.Entry<String[], String> fieldObj) { ArrayList<JavaSourceMethod> globalMethodList = entityClassFile.getGlobalMethodList(); String pluralRemoteEntity = GwUtils.getInflectorPlural(entityClassFile.CLASS_NAME, Locale.ENGLISH); String smallRemoteEntity = StringUtils.uncapitalize(entityClassFile.CLASS_NAME); for (JavaSourceMethod method : globalMethodList) { String methodName = method.getMethodName(); /*//from ww w .ja v a 2 s .c o m * We insert the new field in the persist and merge methods */ if (methodName.endsWith("persist") || methodName.endsWith("merge")) { StringBuffer methodBody = new StringBuffer(method.getMethodBody()); methodBody.insert(methodBody.lastIndexOf(".execute()"), makeGWPersistFieldCode("", fieldObj)); method.setMethodBody(methodBody.toString()); } /* * We insert the new field in the findAll and find<Entity>Entries methods */ else if (methodName.endsWith("findAll" + pluralRemoteEntity) || methodName.endsWith("find" + entityClassFile.CLASS_NAME + "Entries")) { StringBuffer methodBody = new StringBuffer(method.getMethodBody()); methodBody.insert(methodBody.indexOf("virtual" + entityClassFile.CLASS_NAME + "List.add"), makeGWShowFieldCode("", smallRemoteEntity + "Instance", smallRemoteEntity + "Item", fieldObj)); method.setMethodBody(methodBody.toString()); } /* * We insert the new field in the find<Entity> method */ else if (methodName.endsWith("find" + entityClassFile.CLASS_NAME)) { StringBuffer methodBody = new StringBuffer(method.getMethodBody()); methodBody.insert(methodBody.indexOf("return "), makeGWShowFieldCode("", "virtual" + entityClassFile.CLASS_NAME, smallRemoteEntity, fieldObj)); method.setMethodBody(methodBody.toString()); } } }
From source file:com.sap.research.connectivity.gw.GWOperationsUtils.java
public void addLocalFieldInPersistenceMethods(JavaSourceFileEditor entityClassFile, String fieldName, String fieldType) {//from w ww .jav a2s. c o m ArrayList<JavaSourceMethod> globalMethodList = entityClassFile.getGlobalMethodList(); String pluralRemoteEntity = GwUtils.getInflectorPlural(entityClassFile.CLASS_NAME, Locale.ENGLISH); String smallRemoteEntity = StringUtils.uncapitalize(entityClassFile.CLASS_NAME); for (JavaSourceMethod method : globalMethodList) { String methodName = method.getMethodName(); /* * We insert the new field in the findAll and find<Entity>Entries methods */ if (methodName.endsWith("findAll" + pluralRemoteEntity) || methodName.endsWith("find" + entityClassFile.CLASS_NAME + "Entries")) { StringBuffer methodBody = new StringBuffer(method.getMethodBody()); methodBody.insert(methodBody.indexOf("virtual" + entityClassFile.CLASS_NAME + "List.add"), makeLocalShowFieldCode("\t\t", smallRemoteEntity + "Instance", entityClassFile.CLASS_NAME, fieldName)); method.setMethodBody(methodBody.toString()); } /* NO NEED TO INSERT IN THE FIND METHOD ANYMORE AS ONCE FOUND IN THE LOCAL DB, THE LOCAL FIELDS ARE AUTOMATICALLY POPULATED * We insert the new field in the find<Entity> method * else if (methodName.endsWith("find" + entityClassFile.CLASS_NAME)) { StringBuffer methodBody = new StringBuffer(method.getMethodBody()); methodBody.insert(methodBody.indexOf("return "), makeLocalShowFieldCode("\t", "virtual" + entityClassFile.CLASS_NAME, entityClassFile.CLASS_NAME, fieldName)); method.setMethodBody(methodBody.toString()); }*/ } }
From source file:com.github.robozonky.notifications.SupportedListener.java
/** * Return ID of the listener. If listeners have the same ID, it means they share one namespace in configuration. * @return ID of the listener which will be used as namespace in the config file. *//* ww w. j av a2 s.co m*/ public String getLabel() { final String className = this.getEventType().getSimpleName(); final String decapitalized = StringUtils.uncapitalize(className); // this works because Event subclasses must be named (Something)Event; check Event(). return decapitalized.substring(0, decapitalized.length() - "Event".length()); }
From source file:com.sap.research.connectivity.gw.GWOperationsUtils.java
public String getCountMethodBody(String remoteEntity) { String smallRemoteEntity = StringUtils.uncapitalize(remoteEntity); String returnString = "\t\tOQueryRequest<OEntity> " + smallRemoteEntity + "List = " + GwUtils.GW_CONNECTION_FIELD_NAME + ".rooODataConsumer.getEntities(\"" + remoteEntity + "\");\n"; returnString += "\t\tint i = 0;\n"; returnString += "\t\tfor (OEntity " + smallRemoteEntity + "Item : " + smallRemoteEntity + "List) {\n"; returnString += "\t\t\ti++;\n"; returnString += "\t\t}\n"; returnString += "\t\treturn i;\n"; return returnString; }
From source file:com.sap.research.connectivity.gw.GWOperationsUtils.java
public String getFindMethodBody(Map<String[], String> fields, String remoteEntity) { String smallRemoteEntity = StringUtils.uncapitalize(remoteEntity); String returnString = "\t\tOEntity " + smallRemoteEntity + " = getRemote" + remoteEntity + "(Id);\n"; returnString += "\t\t" + remoteEntity + " virtual" + remoteEntity + " = entityManager().find(" + remoteEntity + ".class, " + GwUtils.GW_CONNECTION_FIELD_NAME + ".getDecodedRemoteKey(Id));\n"; returnString += "\t\tif (virtual" + remoteEntity + " == null)\n" + "\t\t\tvirtual" + remoteEntity + " = new " + remoteEntity + "();\n"; returnString += "\t\tDateTimeFormatter DTformatter = ISODateTimeFormat.dateHourMinuteSecondFraction();\n"; returnString += "\t\tDateTimeFormatter DTOformatter = ISODateTimeFormat.dateTime();\n"; for (Map.Entry<String[], String> field : fields.entrySet()) { returnString += makeGWShowFieldCode("\t\t", "virtual" + remoteEntity, smallRemoteEntity, field); }//w ww. j a v a 2s. c om //returnString += "\t\t" + "virtual" + remoteEntity + ".setId(" + DECODED_KEY + ");\n"; //returnString += "\t\t" + remoteEntity + " local" + remoteEntity + " = entityManager().find(" + remoteEntity + ".class, " + DECODED_KEY + ");\n"; returnString += "\t\ttry {\n" + "\t\t\t\n" + "\t\t} catch (Exception relationshipsException) {\n" + "\t\t\trelationshipsException.printStackTrace();\n" + "\t\t};\n"; returnString += "\t\treturn " + "virtual" + remoteEntity + ";\n"; return returnString; }
From source file:com.sap.research.connectivity.gw.GWOperationsUtils.java
public String getfindAllMethodBody(Map<String[], String> fields, Map<String[], String> keys, String remoteEntity) {//from w w w .j av a2 s . co m String smallRemoteEntity = StringUtils.uncapitalize(remoteEntity); String returnString = "\t\tOQueryRequest<OEntity> " + smallRemoteEntity + "List = " + GwUtils.GW_CONNECTION_FIELD_NAME + ".rooODataConsumer.getEntities(\"" + remoteEntity + "\");\n"; returnString += "\t\tList<" + remoteEntity + "> virtual" + remoteEntity + "List = " + "new ArrayList<" + remoteEntity + ">();\n"; returnString += "\t\tfor (OEntity " + smallRemoteEntity + "Item : " + smallRemoteEntity + "List) {\n"; returnString += "\t\t\t" + remoteEntity + " " + smallRemoteEntity + "Instance = new " + remoteEntity + "();\n"; returnString += "\t\t\tDateTimeFormatter DTformatter = ISODateTimeFormat.dateHourMinuteSecondFraction();\n"; returnString += "\t\t\tDateTimeFormatter DTOformatter = ISODateTimeFormat.dateTime();\n"; for (Map.Entry<String[], String> field : fields.entrySet()) { returnString += makeGWShowFieldCode("\t\t\t", smallRemoteEntity + "Instance", smallRemoteEntity + "Item", field); } String instance = smallRemoteEntity + "Instance"; returnString += generateEncodedKey(keys, 3, instance); returnString += "\t\t\tString " + DECODED_KEY + " = " + GwUtils.GW_CONNECTION_FIELD_NAME + ".getDecodedRemoteKey(" + ODATA_KEY + ".toKeyString());\n"; /* * Here we deal with the local part (e.g. fields, if any) * (the idea is that if we browse through a remote list of entities, then we might encounter some that have not been created using * the generated backend. So then we must first persist them (at least the id's) */ returnString += "\t\t\t" + remoteEntity + " local" + remoteEntity + " = entityManager().find(" + remoteEntity + ".class, " + DECODED_KEY + ");\n"; returnString += "\t\t\tif (local" + remoteEntity + " == null) {\n" + "\t\t\t\t" + remoteEntity + " tempLocal" + remoteEntity + " = new " + remoteEntity + "();\n" + "\t\t\t\ttempLocal" + remoteEntity + ".entityManager = entityManager();\n" + "\t\t\t\ttempLocal" + remoteEntity + ".setId(" + DECODED_KEY + ");\n" + "\t\t\t\ttempLocal" + remoteEntity + ".localPersist();\n" + "\t\t\t\tlocal" + remoteEntity + " = entityManager().find(" + remoteEntity + ".class, " + DECODED_KEY + ");\n" + "\t\t\t}\n"; returnString += "\t\t\ttry {\n" + "\t\t\t\t\n" + "\t\t\t} catch (Exception relationshipsException) {\n" + "\t\t\t\trelationshipsException.printStackTrace();\n" + "\t\t\t};\n"; returnString += "\t\t\tvirtual" + remoteEntity + "List.add(" + smallRemoteEntity + "Instance);\n"; returnString += "\t\t}\n"; returnString += "\n"; returnString += "\t\treturn " + "virtual" + remoteEntity + "List;\n"; return returnString; }
From source file:de.crowdcode.kissmda.cartridges.simplejava.InterfaceGenerator.java
/** * Generate method parameters.//from w w w . ja va 2 s . c o m * * @param ast * JDT AST tree * @param td * JDT type declaration * @param operation * UML2 operation * @param md * JDT method declaration */ public void generateMethodParams(AST ast, TypeDeclaration td, Operation operation, MethodDeclaration md) { EList<Parameter> parameters = operation.getOwnedParameters(); for (Parameter parameter : parameters) { if (parameter.getDirection().getValue() != ParameterDirectionKind.RETURN) { Type type = parameter.getType(); String umlTypeName = type.getName(); String umlQualifiedTypeName = type.getQualifiedName(); String umlPropertyName = StringUtils.uncapitalize(parameter.getName()); logger.log(Level.FINE, "Parameter: " + parameter.getName() + " - " + "Type: " + umlTypeName); if (parameter.getUpper() >= 0) { // Upper Cardinality 0..1 // Only for parameterized type if (dataTypeUtils.isParameterizedType(umlTypeName)) { Map<String, String> types = umlHelper .checkParameterizedTypeForTemplateParameterSubstitution(type); umlTypeName = types.get("umlTypeName"); umlQualifiedTypeName = types.get("umlQualifiedTypeName"); } jdtHelper.createParameterTypes(ast, td, md, umlTypeName, umlQualifiedTypeName, umlPropertyName, sourceDirectoryPackageName); } else { // Upper Cardinality 0..* generateAssociationEndUpperCardinalityMultiples(ast, td, parameter, md, umlTypeName, umlQualifiedTypeName, umlPropertyName); } } } }
From source file:com.sap.research.connectivity.gw.GWOperationsUtils.java
private void addRelationshipInPersistenceMethods(JavaSourceFileEditor entityClassFile, String nav, String javaType, String associationType) { // TODO Auto-generated method stub ArrayList<JavaSourceMethod> globalMethodList = entityClassFile.getGlobalMethodList(); String pluralRemoteEntity = GwUtils.getInflectorPlural(entityClassFile.CLASS_NAME, Locale.ENGLISH); String smallRemoteEntity = StringUtils.uncapitalize(entityClassFile.CLASS_NAME); for (JavaSourceMethod method : globalMethodList) { String methodName = method.getMethodName(); /*//from www . j av a 2 s.c o m * We insert the relation in the persist and merge methods */ if (methodName.endsWith("persist")) { StringBuffer methodBody = new StringBuffer(method.getMethodBody()); methodBody.insert(methodBody.lastIndexOf("newEntity = newEntityRequest"), makeGWPersistRelationshipCode(nav, javaType, associationType, "\t\t")); method.setMethodBody(methodBody.toString()); } else if (methodName.endsWith("merge")) { StringBuffer methodBody = new StringBuffer(method.getMethodBody()); methodBody.insert(methodBody.lastIndexOf("boolean modifyRequest = modifyEntityRequest"), makeGWMergeRelationshipCode(nav, javaType, associationType, "\t\t")); method.setMethodBody(methodBody.toString()); } /* * We insert the relation in the findAll and find<Entity>Entries methods */ else if (methodName.endsWith("findAll" + pluralRemoteEntity) || methodName.endsWith("find" + entityClassFile.CLASS_NAME + "Entries")) { StringBuffer methodBody = new StringBuffer(method.getMethodBody()); int insertPosition = methodBody.indexOf("} catch (Exception relationshipsException)"); boolean isFirstManyToMany = true; if ("OneToMany ManyToMany".contains(associationType)) { String manyToManyInsertReferenceString = StringUtils.uncapitalize(entityClassFile.CLASS_NAME) + "Link.isCollection()) {"; if (methodBody.indexOf(manyToManyInsertReferenceString) > -1) { insertPosition = methodBody.indexOf(manyToManyInsertReferenceString); isFirstManyToMany = false; } } methodBody.insert(insertPosition, makeGWShowRelationshipCode(entityClassFile.CLASS_NAME, smallRemoteEntity + "Instance", smallRemoteEntity + "Item", ODATA_KEY, nav, javaType, associationType, "\t\t", isFirstManyToMany)); method.setMethodBody(methodBody.toString()); } /* * We insert the relation in the find<Entity> method */ else if (methodName.endsWith("find" + entityClassFile.CLASS_NAME)) { StringBuffer methodBody = new StringBuffer(method.getMethodBody()); int insertPosition = methodBody.indexOf("} catch (Exception relationshipsException)"); boolean isFirstManyToMany = true; if ("OneToMany ManyToMany".contains(associationType)) { String manyToManyInsertReferenceString = StringUtils.uncapitalize(entityClassFile.CLASS_NAME) + "Link.isCollection()) {"; if (methodBody.indexOf(manyToManyInsertReferenceString) > -1) { insertPosition = methodBody.indexOf(manyToManyInsertReferenceString); isFirstManyToMany = false; } } methodBody.insert(insertPosition, makeGWShowRelationshipCode(entityClassFile.CLASS_NAME, "virtual" + entityClassFile.CLASS_NAME, smallRemoteEntity, "OEntityKey.parse(" + GwUtils.GW_CONNECTION_FIELD_NAME + ".getDecodedRemoteKey(Id))", nav, javaType, associationType, "\t\t\t", isFirstManyToMany)); method.setMethodBody(methodBody.toString()); } } }
From source file:com.sap.research.connectivity.gw.GWOperationsUtils.java
private String makeGWShowRelationshipCode(String className, String virtualLocalEntityInstance, String remoteEntity, String remoteId, String nav, String javaType, String associationType, String tabs, boolean isFirstManyToMany) { String smallClassName = StringUtils.uncapitalize(className); String capitalNav = StringUtils.capitalize(nav); String returnString = ""; if ("ManyToOne OneToOne".contains(associationType)) { returnString += "OEntity remote" + javaType + " = " + GwUtils.GW_CONNECTION_FIELD_NAME + ".rooODataConsumer.getEntity(\"" + className + "\", " + remoteId + ").nav(\"" + nav + "\").execute();\n"; returnString += tabs + javaType + " virtual" + javaType + " = " + javaType + ".find" + javaType + "(remote" + javaType + ".getEntityKey().toKeyString());\n"; returnString += tabs + virtualLocalEntityInstance + ".set" + javaType + "(virtual" + javaType + ");\n" + tabs;//from w w w .jav a 2 s .c o m } else { String extraReturn = ""; if (isFirstManyToMany) { returnString += "List<OLink> " + smallClassName + "Links = " + remoteEntity + ".getLinks();\n" + tabs + "\tfor(OLink " + smallClassName + "Link : " + smallClassName + "Links) {\n" + tabs + "\t\tif (" + smallClassName + "Link.isCollection()) {\n"; extraReturn = "\n"; } returnString += extraReturn + tabs + "\t\t\tif (" + smallClassName + "Link.getTitle().equals(\"" + nav + "\")) {\n" + tabs + "\t\t\t\tSet<" + javaType + "> virtual" + javaType + "List = new HashSet<" + javaType + ">();\n" + tabs + "\t\t\t\tList<OEntity> remote" + javaType + "List = " + GwUtils.GW_CONNECTION_FIELD_NAME + ".rooODataConsumer.getEntities(" + "OLinks.relatedEntities(" + smallClassName + "Link.getRelation(), " + smallClassName + "Link.getTitle(), " + smallClassName + "Link.getHref()))\n" + tabs + "\t\t\t\t.execute().toList();\n" + tabs + "\t\t\t\tfor (OEntity remote" + javaType + " : remote" + javaType + "List) {\n" + tabs + "\t\t\t\t\t" + javaType + " virtual" + javaType + " = " + javaType + ".find" + javaType + "(remote" + javaType + ".getEntityKey().toKeyString());\n" + tabs + "\t\t\t\t\tvirtual" + javaType + "List.add(virtual" + javaType + ");\n" + tabs + "\t\t\t\t}\n" + tabs + "\t\t\t\t" + virtualLocalEntityInstance + ".set" + capitalNav + "(virtual" + javaType + "List);\n" + tabs + "\t\t\t}\n"; if (isFirstManyToMany) returnString += tabs + "\t\t}\n" + tabs + "}\n" + tabs; } return returnString; }