#18576 spring cleanup of starter import / reindex error handling#18584
Conversation
| db.setSQL("select count(*) as test from inode"); | ||
| return new DotConnect() | ||
| .setSQL("select count(*) as test from inode") | ||
| .getInt("test")>0; |
There was a problem hiding this comment.
Nice I didn't know this one
|
|
||
|
|
||
|
|
||
| Try.run(() -> loadStarterSite()).getOrElseThrow(e->new DotRuntimeException(e)); |
There was a problem hiding this comment.
you can replace this (e->new DotRuntimeException(e));
by this
(DotRuntimeException::new);
Kinda fancy
| httpResponse.setHeader("Content-Disposition", "attachment; filename=" + zipFile.getName()); | ||
| } | ||
|
|
||
| try(final OutputStream outStream = (download) |
|
|
||
| public void executeStartUpTasks() throws DotDataException { | ||
|
|
||
| Logger.debug(this.getClass(), "Running Startup Tasks"); |
There was a problem hiding this comment.
I think it's redundant because there is a Logger.info just below with the same info
| boolean identityOn = false; | ||
| String cName = _className.substring(_className.lastIndexOf(".") + 1); | ||
| String tableName = ""; | ||
| if (classesWithIdentity.contains(cName) && DbConnectionFactory.isMsSql() && !cName.equalsIgnoreCase("inode")) { |
There was a problem hiding this comment.
| * @param out - Printwriter to write responses to Reponse Printwriter so this method can write to | ||
| * screen. | ||
| */ | ||
| private void doXMLFileImport(File f) throws Exception { |
There was a problem hiding this comment.
Issue found: Avoid variables with short names like f
| public Response indexList(@Context HttpServletRequest httpServletRequest, @Context final HttpServletResponse httpServletResponse, @PathParam("params") String params) { | ||
| try { | ||
| InitDataObject init = auth(params,httpServletRequest, httpServletResponse); | ||
| InitDataObject init = auth(httpServletRequest, httpServletResponse); |
There was a problem hiding this comment.
Issue found: Avoid unused local variables such as 'init'.
| } | ||
| } else if (_importClass.equals(User.class)) { | ||
| for (int j = 0; j < l.size(); j++) { | ||
| User u = (User) l.get(j); |
There was a problem hiding this comment.
Issue found: Avoid variables with short names like u
|
|
||
| if (_className.equals("Counter")) { | ||
| counter = true; | ||
| } else if (_className.equals("Image")) { |
There was a problem hiding this comment.
Issue found: Position literals first in String comparisons
| } | ||
|
|
||
| // updating file_type on folder now that structures were added | ||
| DotConnect dc = new DotConnect(); |
There was a problem hiding this comment.
Issue found: Avoid variables with short names like dc
| private final String oraCreate = "CREATE TABLE \"DB_VERSION\" ( \"DB_VERSION\" INTEGER NOT NULL , \"DATE_UPDATE\" TIMESTAMP NOT NULL, PRIMARY KEY (\"DB_VERSION\") )"; | ||
| private final String msCreate = "CREATE TABLE db_version ( db_version int NOT NULL , date_update datetime NOT NULL, PRIMARY KEY (db_version) )"; | ||
|
|
||
| private final String SELECT = "SELECT max(db_version) AS test FROM db_version"; |
There was a problem hiding this comment.
Issue found: This final field could be made static
| return true; | ||
| } | ||
| }); | ||
| } catch (Exception e) { |
There was a problem hiding this comment.
| final HashMap<String, String> dcResults = (HashMap<String, String>) l.get(j); | ||
|
|
||
| DotConnect dc = new DotConnect(); | ||
| StringBuffer sb = new StringBuffer("insert into portlet values (?,?,?,?,"); |
There was a problem hiding this comment.
Issue found: Avoid variables with short names like sb
| @Path("/reindex") | ||
| @Produces({MediaType.APPLICATION_JSON}) | ||
| public Response startReindex(@Context final HttpServletRequest request, @Context final HttpServletResponse response, | ||
| @QueryParam("shards") int shards, @DefaultValue(DOTALL) @QueryParam("contentType") String contentType) throws DotDataException, DotSecurityException { |
There was a problem hiding this comment.
Issue found: Avoid reassigning parameters such as 'shards'
|
|
||
| private final String createTableSQL() { | ||
|
|
||
| return (DbConnectionFactory.isPostgres()) |
| indexName = create(indexName, shards, live); | ||
| if(indexName == null) | ||
| indexName=ContentletIndexAPIImpl.timestampFormatter.format(new Date()); | ||
| indexName = (live) ? "live_" + indexName : "working_" + indexName; |
There was a problem hiding this comment.
| recordsToIndex = APILocator.getReindexQueueAPI().recordsInQueue(); | ||
| Logger.info(DotCMSInitDb.class, "Records left to index : " + recordsToIndex); | ||
| // ten minutes | ||
| if(++counter>30000) { |
There was a problem hiding this comment.
Issue found: Avoid assignments in operands
|
|
||
| // sorting folder identifiers by parent path in order to pass parent check | ||
| Collections.sort(folderIdents, new Comparator<Identifier>() { | ||
| public int compare(Identifier o1, Identifier o2) { |
There was a problem hiding this comment.
Issue found: Avoid variables with short names like o1
|
|
||
| DotConnect dc = new DotConnect(); | ||
| StringBuffer sb = new StringBuffer("insert into portlet values (?,?,?,?,"); | ||
| if (dcResults.get("narrow").equalsIgnoreCase("f") || dcResults.get("narrow").equalsIgnoreCase("false") |
There was a problem hiding this comment.
| counter = true; | ||
| } else if (_className.equals("Image")) { | ||
| image = true; | ||
| } else if (_className.equals("Portlet")) { |
There was a problem hiding this comment.
Issue found: Position literals first in String comparisons
| if (!this.validateZipFile()) { | ||
| throw new DotRuntimeException("starter data invalid"); | ||
| } | ||
| final File backTemporalFile = new File(getBackupTempFilePath()); |
There was a problem hiding this comment.
| */ | ||
| protected boolean hasReindexRecords() throws DotDataException { | ||
| DotConnect dc = new DotConnect(); | ||
| String sql = (DbConnectionFactory.isMsSql()) |
|
|
||
| } | ||
| @CloseDBIfOpened | ||
| private static void loadStarterSite() throws Exception{ |
There was a problem hiding this comment.
| if (filter != null) { | ||
| for (Object obj : all) | ||
| if (filter.includeIt(obj)) | ||
| l.add(obj); |
There was a problem hiding this comment.
Issue found: This statement should have braces
|
|
||
| private final String pgCreate = "CREATE TABLE db_version (db_version integer NOT NULL, date_update timestamp with time zone NOT NULL, CONSTRAINT db_version_pkey PRIMARY KEY (db_version));"; | ||
| private final String myCreate = "CREATE TABLE `db_version` (`db_version` INTEGER UNSIGNED NOT NULL,`date_update` DATETIME NOT NULL, PRIMARY KEY (`db_version`))"; | ||
| private final String oraCreate = "CREATE TABLE \"DB_VERSION\" ( \"DB_VERSION\" INTEGER NOT NULL , \"DATE_UPDATE\" TIMESTAMP NOT NULL, PRIMARY KEY (\"DB_VERSION\") )"; |
There was a problem hiding this comment.
Issue found: This final field could be made static
| Logger.info(this, "Importing:\t" + _className); | ||
|
|
||
|
|
||
| List l = new ArrayList(); |
There was a problem hiding this comment.
Issue found: Avoid variables with short names like l
| * The path where tmp files are stored. This gets wiped alot | ||
| */ | ||
| private String backupTempFilePath = ConfigUtils.getBackupPath() + File.separator + "temp"; | ||
| private ArrayList<String> classesWithIdentity = new ArrayList<String>(); |
There was a problem hiding this comment.
| //by an NCLOB field. In the case of dot_containers table, the second field, CODE, is an NCLOB field. Because of this, | ||
| //ordering is done only on the first field for the tables, which is INODE | ||
| if(com.dotmarketing.beans.Tree.class.equals(clazz)){ | ||
| _dh.setQuery("from " + clazz.getName() + " order by parent, child, relation_type"); |
There was a problem hiding this comment.
| import com.dotcms.content.elasticsearch.business.ContentletIndexAPIImpl; | ||
| import com.dotcms.content.elasticsearch.business.IndiciesInfo; | ||
| import com.dotmarketing.business.APILocator; | ||
| import com.dotmarketing.common.db.DotConnect; |
There was a problem hiding this comment.
This is a bit of housekeeping (not a rewrite) on how the starter is generated and how it is imported.
removed most of the broken db locking/transaction stuff from the StartupTasksExecutor and importing a starter is now transactional.
moved the Import and Export Utils to their own classes and renamed them
ImportStarterUtilandExportStarterUtilWhen serializing and deserializing objects as XML, I am using the
BundleUtilwhich handles writing XML 1.0 correctly.Heavy cleanup (though not a complete rewrite) on the ImportStarterUtil. It is better but there is risk that I might have been to aggressive and missed something.
I have starters and data sets that cannot be imported and/or reindexed without these changes. Reach out to me if you are looking to test one of them.