diff --git a/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/undeploy/SmartFilesValidator.groovy b/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/undeploy/SmartFilesValidator.groovy index 6724f1e..756c718 100644 --- a/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/undeploy/SmartFilesValidator.groovy +++ b/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/undeploy/SmartFilesValidator.groovy @@ -132,8 +132,10 @@ class SmartFilesValidator { * Fills all folder supported to create queries */ private void fillFoldersSupported() { - QueryBuilder.defaultComponents.each { typeFile -> - foldersSupported.push(MetadataComponents.getDirectoryByName(typeFile)) + QueryBuilder.mapComponents.each { group, components -> + components.each { typeFile -> + foldersSupported.push(MetadataComponents.getDirectoryByName(typeFile)) + } } } diff --git a/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/utils/Util.groovy b/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/utils/Util.groovy index 092a60f..7a25c6c 100644 --- a/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/utils/Util.groovy +++ b/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/utils/Util.groovy @@ -41,7 +41,12 @@ class Util { * @return developerName of custom field */ public static String getDeveloperName(String fullName) { - return fullName.substring(fullName.indexOf('.') + 1, fullName.length() - 7) + int point1 = fullName.indexOf('.') + 1 + int point2 = fullName.indexOf("__c",point1) + if(point2 < 0) { + point2 = fullName.lastIndexOf('.') + } + return fullName.substring(point1, point2) } /** diff --git a/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/wsc/rest/QueryBuilder.groovy b/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/wsc/rest/QueryBuilder.groovy index ff8f9a5..ab23a26 100644 --- a/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/wsc/rest/QueryBuilder.groovy +++ b/src/main/groovy/org/fundacionjala/gradle/plugins/enforce/wsc/rest/QueryBuilder.groovy @@ -5,6 +5,7 @@ package org.fundacionjala.gradle.plugins.enforce.wsc.rest +import aQute.bnd.osgi.Clazz import com.sforce.soap.metadata.PackageTypeMembers import groovy.util.logging.Log import org.fundacionjala.gradle.plugins.enforce.utils.Constants @@ -21,12 +22,22 @@ class QueryBuilder { private final String SELECT_NAME = 'SELECT Name FROM' private final String SELECT_FULL_NAME = 'SELECT FullName FROM' private final String WHERE_NAME = 'WHERE Name =' - private final String WHERE_FULL_NAME = 'WHERE DeveloperName =' + private final String WHERE_DEVELOPER_NAME = 'WHERE DeveloperName =' + private final String WHERE_VALIDATION_NAME = 'WHERE ValidationName =' private final String THERE_IS_NOT_PACKAGE = "There isn't a package xml file in this path: " public static final ArrayList defaultComponents = ['ApexClass', 'ApexComponent', 'ApexPage', 'ApexTrigger', 'StaticResource', 'Profile', 'EmailTemplate'] - public static final ArrayList defaultSubComponents = ['CompactLayout'] + public static final ArrayList componentCompactLayout = ['CompactLayout'] + public static final ArrayList defaultSubComponents = ['CustomField', 'CompactLayout', 'RecordType','ValidationRule'] + public static final ArrayList validationRule = ['ValidationRule'] + + public static final Map> mapComponents = + [ + 'defaultComponent' : defaultComponents, + 'defaultSubComponent' : defaultSubComponents, + 'validationRule' : validationRule + ] /** * Gets queries of components from package xml file * @param packagePath is type String @@ -38,10 +49,10 @@ class QueryBuilder { } ArrayList queries = new ArrayList() getComponents(new FileReader(packagePath)).each { typeMembers -> - if(defaultSubComponents.contains(typeMembers.name)) { + if(componentCompactLayout.contains(typeMembers.name)) { typeMembers.members.each { member -> if (member != '*') { - queries.add("""${SELECT_FULL_NAME} ${typeMembers.name} ${WHERE_FULL_NAME} '${ + queries.add("""${SELECT_FULL_NAME} ${typeMembers.name} ${WHERE_DEVELOPER_NAME} '${ Util.getDeveloperNameByMember(member, typeMembers.name as String) }'""") } @@ -69,12 +80,17 @@ class QueryBuilder { String folderName = file.getParentFile().getName() MetadataComponents component = MetadataComponents.getComponentByPath(folderName) if (component && isDefaultComponent(component.getTypeName())) { - String query = component.getExtension() != 'sbc'? - """${SELECT_NAME} ${component.getTypeName()} ${WHERE_NAME} '${ - Util.getFileName(file.getName())}'""" : - """${SELECT_FULL_NAME} ${component.getTypeName()} ${WHERE_FULL_NAME} '${ - Util.getDeveloperName(file.getName()) - }'""" + String query = "" + + if(getGroupComponent(component.getTypeName()).equals("defaultComponent")) { + query = """${SELECT_NAME} ${component.getTypeName()} ${WHERE_NAME} '${Util.getFileName(file.getName())}'""" + } + else if(getGroupComponent(component.getTypeName()).equals("defaultSubComponent")) { + query = """${SELECT_FULL_NAME} ${component.getTypeName()} ${WHERE_DEVELOPER_NAME} '${Util.getDeveloperName(file.getName())}'""" + } + else if(getGroupComponent(component.getTypeName()).equals("validationRule")) { + query = """${SELECT_FULL_NAME} ${component.getTypeName()} ${WHERE_VALIDATION_NAME} '${Util.getDeveloperName(file.getName())}'""" + } queries.add(query) } else { invalidFolders.add(folderName) @@ -108,16 +124,30 @@ class QueryBuilder { } /** - * Verifies if a component is into default components + * Verifies if a component is into components map * @param component is type String * @return true if there is a component else false */ + public boolean isDefaultComponent(String component) { boolean result = false - for (String componentObtained in defaultComponents) { - if (componentObtained == component) { + mapComponents.each { group, components -> + if(components.contains(component)) { result = true - break + } + } + return result + } + + /** + * @param component is type String + * @return the group of component name + */ + public String getGroupComponent(String component) { + String result = "default" + mapComponents.each { group, components -> + if(components.contains(component)) { + result = group } } return result diff --git a/src/test/groovy/org/fundacionjala/gradle/plugins/enforce/wsc/rest/QueryBuilderTest.groovy b/src/test/groovy/org/fundacionjala/gradle/plugins/enforce/wsc/rest/QueryBuilderTest.groovy index 6639704..66b3f76 100644 --- a/src/test/groovy/org/fundacionjala/gradle/plugins/enforce/wsc/rest/QueryBuilderTest.groovy +++ b/src/test/groovy/org/fundacionjala/gradle/plugins/enforce/wsc/rest/QueryBuilderTest.groovy @@ -62,7 +62,7 @@ class QueryBuilderTest extends Specification { when: def queries = queryBuilder.createQueryFromPackage(packagePath) then: - queries.sort() == ['SELECT Name FROM ApexClass', 'SELECT Name FROM ApexComponent'].sort() + queries.sort() == ['SELECT Name FROM ApexClass', 'SELECT Name FROM ApexComponent', 'SELECT Name FROM CustomField'].sort() } def "Test should return an array with queries" () {