From 050a1fbb894a1ad539fb3a073bb91302df0486b6 Mon Sep 17 00:00:00 2001 From: devenyantis Date: Tue, 14 Sep 2021 21:56:32 +0800 Subject: [PATCH 01/16] :construction: WIP --- .../classifai/action/DeleteProjectData.java | 13 +- .../java/ai/classifai/database/DBUtils.java | 3 + .../database/portfolio/PortfolioDB.java | 241 +++++++----------- .../java/ai/classifai/router/V1Endpoint.java | 74 ++++-- .../java/ai/classifai/router/V2Endpoint.java | 76 +++--- .../classifai/util/message/ReplyHandler.java | 6 +- 6 files changed, 187 insertions(+), 226 deletions(-) diff --git a/classifai-core/src/main/java/ai/classifai/action/DeleteProjectData.java b/classifai-core/src/main/java/ai/classifai/action/DeleteProjectData.java index 60f2139e..291534a1 100644 --- a/classifai-core/src/main/java/ai/classifai/action/DeleteProjectData.java +++ b/classifai-core/src/main/java/ai/classifai/action/DeleteProjectData.java @@ -17,11 +17,8 @@ import ai.classifai.database.portfolio.PortfolioVerticle; import ai.classifai.loader.ProjectLoader; -import ai.classifai.util.ParamConfig; import ai.classifai.util.collection.ConversionHandler; -import ai.classifai.util.message.ReplyHandler; import io.vertx.core.json.JsonArray; -import io.vertx.core.json.JsonObject; import lombok.extern.slf4j.Slf4j; import java.io.IOException; @@ -39,7 +36,7 @@ private DeleteProjectData() { throw new IllegalStateException("Utility class"); } - public static JsonObject deleteProjectDataOnComplete(ProjectLoader loader, List deleteUUIDList, JsonArray deletedDataPath) throws IOException { + public static List deleteProjectDataOnComplete(ProjectLoader loader, List deleteUUIDList, JsonArray deletedDataPath) throws IOException { List dbUUIDList = loader.getUuidListFromDb(); List deletedDataPathList = ConversionHandler.jsonArray2StringList(deletedDataPath); if (dbUUIDList.removeAll(deleteUUIDList)) @@ -61,14 +58,10 @@ public static JsonObject deleteProjectDataOnComplete(ProjectLoader loader, List< //update Portfolio Verticle PortfolioVerticle.updateFileSystemUuidList(loader.getProjectId()); - JsonObject response = ReplyHandler.getOkReply(); - response.put(ParamConfig.getUuidListParam(), loader.getSanityUuidList()); - - return response; + return loader.getSanityUuidList(); } - return ReplyHandler.reportUserDefinedError( - "Failed to remove uuid from Portfolio Verticle. Project not expected to work fine"); + return null; } } diff --git a/classifai-core/src/main/java/ai/classifai/database/DBUtils.java b/classifai-core/src/main/java/ai/classifai/database/DBUtils.java index e3b41ac6..9becc194 100644 --- a/classifai-core/src/main/java/ai/classifai/database/DBUtils.java +++ b/classifai-core/src/main/java/ai/classifai/database/DBUtils.java @@ -79,4 +79,7 @@ public static Handler>> handleResponse(@NonNull Consumer }; } + public static Void toVoid(Object object) { + return null; + } } diff --git a/classifai-core/src/main/java/ai/classifai/database/portfolio/PortfolioDB.java b/classifai-core/src/main/java/ai/classifai/database/portfolio/PortfolioDB.java index 8dec0a47..a4aca4a6 100644 --- a/classifai-core/src/main/java/ai/classifai/database/portfolio/PortfolioDB.java +++ b/classifai-core/src/main/java/ai/classifai/database/portfolio/PortfolioDB.java @@ -82,21 +82,16 @@ private Future> runQuery(String query, Tuple params, JDBCPool pool) return promise.future(); } - public Future renameProject(String projectId, String newProjectName) { + public Future renameProject(String projectId, String newProjectName) { Tuple params = Tuple.of(newProjectName, projectId); - Promise promise = Promise.promise(); - runQuery(PortfolioDbQuery.getRenameProject(), params) - .onComplete(DBUtils.handleResponse( - result -> promise.complete(ReplyHandler.getOkReply()), - promise::fail - )); - return promise.future(); + return runQuery(PortfolioDbQuery.getRenameProject(), params) + .map(DBUtils::toVoid); } - public Future exportProject(String projectId, int exportType) { + public Future exportProject(String projectId, int exportType) { Tuple params = Tuple.of(projectId); - Promise promise = Promise.promise(); + Promise promise = Promise.promise(); runQuery(PortfolioDbQuery.getExportProject(), params) .onComplete(DBUtils.handleResponse( result -> { @@ -116,7 +111,7 @@ public Future exportProject(String projectId, int exportType) { fileGenerator.run(loader, configContent, exportType); } }); - promise.complete(ReplyHandler.getOkReply()); + promise.complete(); }, cause -> ProjectExport.setExportStatus(ProjectExport.ProjectExportStatus.EXPORT_FAIL) )); @@ -124,40 +119,32 @@ public Future exportProject(String projectId, int exportType) { return promise.future(); } - public Future deleteProjectData(String projectId, JsonArray uuidListArray, JsonArray uuidImgPathList) { + public Future> deleteProjectData(String projectId, JsonArray uuidListArray, JsonArray uuidImgPathList) { ProjectLoader loader = Objects.requireNonNull(ProjectHandler.getProjectLoader(projectId)); List deleteUUIDList = ConversionHandler.jsonArray2StringList(uuidListArray); String uuidQueryParam = String.join(",", deleteUUIDList); Tuple params = Tuple.of(projectId, uuidQueryParam); - Promise promise = Promise.promise(); - - runQuery(AnnotationQuery.getDeleteProjectData(), params, AnnotationHandler.getJDBCPool(loader)) - .onComplete(DBUtils.handleResponse( - result -> { - try { - JsonObject response = DeleteProjectData.deleteProjectDataOnComplete( - loader, deleteUUIDList, uuidImgPathList); - promise.complete(response); - } catch (IOException e) { - String errorMessage = "Fail to delete. IO exception occurs."; - log.info(errorMessage); - promise.fail(errorMessage); - } - }, - cause -> promise.fail("Delete project data fail") - )); - return promise.future(); + return runQuery(AnnotationQuery.getDeleteProjectData(), params, AnnotationHandler.getJDBCPool(loader)) + .map(result -> { + try { + return DeleteProjectData.deleteProjectDataOnComplete(loader, deleteUUIDList, uuidImgPathList); + } catch (IOException e) { + String errorMessage = "Fail to delete. IO exception occurs."; + log.info(errorMessage); + } + return null; + }); } - public Future renameData(String projectId, String uuid, String newFilename) { + public Future renameData(String projectId, String uuid, String newFilename) { ProjectLoader loader = Objects.requireNonNull(ProjectHandler.getProjectLoader(projectId)); RenameProjectData renameProjectData = new RenameProjectData(loader); renameProjectData.getAnnotationVersion(uuid); - Promise promise = Promise.promise(); + Promise promise = Promise.promise(); if(renameProjectData.containIllegalChars(newFilename)) { // Abort if filename contain illegal chars @@ -180,20 +167,12 @@ public Future renameData(String projectId, String uuid, String newFi if(renameProjectData.renameDataPath(newDataPath, renameProjectData.getOldDataFileName())) { - runQuery(AnnotationQuery.getRenameProjectData(), params, AnnotationHandler.getJDBCPool(loader)) - .onComplete(DBUtils.handleResponse( - result -> { - JsonObject response = ReplyHandler.getOkReply(); - response.put(ParamConfig.getImgPathParam(), newDataPath.toString()); - promise.complete(response); - }, - cause -> { - String queryErrorMes = "Fail to update filename in database"; - promise.fail(renameProjectData.reportRenameError( - RenameProjectData.RenameDataErrorCode.RENAME_FAIL.ordinal(), queryErrorMes).toString()); - } - )); - renameProjectData.updateAnnotationCache(updatedFileName, uuid); + + return runQuery(AnnotationQuery.getRenameProjectData(), params, AnnotationHandler.getJDBCPool(loader)) + .map(result -> { + renameProjectData.updateAnnotationCache(updatedFileName, uuid); + return newDataPath.toString(); + }); } else { @@ -205,24 +184,20 @@ public Future renameData(String projectId, String uuid, String newFi return promise.future(); } - public Future starProject(String projectId, Boolean isStarred) { + public Future starProject(String projectId, Boolean isStarred) { Tuple params = Tuple.of(isStarred, projectId); - Promise promise = Promise.promise(); - runQuery(PortfolioDbQuery.getStarProject(), params) - .onComplete(DBUtils.handleResponse( - result -> promise.complete(ReplyHandler.getOkReply()), - promise::fail - )); - return promise.future(); + + return runQuery(PortfolioDbQuery.getStarProject(), params) + .map(DBUtils::toVoid); } - public Future reloadProject(String projectId) { + public Future reloadProject(String projectId) { ProjectLoader loader = Objects.requireNonNull(ProjectHandler.getProjectLoader(projectId)); - Promise promise = Promise.promise(); + Promise promise = Promise.promise(); if(ImageHandler.loadProjectRootPath(loader)) { - promise.complete(ReplyHandler.getOkReply()); + promise.complete(); } else { promise.fail(ReplyHandler.getFailedReply().toString()); } @@ -230,43 +205,35 @@ public Future reloadProject(String projectId) { return promise.future(); } - public Future getProjectMetadata(String projectId) { + public Future> getProjectMetadata(String projectId) { - Promise promise = Promise.promise(); + Promise> promise = Promise.promise(); List result = new ArrayList<>(); PortfolioVerticle.getProjectMetadata(result, projectId); - JsonObject response = ReplyHandler.getOkReply() - .put(ParamConfig.getContent(), result); - promise.complete(response); + promise.complete(result); return promise.future(); } - public Future getAllProjectsMeta(int annotationType) { + public Future> getAllProjectsMeta(int annotationType) { Tuple params = Tuple.of(annotationType); - Promise promise = Promise.promise(); - runQuery(PortfolioDbQuery.getRetrieveAllProjectsForAnnotationType(), params) - .onComplete(DBUtils.handleResponse( - result -> { - List projectData = new ArrayList<>(); - for (Row row : result) - { - String projectName = row.getString(0); - PortfolioVerticle.getProjectMetadata(projectData, - ProjectHandler.getProjectId(projectName, annotationType)); - } - JsonObject response = ReplyHandler.getOkReply() - .put(ParamConfig.getContent(), projectData); - promise.complete(response); - }, - promise::fail - )); - return promise.future(); + + return runQuery(PortfolioDbQuery.getRetrieveAllProjectsForAnnotationType(), params) + .map(result -> { + List projectData = new ArrayList<>(); + for (Row row : result) + { + String projectName = row.getString(0); + PortfolioVerticle.getProjectMetadata(projectData, + ProjectHandler.getProjectId(projectName, annotationType)); + } + return projectData; + }); } - public Future loadProject(String projectId) { - Promise promise = Promise.promise(); + public Future loadProject(String projectId) { + Promise promise = Promise.promise(); ProjectLoader loader = Objects.requireNonNull(ProjectHandler.getProjectLoader(projectId)); List oriUUIDList = loader.getUuidListFromDb(); @@ -294,7 +261,7 @@ public Future loadProject(String projectId) { } loader.updateDBLoadingProgress(currentLength); if(!promise.future().isComplete()) { - promise.complete(ReplyHandler.getOkReply()); + promise.complete(); } }, promise::fail @@ -314,37 +281,33 @@ public Future getThumbnail(String projectId, String uuid) { return promise.future(); } - public Future getImageSource(String projectId, String uuid, String projectName) { + public Future getImageSource(String projectId, String uuid, String projectName) { Tuple params = Tuple.of(uuid, projectId); ProjectLoader loader = Objects.requireNonNull(ProjectHandler.getProjectLoader(projectId)); - Promise promise = Promise.promise(); - runQuery(AnnotationQuery.getRetrieveDataPath(), params, AnnotationHandler.getJDBCPool(loader)) - .onComplete(DBUtils.handleResponse( - result -> { - if (result.size() == 0) { - promise.fail("Failure to retrieve data path for " + projectName + " with uuid " + uuid); - } else { - JsonObject response = ReplyHandler.getOkReply(); - Row row = result.iterator().next(); - String dataPath = row.getString(0); - - if(loader.isCloud()) { - response.put(ParamConfig.getImgSrcParam(), - WasabiImageHandler.encodeFileToBase64Binary(loader.getWasabiProject(), dataPath)); - } else { - File fileImgPath = AnnotationVerticle.getDataFullPath(projectId, dataPath); - response.put(ParamConfig.getImgSrcParam(), ImageHandler.encodeFileToBase64Binary(fileImgPath)); - } - promise.complete(response); - } - }, - promise::fail - )); - return promise.future(); + + return runQuery(AnnotationQuery.getRetrieveDataPath(), params, AnnotationHandler.getJDBCPool(loader)) + .map(result -> { + if(result.size() != 0) { + String imageStr; + Row row = result.iterator().next(); + String dataPath = row.getString(0); + + if(loader.isCloud()) { + imageStr = WasabiImageHandler.encodeFileToBase64Binary(loader.getWasabiProject(), dataPath); + } else { + File fileImgPath = AnnotationVerticle.getDataFullPath(projectId, dataPath); + imageStr = ImageHandler.encodeFileToBase64Binary(fileImgPath); + } + return imageStr; + } + + log.info("Failure to retrieve data path for " + projectName + " with uuid " + uuid); + return null; + }); } - public Future updateData(JsonObject requestBody, String projectId) { - Promise promise = Promise.promise(); + public Future updateData(JsonObject requestBody, String projectId) { + Promise promise = Promise.promise(); try { String uuid = requestBody.getString(ParamConfig.getUuidParam()); @@ -381,11 +344,8 @@ public Future updateData(JsonObject requestBody, String projectId) { uuid, projectId); - runQuery(AnnotationQuery.getUpdateData(), params, AnnotationHandler.getJDBCPool(loader)) - .onComplete(DBUtils.handleResponse( - result -> promise.complete(ReplyHandler.getOkReply()), - promise::fail - )); + return runQuery(AnnotationQuery.getUpdateData(), params, AnnotationHandler.getJDBCPool(loader)) + .map(DBUtils::toVoid); } catch (Exception e) { @@ -396,23 +356,15 @@ public Future updateData(JsonObject requestBody, String projectId) { return promise.future(); } - public Future updateLastModifiedDate(String projectId, String dbFormat) { + public Future updateLastModifiedDate(String projectId, String dbFormat) { Tuple params = Tuple.of(dbFormat, projectId); - Promise promise = Promise.promise(); - runQuery(PortfolioDbQuery.getUpdateLastModifiedDate(), params) - .onComplete(DBUtils.handleResponse( - result -> promise.complete(ReplyHandler.getOkReply()), - cause -> { - log.info(cause.getMessage()); - promise.fail(cause); - } - )); - return promise.future(); + return runQuery(PortfolioDbQuery.getUpdateLastModifiedDate(), params) + .map(DBUtils::toVoid); } - public Future updateLabels(String projectId, JsonObject requestBody) { + public Future updateLabels(String projectId, JsonObject requestBody) { ProjectLoader loader = Objects.requireNonNull(ProjectHandler.getProjectLoader(projectId)); JsonArray newLabelListJson = requestBody.getJsonArray(ParamConfig.getLabelListParam()); ProjectVersion project = loader.getProjectVersion(); @@ -421,37 +373,22 @@ public Future updateLabels(String projectId, JsonObject requestBody) Tuple params = Tuple.of(project.getLabelVersionDbFormat(), projectId); - Promise promise = Promise.promise(); - runQuery(PortfolioDbQuery.getUpdateLabelList(), params) - .onComplete(DBUtils.handleResponse( - result -> promise.complete(ReplyHandler.getOkReply()), - promise::fail - )); - - return promise.future(); + return runQuery(PortfolioDbQuery.getUpdateLabelList(), params) + .map(DBUtils::toVoid); } - public Future deleteProjectFromPortfolioDb(String projectID) { + public Future deleteProjectFromPortfolioDb(String projectID) { Tuple params = Tuple.of(projectID); - Promise promise = Promise.promise(); - runQuery(PortfolioDbQuery.getDeleteProject(), params) - .onComplete(DBUtils.handleResponse( - result -> promise.complete(ReplyHandler.getOkReply()), - promise::fail - )); - return promise.future(); + return runQuery(PortfolioDbQuery.getDeleteProject(), params) + .map(DBUtils::toVoid); } - public Future deleteProjectFromAnnotationDb(String projectId) { + public Future deleteProjectFromAnnotationDb(String projectId) { ProjectLoader loader = Objects.requireNonNull(ProjectHandler.getProjectLoader(projectId)); Tuple params = Tuple.of(projectId); - Promise promise = Promise.promise(); - runQuery(AnnotationQuery.getDeleteProject(), params, AnnotationHandler.getJDBCPool(loader)) - .onComplete(DBUtils.handleResponse( - result -> promise.complete(ReplyHandler.getOkReply()), - promise::fail - )); - return promise.future(); + + return runQuery(AnnotationQuery.getDeleteProject(), params, AnnotationHandler.getJDBCPool(loader)) + .map(DBUtils::toVoid); } } diff --git a/classifai-core/src/main/java/ai/classifai/router/V1Endpoint.java b/classifai-core/src/main/java/ai/classifai/router/V1Endpoint.java index 7370cd3d..7fa792c1 100644 --- a/classifai-core/src/main/java/ai/classifai/router/V1Endpoint.java +++ b/classifai-core/src/main/java/ai/classifai/router/V1Endpoint.java @@ -26,7 +26,6 @@ import ai.classifai.util.project.ProjectHandler; import ai.classifai.util.type.AnnotationHandler; import ai.classifai.util.type.AnnotationType; -import io.vertx.core.Future; import io.vertx.core.json.JsonObject; import io.vertx.ext.web.RoutingContext; import lombok.Setter; @@ -61,8 +60,11 @@ public void getProjectMetadata(RoutingContext context) ProjectLoader loader = Objects.requireNonNull(ProjectHandler.getProjectLoader(projectName, type)); if(helper.checkIfProjectNull(context, loader, projectName)) return; - Future future = portfolioDB.getProjectMetadata(loader.getProjectId()); - ReplyHandler.sendResult(context, future, "Failed to retrieve metadata for project " + projectName); + portfolioDB.getProjectMetadata(loader.getProjectId()) + .onSuccess(result -> HTTPResponseHandler.configureOK(context, + ReplyHandler.getOkReply().put(ParamConfig.getContent(), result))) + .onFailure(cause -> HTTPResponseHandler.configureOK(context, + ReplyHandler.reportUserDefinedError("Failed to retrieve metadata for project " + projectName))); } /** @@ -74,8 +76,11 @@ public void getAllProjectsMeta(RoutingContext context) { AnnotationType type = AnnotationHandler.getTypeFromEndpoint(context.request().getParam(ParamConfig.getAnnotationTypeParam())); - Future future = portfolioDB.getAllProjectsMeta(type.ordinal()); - ReplyHandler.sendResult(context, future, "Failure in getting all the projects for " + type.name()); + portfolioDB.getAllProjectsMeta(type.ordinal()) + .onSuccess(result -> HTTPResponseHandler.configureOK(context, + ReplyHandler.getOkReply().put(ParamConfig.getContent(), result))) + .onFailure(cause -> HTTPResponseHandler.configureOK(context, + ReplyHandler.reportUserDefinedError("Failure in getting all the projects for " + type.name()))); } /** @@ -112,8 +117,10 @@ public void loadProject(RoutingContext context) if(projectLoaderStatus.equals(ProjectLoaderStatus.DID_NOT_INITIATED) || projectLoaderStatus.equals(ProjectLoaderStatus.LOADED)) { loader.setProjectLoaderStatus(ProjectLoaderStatus.LOADING); - Future future = portfolioDB.loadProject(loader.getProjectId()); - ReplyHandler.sendEmptyResult(context, future, "Failed to load project " + projectName + ". Check validity of data points failed."); + portfolioDB.loadProject(loader.getProjectId()) + .onComplete(result -> HTTPResponseHandler.configureOK(context)) + .onFailure(cause -> HTTPResponseHandler.configureOK(context, + ReplyHandler.reportUserDefinedError("Failed to load project " + projectName + ". Check validity of data points failed."))); } else if(projectLoaderStatus.equals(ProjectLoaderStatus.LOADING)) { @@ -194,8 +201,10 @@ public void getThumbnail(RoutingContext context) String projectID = ProjectHandler.getProjectId(projectName, type.ordinal()); String uuid = context.request().getParam(ParamConfig.getUuidParam()); - Future future = portfolioDB.getThumbnail(projectID, uuid); - ReplyHandler.sendResult(context, future, "Fail retrieving thumbnail"); + portfolioDB.getThumbnail(projectID, uuid) + .onSuccess(result -> HTTPResponseHandler.configureOK(context, result)) + .onFailure(cause -> HTTPResponseHandler.configureOK(context, + ReplyHandler.reportUserDefinedError("Fail retrieving thumbnail"))); } /*** @@ -213,8 +222,11 @@ public void getImageSource(RoutingContext context) String projectID = ProjectHandler.getProjectId(projectName, type.ordinal()); String uuid = context.request().getParam(ParamConfig.getUuidParam()); - Future future = portfolioDB.getImageSource(projectID, uuid, projectName); - ReplyHandler.sendResult(context, future, "Fail getting image source"); + portfolioDB.getImageSource(projectID, uuid, projectName) + .onSuccess(result -> HTTPResponseHandler.configureOK(context, + ReplyHandler.getOkReply().put(ParamConfig.getImgSrcParam(), result))) + .onFailure(cause -> HTTPResponseHandler.configureOK(context, + ReplyHandler.reportUserDefinedError("Fail getting image source"))); } /*** @@ -239,10 +251,13 @@ public void updateData(RoutingContext context) context.request().bodyHandler(handler -> { JsonObject requestBody = handler.toJsonObject(); - Future future = portfolioDB.updateData(requestBody, projectID); - ReplyHandler.sendResultRunSuccessSideEffect(context, future, - () -> updateLastModifiedDate(loader), - "Failure in updating database for " + type + " project: " + projectName); + portfolioDB.updateData(requestBody, projectID) + .onSuccess(result -> { + updateLastModifiedDate(loader); + HTTPResponseHandler.configureOK(context); + }) + .onFailure(cause -> HTTPResponseHandler.configureOK(context, + ReplyHandler.reportUserDefinedError("Failure in updating database for " + type + " project: " + projectName))); }); } @@ -254,12 +269,8 @@ private void updateLastModifiedDate(ProjectLoader loader) version.setLastModifiedDate(new DateTime()); - Future future = portfolioDB.updateLastModifiedDate(projectID, version.getDbFormat()); - future.onComplete(result -> { - if(result.failed()) { - log.info("Databse update fail. Type: " + loader.getAnnotationType() + " Project: " + loader.getProjectName()); - } - }); + portfolioDB.updateLastModifiedDate(projectID, version.getDbFormat()) + .onFailure(cause -> log.info("Databse update fail. Type: " + loader.getAnnotationType() + " Project: " + loader.getProjectName())); } @@ -282,8 +293,11 @@ public void updateLabels(RoutingContext context) context.request().bodyHandler(handlers -> { JsonObject requestBody = handlers.toJsonObject(); - Future future = portfolioDB.updateLabels(projectID, requestBody); - ReplyHandler.sendResult(context, future, "Fail to update labels: " + projectName); + + portfolioDB.updateLabels(projectID, requestBody) + .onSuccess(result -> HTTPResponseHandler.configureOK(context)) + .onFailure(cause -> HTTPResponseHandler.configureOK(context, + ReplyHandler.reportUserDefinedError("Fail to update labels: " + projectName))); }); } @@ -308,11 +322,15 @@ public void deleteProject(RoutingContext context) String errorMessage = "Failure in delete project name: " + projectName + " for " + type.name(); - Future future = portfolioDB.deleteProjectFromPortfolioDb(projectID) - .compose(response -> portfolioDB.deleteProjectFromAnnotationDb(projectID)); - ReplyHandler.sendResultRunSuccessSideEffect(context, future, - () -> ProjectHandler.deleteProjectFromCache(projectID), - errorMessage); + + portfolioDB.deleteProjectFromPortfolioDb(projectID) + .compose(result -> portfolioDB.deleteProjectFromAnnotationDb(projectID)) + .onSuccess(result -> { + ProjectHandler.deleteProjectFromCache(projectID); + HTTPResponseHandler.configureOK(context); + }) + .onFailure(cause -> HTTPResponseHandler.configureOK(context, + ReplyHandler.reportUserDefinedError(errorMessage))); } } diff --git a/classifai-core/src/main/java/ai/classifai/router/V2Endpoint.java b/classifai-core/src/main/java/ai/classifai/router/V2Endpoint.java index e5757f50..a5cfbd0e 100644 --- a/classifai-core/src/main/java/ai/classifai/router/V2Endpoint.java +++ b/classifai-core/src/main/java/ai/classifai/router/V2Endpoint.java @@ -36,7 +36,7 @@ import ai.classifai.util.project.ProjectInfra; import ai.classifai.util.type.AnnotationHandler; import ai.classifai.util.type.AnnotationType; -import io.vertx.core.Future; +import io.vertx.core.json.JsonArray; import io.vertx.core.json.JsonObject; import io.vertx.ext.web.RoutingContext; import lombok.Setter; @@ -119,13 +119,14 @@ public void starProject(RoutingContext context) context.request().bodyHandler(handler -> { JsonObject request = handler.toJsonObject(); Boolean isStarred = Boolean.parseBoolean(request.getString(ParamConfig.getStatusParam())); - Future future = portfolioDB.starProject(projectID, isStarred); - ReplyHandler.sendResultRunSuccessSideEffect(context, future, - ()-> { + portfolioDB.starProject(projectID, isStarred) + .onSuccess(result -> { ProjectLoader loader = Objects.requireNonNull(ProjectHandler.getProjectLoader(projectID)); loader.setIsProjectStarred(isStarred); - }, - "Star project fail"); + HTTPResponseHandler.configureOK(context, ReplyHandler.getOkReply()); + }) + .onFailure(cause -> HTTPResponseHandler.configureOK(context, + ReplyHandler.reportUserDefinedError("Star project fail"))); }); } @@ -283,12 +284,15 @@ public void renameProject(RoutingContext context) if(ProjectHandler.checkValidProjectRename(newProjectName, type.ordinal())) { - Future future = portfolioDB.renameProject(loader.getProjectId(), newProjectName); - ReplyHandler.sendEmptyResult(context, future, () -> { - loader.setProjectName(newProjectName); - ProjectHandler.updateProjectNameInCache(loader.getProjectId(), loader, projectName); - log.debug("Rename to " + newProjectName + " success."); - }, "Failed to rename project " + projectName); + portfolioDB.renameProject(loader.getProjectId(), newProjectName) + .onSuccess(result -> { + loader.setProjectName(newProjectName); + ProjectHandler.updateProjectNameInCache(loader.getProjectId(), loader, projectName); + log.debug("Rename to " + newProjectName + " success."); + HTTPResponseHandler.configureOK(context); + }) + .onFailure(cause -> HTTPResponseHandler.configureOK(context, + ReplyHandler.reportUserDefinedError("Failed to rename project " + projectName))); } else { @@ -318,8 +322,10 @@ public void reloadProject(RoutingContext context) loader.setFileSystemStatus(FileSystemStatus.ITERATING_FOLDER); - Future future = portfolioDB.reloadProject(loader.getProjectId()); - ReplyHandler.sendEmptyResult(context, future, "Failed to reload project " + projectName); + portfolioDB.reloadProject(loader.getProjectId()) + .onSuccess(result -> HTTPResponseHandler.configureOK(context)) + .onFailure(cause -> HTTPResponseHandler.configureOK(context, + ReplyHandler.reportUserDefinedError("Failed to reload project " + projectName))); } /** @@ -376,10 +382,13 @@ public void exportProject(RoutingContext context) context.request().getParam(ActionConfig.getExportTypeParam())); if(exportType.equals(ActionConfig.ExportType.INVALID_CONFIG)) return; - Future future = portfolioDB.exportProject(projectId, exportType.ordinal()); - ReplyHandler.sendResultRunFailSideEffect(context, future, - () -> ProjectExport.setExportStatus(ProjectExport.ProjectExportStatus.EXPORT_FAIL), - "Export of project failed for " + projectName); + portfolioDB.exportProject(projectId, exportType.ordinal()) + .onSuccess(result -> HTTPResponseHandler.configureOK(context, ReplyHandler.getOkReply())) + .onFailure(cause -> { + ProjectExport.setExportStatus(ProjectExport.ProjectExportStatus.EXPORT_FAIL); + HTTPResponseHandler.configureOK(context, + ReplyHandler.reportUserDefinedError("Export of project failed for " + projectName)); + }); } /** @@ -566,13 +575,14 @@ public void deleteProjectData(RoutingContext context) context.request().bodyHandler(handler -> { JsonObject request = Objects.requireNonNull(ConversionHandler.json2JSONObject(handler.toJson())); - - Future future = portfolioDB.deleteProjectData( - projectID, - request.getJsonArray(ParamConfig.getUuidListParam()), - request.getJsonArray(ParamConfig.getImgPathListParam()) - ); - ReplyHandler.sendResult(context, future, "Delete project data fail."); + JsonArray uuidListArray = request.getJsonArray(ParamConfig.getUuidListParam()); + JsonArray uuidImgPathList = request.getJsonArray(ParamConfig.getImgPathListParam()); + + portfolioDB.deleteProjectData(projectID, uuidListArray, uuidImgPathList) + .onSuccess(result -> HTTPResponseHandler.configureOK(context, + ReplyHandler.getOkReply().put(ParamConfig.getUuidListParam(), result))) + .onFailure(cause -> HTTPResponseHandler.configureOK(context, + ReplyHandler.reportUserDefinedError("Delete project data fail"))); }); } @@ -599,14 +609,14 @@ public void renameData(RoutingContext context) context.request().bodyHandler(handler -> { JsonObject request = Objects.requireNonNull(ConversionHandler.json2JSONObject(handler.toJson())); - - Future future = portfolioDB.renameData( - projectId, - request.getString(ParamConfig.getUuidParam()), - request.getString(ParamConfig.getNewFileNameParam()) - ); - - ReplyHandler.sendResult(context, future, "Rename data fail"); + String uuid = request.getString(ParamConfig.getUuidParam()); + String newFilename = request.getString(ParamConfig.getNewFileNameParam()); + + portfolioDB.renameData(projectId, uuid, newFilename) + .onSuccess(result -> HTTPResponseHandler.configureOK(context, + ReplyHandler.getOkReply().put(ParamConfig.getImgPathParam(), result))) + .onFailure(cause -> HTTPResponseHandler.configureOK(context, + ReplyHandler.reportUserDefinedError("Rename data fail"))); }); } } diff --git a/classifai-core/src/main/java/ai/classifai/util/message/ReplyHandler.java b/classifai-core/src/main/java/ai/classifai/util/message/ReplyHandler.java index 151b4755..d9c15095 100644 --- a/classifai-core/src/main/java/ai/classifai/util/message/ReplyHandler.java +++ b/classifai-core/src/main/java/ai/classifai/util/message/ReplyHandler.java @@ -77,7 +77,7 @@ public static void sendEmptyResult(RoutingContext context, Future fu }); } - public static void sendEmptyResult(RoutingContext context, Future future, Runnable successSideEffect, + public static void sendEmptyResult(RoutingContext context, Future future, Runnable successSideEffect, String errorMessage) { future.onComplete(result -> { if(result.succeeded()) { @@ -111,11 +111,11 @@ public static void sendResultRunSuccessSideEffect(RoutingContext context, Future }); } - public static void sendResultRunFailSideEffect(RoutingContext context, Future future, + public static void sendResultRunFailSideEffect(RoutingContext context, Future future, Runnable failSideEffect, String errorMessage) { future.onComplete(result -> { if(result.succeeded()) { - HTTPResponseHandler.configureOK(context, result.result()); + HTTPResponseHandler.configureOK(context, ReplyHandler.getOkReply()); } else { failSideEffect.run(); HTTPResponseHandler.configureOK(context, ReplyHandler.reportUserDefinedError(errorMessage)); From 6548beaeeb791cbc7d6ec730098bf05f21b6ac6b Mon Sep 17 00:00:00 2001 From: devenyantis Date: Wed, 15 Sep 2021 10:33:24 +0800 Subject: [PATCH 02/16] :recycle: Remove JsonObject from return type --- .../classifai/database/portfolio/PortfolioDB.java | 11 +++++------ .../main/java/ai/classifai/router/V1Endpoint.java | 14 ++++++-------- .../main/java/ai/classifai/router/V2Endpoint.java | 14 +++++++------- .../ai/classifai/util/message/ReplyHandler.java | 2 +- 4 files changed, 19 insertions(+), 22 deletions(-) diff --git a/classifai-core/src/main/java/ai/classifai/database/portfolio/PortfolioDB.java b/classifai-core/src/main/java/ai/classifai/database/portfolio/PortfolioDB.java index a4aca4a6..5a8516cd 100644 --- a/classifai-core/src/main/java/ai/classifai/database/portfolio/PortfolioDB.java +++ b/classifai-core/src/main/java/ai/classifai/database/portfolio/PortfolioDB.java @@ -131,10 +131,9 @@ public Future> deleteProjectData(String projectId, JsonArray uuidLi try { return DeleteProjectData.deleteProjectDataOnComplete(loader, deleteUUIDList, uuidImgPathList); } catch (IOException e) { - String errorMessage = "Fail to delete. IO exception occurs."; - log.info(errorMessage); + log.info("Fail to delete. IO exception occurs."); } - return null; + return loader.getSanityUuidList(); }); } @@ -174,9 +173,9 @@ public Future renameData(String projectId, String uuid, String newFilena return newDataPath.toString(); }); } - else - { - String failRenameMes = "Fail to rename file"; + + String failRenameMes = "Fail to rename file"; + if(!promise.future().isComplete()) { promise.fail(renameProjectData.reportRenameError( RenameProjectData.RenameDataErrorCode.RENAME_FAIL.ordinal(), failRenameMes).toString()); } diff --git a/classifai-core/src/main/java/ai/classifai/router/V1Endpoint.java b/classifai-core/src/main/java/ai/classifai/router/V1Endpoint.java index 7fa792c1..81cd8cfa 100644 --- a/classifai-core/src/main/java/ai/classifai/router/V1Endpoint.java +++ b/classifai-core/src/main/java/ai/classifai/router/V1Endpoint.java @@ -26,6 +26,7 @@ import ai.classifai.util.project.ProjectHandler; import ai.classifai.util.type.AnnotationHandler; import ai.classifai.util.type.AnnotationType; +import io.vertx.core.Future; import io.vertx.core.json.JsonObject; import io.vertx.ext.web.RoutingContext; import lombok.Setter; @@ -117,10 +118,9 @@ public void loadProject(RoutingContext context) if(projectLoaderStatus.equals(ProjectLoaderStatus.DID_NOT_INITIATED) || projectLoaderStatus.equals(ProjectLoaderStatus.LOADED)) { loader.setProjectLoaderStatus(ProjectLoaderStatus.LOADING); - portfolioDB.loadProject(loader.getProjectId()) - .onComplete(result -> HTTPResponseHandler.configureOK(context)) - .onFailure(cause -> HTTPResponseHandler.configureOK(context, - ReplyHandler.reportUserDefinedError("Failed to load project " + projectName + ". Check validity of data points failed."))); + Future future = portfolioDB.loadProject(loader.getProjectId()); + ReplyHandler.sendEmptyResult(context, future, + "Failed to load project " + projectName + ". Check validity of data points failed."); } else if(projectLoaderStatus.equals(ProjectLoaderStatus.LOADING)) { @@ -294,10 +294,8 @@ public void updateLabels(RoutingContext context) context.request().bodyHandler(handlers -> { JsonObject requestBody = handlers.toJsonObject(); - portfolioDB.updateLabels(projectID, requestBody) - .onSuccess(result -> HTTPResponseHandler.configureOK(context)) - .onFailure(cause -> HTTPResponseHandler.configureOK(context, - ReplyHandler.reportUserDefinedError("Fail to update labels: " + projectName))); + Future future = portfolioDB.updateLabels(projectID, requestBody); + ReplyHandler.sendEmptyResult(context, future, "Fail to update labels: " + projectName); }); } diff --git a/classifai-core/src/main/java/ai/classifai/router/V2Endpoint.java b/classifai-core/src/main/java/ai/classifai/router/V2Endpoint.java index a5cfbd0e..1f95c5b1 100644 --- a/classifai-core/src/main/java/ai/classifai/router/V2Endpoint.java +++ b/classifai-core/src/main/java/ai/classifai/router/V2Endpoint.java @@ -36,6 +36,7 @@ import ai.classifai.util.project.ProjectInfra; import ai.classifai.util.type.AnnotationHandler; import ai.classifai.util.type.AnnotationType; +import io.vertx.core.Future; import io.vertx.core.json.JsonArray; import io.vertx.core.json.JsonObject; import io.vertx.ext.web.RoutingContext; @@ -322,10 +323,8 @@ public void reloadProject(RoutingContext context) loader.setFileSystemStatus(FileSystemStatus.ITERATING_FOLDER); - portfolioDB.reloadProject(loader.getProjectId()) - .onSuccess(result -> HTTPResponseHandler.configureOK(context)) - .onFailure(cause -> HTTPResponseHandler.configureOK(context, - ReplyHandler.reportUserDefinedError("Failed to reload project " + projectName))); + Future future = portfolioDB.reloadProject(loader.getProjectId()); + ReplyHandler.sendEmptyResult(context, future, "Failed to reload project " + projectName); } /** @@ -383,7 +382,7 @@ public void exportProject(RoutingContext context) if(exportType.equals(ActionConfig.ExportType.INVALID_CONFIG)) return; portfolioDB.exportProject(projectId, exportType.ordinal()) - .onSuccess(result -> HTTPResponseHandler.configureOK(context, ReplyHandler.getOkReply())) + .onSuccess(result -> HTTPResponseHandler.configureOK(context)) .onFailure(cause -> { ProjectExport.setExportStatus(ProjectExport.ProjectExportStatus.EXPORT_FAIL); HTTPResponseHandler.configureOK(context, @@ -615,8 +614,9 @@ public void renameData(RoutingContext context) portfolioDB.renameData(projectId, uuid, newFilename) .onSuccess(result -> HTTPResponseHandler.configureOK(context, ReplyHandler.getOkReply().put(ParamConfig.getImgPathParam(), result))) - .onFailure(cause -> HTTPResponseHandler.configureOK(context, - ReplyHandler.reportUserDefinedError("Rename data fail"))); + .onFailure(cause -> { + HTTPResponseHandler.configureOK(context, new JsonObject(cause.getMessage())); + }); }); } } diff --git a/classifai-core/src/main/java/ai/classifai/util/message/ReplyHandler.java b/classifai-core/src/main/java/ai/classifai/util/message/ReplyHandler.java index d9c15095..15dc65c6 100644 --- a/classifai-core/src/main/java/ai/classifai/util/message/ReplyHandler.java +++ b/classifai-core/src/main/java/ai/classifai/util/message/ReplyHandler.java @@ -67,7 +67,7 @@ public static JsonObject getFailedReply() return new JsonObject().put(MESSAGE_KEY, FAILED); } - public static void sendEmptyResult(RoutingContext context, Future future, String errorMessage) { + public static void sendEmptyResult(RoutingContext context, Future future, String errorMessage) { future.onComplete(result -> { if(result.succeeded()) { HTTPResponseHandler.configureOK(context); From 9ee05159d6f043b1ec1445430903b83d11229b25 Mon Sep 17 00:00:00 2001 From: devenyantis Date: Wed, 15 Sep 2021 10:44:05 +0800 Subject: [PATCH 03/16] :recycle: Fix code smell --- .../src/main/java/ai/classifai/action/DeleteProjectData.java | 2 +- .../src/main/java/ai/classifai/router/V2Endpoint.java | 4 +--- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/classifai-core/src/main/java/ai/classifai/action/DeleteProjectData.java b/classifai-core/src/main/java/ai/classifai/action/DeleteProjectData.java index 291534a1..15956802 100644 --- a/classifai-core/src/main/java/ai/classifai/action/DeleteProjectData.java +++ b/classifai-core/src/main/java/ai/classifai/action/DeleteProjectData.java @@ -61,7 +61,7 @@ public static List deleteProjectDataOnComplete(ProjectLoader loader, Lis return loader.getSanityUuidList(); } - return null; + return loader.getSanityUuidList(); } } diff --git a/classifai-core/src/main/java/ai/classifai/router/V2Endpoint.java b/classifai-core/src/main/java/ai/classifai/router/V2Endpoint.java index 1f95c5b1..cff4e4ec 100644 --- a/classifai-core/src/main/java/ai/classifai/router/V2Endpoint.java +++ b/classifai-core/src/main/java/ai/classifai/router/V2Endpoint.java @@ -614,9 +614,7 @@ public void renameData(RoutingContext context) portfolioDB.renameData(projectId, uuid, newFilename) .onSuccess(result -> HTTPResponseHandler.configureOK(context, ReplyHandler.getOkReply().put(ParamConfig.getImgPathParam(), result))) - .onFailure(cause -> { - HTTPResponseHandler.configureOK(context, new JsonObject(cause.getMessage())); - }); + .onFailure(cause -> HTTPResponseHandler.configureOK(context, new JsonObject(cause.getMessage()))); }); } } From a758f4c02194c3e5cfc591e5c86fa171a46a6b05 Mon Sep 17 00:00:00 2001 From: devenyantis Date: Fri, 17 Sep 2021 17:27:19 +0800 Subject: [PATCH 04/16] :construction: WIP --- classifai-core/pom.xml | 4 + .../classifai/action/DeleteProjectData.java | 7 +- .../database/portfolio/PortfolioDB.java | 22 ++--- .../database/portfolio/PortfolioVerticle.java | 95 +++++++++++-------- .../java/ai/classifai/dto/ProjectMeta.java | 47 +++++++++ .../main/java/ai/classifai/dto/Thumbnail.java | 50 ++++++++++ .../java/ai/classifai/router/V1Endpoint.java | 12 ++- .../java/ai/classifai/router/V2Endpoint.java | 5 +- pom.xml | 6 ++ 9 files changed, 189 insertions(+), 59 deletions(-) create mode 100644 classifai-core/src/main/java/ai/classifai/dto/ProjectMeta.java create mode 100644 classifai-core/src/main/java/ai/classifai/dto/Thumbnail.java diff --git a/classifai-core/pom.xml b/classifai-core/pom.xml index 7d83783b..cfdf197d 100644 --- a/classifai-core/pom.xml +++ b/classifai-core/pom.xml @@ -120,6 +120,10 @@ org.openpnp opencv + + com.fasterxml.jackson.core + jackson-core + diff --git a/classifai-core/src/main/java/ai/classifai/action/DeleteProjectData.java b/classifai-core/src/main/java/ai/classifai/action/DeleteProjectData.java index 15956802..7182bfda 100644 --- a/classifai-core/src/main/java/ai/classifai/action/DeleteProjectData.java +++ b/classifai-core/src/main/java/ai/classifai/action/DeleteProjectData.java @@ -17,8 +17,6 @@ import ai.classifai.database.portfolio.PortfolioVerticle; import ai.classifai.loader.ProjectLoader; -import ai.classifai.util.collection.ConversionHandler; -import io.vertx.core.json.JsonArray; import lombok.extern.slf4j.Slf4j; import java.io.IOException; @@ -36,9 +34,9 @@ private DeleteProjectData() { throw new IllegalStateException("Utility class"); } - public static List deleteProjectDataOnComplete(ProjectLoader loader, List deleteUUIDList, JsonArray deletedDataPath) throws IOException { + public static List deleteProjectDataOnComplete(ProjectLoader loader, List deleteUUIDList, + List deletedDataPathList) throws IOException { List dbUUIDList = loader.getUuidListFromDb(); - List deletedDataPathList = ConversionHandler.jsonArray2StringList(deletedDataPath); if (dbUUIDList.removeAll(deleteUUIDList)) { loader.setUuidListFromDb(dbUUIDList); @@ -58,7 +56,6 @@ public static List deleteProjectDataOnComplete(ProjectLoader loader, Lis //update Portfolio Verticle PortfolioVerticle.updateFileSystemUuidList(loader.getProjectId()); - return loader.getSanityUuidList(); } return loader.getSanityUuidList(); diff --git a/classifai-core/src/main/java/ai/classifai/database/portfolio/PortfolioDB.java b/classifai-core/src/main/java/ai/classifai/database/portfolio/PortfolioDB.java index 5a8516cd..3df54964 100644 --- a/classifai-core/src/main/java/ai/classifai/database/portfolio/PortfolioDB.java +++ b/classifai-core/src/main/java/ai/classifai/database/portfolio/PortfolioDB.java @@ -25,6 +25,8 @@ import ai.classifai.database.versioning.Annotation; import ai.classifai.database.versioning.AnnotationVersion; import ai.classifai.database.versioning.ProjectVersion; +import ai.classifai.dto.ProjectMeta; +import ai.classifai.dto.Thumbnail; import ai.classifai.loader.ProjectLoader; import ai.classifai.util.ParamConfig; import ai.classifai.util.collection.ConversionHandler; @@ -35,7 +37,6 @@ import ai.classifai.wasabis3.WasabiImageHandler; import io.vertx.core.Future; import io.vertx.core.Promise; -import io.vertx.core.json.JsonArray; import io.vertx.core.json.JsonObject; import io.vertx.jdbcclient.JDBCPool; import io.vertx.sqlclient.Row; @@ -119,9 +120,8 @@ public Future exportProject(String projectId, int exportType) { return promise.future(); } - public Future> deleteProjectData(String projectId, JsonArray uuidListArray, JsonArray uuidImgPathList) { + public Future> deleteProjectData(String projectId, List deleteUUIDList, List uuidImgPathList) { ProjectLoader loader = Objects.requireNonNull(ProjectHandler.getProjectLoader(projectId)); - List deleteUUIDList = ConversionHandler.jsonArray2StringList(uuidListArray); String uuidQueryParam = String.join(",", deleteUUIDList); Tuple params = Tuple.of(projectId, uuidQueryParam); @@ -204,10 +204,10 @@ public Future reloadProject(String projectId) { return promise.future(); } - public Future> getProjectMetadata(String projectId) { + public Future> getProjectMetadata(String projectId) { - Promise> promise = Promise.promise(); - List result = new ArrayList<>(); + Promise> promise = Promise.promise(); + List result = new ArrayList<>(); PortfolioVerticle.getProjectMetadata(result, projectId); promise.complete(result); @@ -215,12 +215,12 @@ public Future> getProjectMetadata(String projectId) { return promise.future(); } - public Future> getAllProjectsMeta(int annotationType) { + public Future> getAllProjectsMeta(int annotationType) { Tuple params = Tuple.of(annotationType); return runQuery(PortfolioDbQuery.getRetrieveAllProjectsForAnnotationType(), params) .map(result -> { - List projectData = new ArrayList<>(); + List projectData = new ArrayList<>(); for (Row row : result) { String projectName = row.getString(0); @@ -269,8 +269,8 @@ public Future loadProject(String projectId) { return promise.future(); } - public Future getThumbnail(String projectId, String uuid) { - Promise promise = Promise.promise(); + public Future getThumbnail(String projectId, String uuid) { + Promise promise = Promise.promise(); ProjectLoader loader = Objects.requireNonNull(ProjectHandler.getProjectLoader(projectId)); String annotationKey = PortfolioVerticle.getAnnotationKey(loader); @@ -365,7 +365,7 @@ public Future updateLastModifiedDate(String projectId, String dbFormat) { public Future updateLabels(String projectId, JsonObject requestBody) { ProjectLoader loader = Objects.requireNonNull(ProjectHandler.getProjectLoader(projectId)); - JsonArray newLabelListJson = requestBody.getJsonArray(ParamConfig.getLabelListParam()); + List newLabelListJson = ConversionHandler.jsonArray2StringList(requestBody.getJsonArray(ParamConfig.getLabelListParam())); ProjectVersion project = loader.getProjectVersion(); PortfolioVerticle.updateLoaderLabelList(loader, project, newLabelListJson); diff --git a/classifai-core/src/main/java/ai/classifai/database/portfolio/PortfolioVerticle.java b/classifai-core/src/main/java/ai/classifai/database/portfolio/PortfolioVerticle.java index 136ee3de..494b1f33 100644 --- a/classifai-core/src/main/java/ai/classifai/database/portfolio/PortfolioVerticle.java +++ b/classifai-core/src/main/java/ai/classifai/database/portfolio/PortfolioVerticle.java @@ -30,6 +30,8 @@ import ai.classifai.database.versioning.AnnotationVersion; import ai.classifai.database.versioning.ProjectVersion; import ai.classifai.database.versioning.Version; +import ai.classifai.dto.ProjectMeta; +import ai.classifai.dto.Thumbnail; import ai.classifai.loader.NameGenerator; import ai.classifai.loader.ProjectLoader; import ai.classifai.loader.ProjectLoaderStatus; @@ -52,7 +54,6 @@ import io.vertx.core.Promise; import io.vertx.core.Vertx; import io.vertx.core.eventbus.Message; -import io.vertx.core.json.JsonArray; import io.vertx.core.json.JsonObject; import io.vertx.jdbcclient.JDBCPool; import io.vertx.sqlclient.Row; @@ -233,7 +234,7 @@ public static void loadProjectFromImportingConfigFile(@NonNull JsonObject input) public void updateLabelList(Message message) { String projectId = message.body().getString(ParamConfig.getProjectIdParam()); - JsonArray newLabelListJson = new JsonArray(message.body().getString(ParamConfig.getLabelListParam())); + List newLabelListJson = ConversionHandler.jsonArray2StringList(message.body().getJsonArray(ParamConfig.getLabelListParam())); ProjectLoader loader = Objects.requireNonNull(ProjectHandler.getProjectLoader(projectId)); ProjectVersion project = loader.getProjectVersion(); @@ -248,13 +249,13 @@ public void updateLabelList(Message message) } - public static void updateLoaderLabelList(ProjectLoader loader, ProjectVersion project, JsonArray newLabelListJson) + public static void updateLoaderLabelList(ProjectLoader loader, ProjectVersion project, List newLabelListJson) { List newLabelList = new ArrayList<>(); - for(Object label: newLabelListJson) + for(String label: newLabelListJson) { - String trimmedLabel = StringHandler.removeEndOfLineChar((String) label); + String trimmedLabel = StringHandler.removeEndOfLineChar(label); newLabelList.add(trimmedLabel); } @@ -417,7 +418,7 @@ public void getProjectMetadata(Message message) { String projectId = message.body().getString(ParamConfig.getProjectIdParam()); - List result = new ArrayList<>(); + List result = new ArrayList<>(); getProjectMetadata(result, projectId); @@ -427,7 +428,7 @@ public void getProjectMetadata(Message message) message.replyAndRequest(response); } - public static void getProjectMetadata(@NonNull List result, @NonNull String projectId) + public static void getProjectMetadata(@NonNull List result, @NonNull String projectId) { ProjectLoader loader = Objects.requireNonNull(ProjectHandler.getProjectLoader(projectId)); @@ -442,19 +443,20 @@ public static void getProjectMetadata(@NonNull List result, @NonNull List existingDataInDir = ImageHandler.getValidImagesFromFolder(projectPath); - result.add(new JsonObject() - .put(ParamConfig.getProjectNameParam(), loader.getProjectName()) - .put(ParamConfig.getProjectPathParam(), loader.getProjectPath().getAbsolutePath()) - .put(ParamConfig.getIsNewParam(), loader.getIsProjectNew()) - .put(ParamConfig.getIsStarredParam(), loader.getIsProjectStarred()) - .put(ParamConfig.getIsLoadedParam(), loader.getIsLoadedFrontEndToggle()) - .put(ParamConfig.getIsCloudParam(), loader.isCloud()) - .put(ParamConfig.getProjectInfraParam(), loader.getProjectInfra()) - .put(ParamConfig.getCreatedDateParam(), currentVersion.getCreatedDate().toString()) - .put(ParamConfig.getLastModifiedDate(), currentVersion.getLastModifiedDate().toString()) - .put(ParamConfig.getCurrentVersionParam(), currentVersion.getVersionUuid()) - .put(ParamConfig.getTotalUuidParam(), existingDataInDir.size()) - .put(ParamConfig.getIsRootPathValidParam(), projectPath.exists())); + result.add(new ProjectMeta( + loader.getProjectName(), + loader.getProjectPath().getAbsolutePath(), + loader.getIsProjectNew(), + loader.getIsProjectStarred(), + loader.getIsLoadedFrontEndToggle(), + loader.isCloud(), + loader.getProjectInfra(), + currentVersion.getCreatedDate().toString(), + currentVersion.getLastModifiedDate().toString(), + currentVersion.getVersionUuid(), + existingDataInDir.size(), + projectPath.exists() + )); } /** @@ -470,7 +472,7 @@ public void getAllProjectsMetadata(Message message) .execute(params) .onComplete(DBUtils.handleResponse( result -> { - List projectData = new ArrayList<>(); + List projectData = new ArrayList<>(); for (Row row : result) { @@ -572,7 +574,7 @@ public void reloadProject(Message message) ImageHandler.loadProjectRootPath(loader); } - public static JsonObject queryData(String projectId, String uuid, @NonNull String annotationKey) + public static Thumbnail queryData(String projectId, String uuid, @NonNull String annotationKey) { ProjectLoader loader = Objects.requireNonNull(ProjectHandler.getProjectLoader(projectId)); Annotation annotation = loader.getUuidAnnotationDict().get(uuid); @@ -614,24 +616,39 @@ public static JsonObject queryData(String projectId, String uuid, @NonNull Strin } } - JsonObject response = ReplyHandler.getOkReply(); - response.put(ParamConfig.getUuidParam(), uuid); - response.put(ParamConfig.getProjectNameParam(), loader.getProjectName()); - - response.put(ParamConfig.getImgPathParam(), dataPath); - response.put(annotationKey, version.getAnnotation()); - response.put(ParamConfig.getImgDepth(), Integer.parseInt(imgData.get(ParamConfig.getImgDepth()))); - response.put(ParamConfig.getImgXParam(), version.getImgX()); - response.put(ParamConfig.getImgYParam(), version.getImgY()); - response.put(ParamConfig.getImgWParam(), version.getImgW()); - response.put(ParamConfig.getImgHParam(), version.getImgH()); - response.put(ParamConfig.getFileSizeParam(), annotation.getFileSize()); - response.put(ParamConfig.getImgOriWParam(), Integer.parseInt(imgData.get(ParamConfig.getImgOriWParam()))); - response.put(ParamConfig.getImgOriHParam(), Integer.parseInt(imgData.get(ParamConfig.getImgOriHParam()))); - response.put(ParamConfig.getImgThumbnailParam(), imgData.get(ParamConfig.getBase64Param())); - - return response; +// JsonObject response = ReplyHandler.getOkReply(); +// +// response.put(ParamConfig.getUuidParam(), uuid); +// response.put(ParamConfig.getProjectNameParam(), loader.getProjectName()); +// +// response.put(ParamConfig.getImgPathParam(), dataPath); +// response.put(annotationKey, version.getAnnotation()); +// response.put(ParamConfig.getImgDepth(), Integer.parseInt(imgData.get(ParamConfig.getImgDepth()))); +// response.put(ParamConfig.getImgXParam(), version.getImgX()); +// response.put(ParamConfig.getImgYParam(), version.getImgY()); +// response.put(ParamConfig.getImgWParam(), version.getImgW()); +// response.put(ParamConfig.getImgHParam(), version.getImgH()); +// response.put(ParamConfig.getFileSizeParam(), annotation.getFileSize()); +// response.put(ParamConfig.getImgOriWParam(), Integer.parseInt(imgData.get(ParamConfig.getImgOriWParam()))); +// response.put(ParamConfig.getImgOriHParam(), Integer.parseInt(imgData.get(ParamConfig.getImgOriHParam()))); +// response.put(ParamConfig.getImgThumbnailParam(), imgData.get(ParamConfig.getBase64Param())); + + return new Thumbnail( + uuid, + loader.getProjectName(), + dataPath, + version.getAnnotation(), + Integer.parseInt(imgData.get(ParamConfig.getImgDepth())), + version.getImgX(), + version.getImgY(), + version.getImgW(), + version.getImgH(), + annotation.getFileSize(), + Integer.parseInt(imgData.get(ParamConfig.getImgOriWParam())), + Integer.parseInt(imgData.get(ParamConfig.getImgOriHParam())), + imgData.get(ParamConfig.getBase64Param()) + ); } public static String getAnnotationKey(ProjectLoader loader) { diff --git a/classifai-core/src/main/java/ai/classifai/dto/ProjectMeta.java b/classifai-core/src/main/java/ai/classifai/dto/ProjectMeta.java new file mode 100644 index 00000000..5c890370 --- /dev/null +++ b/classifai-core/src/main/java/ai/classifai/dto/ProjectMeta.java @@ -0,0 +1,47 @@ +package ai.classifai.dto; + +import ai.classifai.util.ParamConfig; +import ai.classifai.util.project.ProjectInfra; +import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.AllArgsConstructor; +import lombok.Data; + +@AllArgsConstructor +@Data +public class ProjectMeta { + @JsonProperty("project_name") + String projectName; + + @JsonProperty("project_path") + String projectPath; + + @JsonProperty("is_new") + Boolean isNewParam; + + @JsonProperty("is_starred") + Boolean isStarredParam; + + @JsonProperty("is_loaded") + Boolean isLoadedParam; + + @JsonProperty("is_cloud") + Boolean isCloud; + + @JsonProperty("project_infra") + ProjectInfra projectInfraParam; + + @JsonProperty("created_date") + String createdDateParam; + + @JsonProperty("last_modified_date") + String lastModifiedDate; + + @JsonProperty("current_version") + String currentVersionParam; + + @JsonProperty("total_uuid") + int totalUuidParam; + + @JsonProperty("root_path_valid") + Boolean isRootPathValidParam; +} diff --git a/classifai-core/src/main/java/ai/classifai/dto/Thumbnail.java b/classifai-core/src/main/java/ai/classifai/dto/Thumbnail.java new file mode 100644 index 00000000..b8140155 --- /dev/null +++ b/classifai-core/src/main/java/ai/classifai/dto/Thumbnail.java @@ -0,0 +1,50 @@ +package ai.classifai.dto; + +import com.fasterxml.jackson.annotation.JsonProperty; +import io.vertx.core.json.JsonArray; +import lombok.AllArgsConstructor; +import lombok.Data; + +@AllArgsConstructor +@Data +public class Thumbnail { + + @JsonProperty("uuid") + String uuidParam; + + @JsonProperty("project_name") + String projectNameParam; + + @JsonProperty("img_path") + String imgPathParam; + + @JsonProperty("bnd_box") + JsonArray boundingBoxParam; + + @JsonProperty("img_depth") + Integer imgDepth; + + @JsonProperty("img_x") + Integer imgXParam; + + @JsonProperty("img_y") + Integer imgYParam; + + @JsonProperty("img_w") + Integer imgWParam; + + @JsonProperty("img_h") + Integer imgHParam; + + @JsonProperty("file_size") + Integer fileSizeParam; + + @JsonProperty("img_ori_w") + Integer imgOriWParam; + + @JsonProperty("img_ori_h") + Integer imgOriHParam; + + @JsonProperty("img_thumbnail") + String imgThumbnailParam; +} diff --git a/classifai-core/src/main/java/ai/classifai/router/V1Endpoint.java b/classifai-core/src/main/java/ai/classifai/router/V1Endpoint.java index 81cd8cfa..d583b1b1 100644 --- a/classifai-core/src/main/java/ai/classifai/router/V1Endpoint.java +++ b/classifai-core/src/main/java/ai/classifai/router/V1Endpoint.java @@ -26,6 +26,8 @@ import ai.classifai.util.project.ProjectHandler; import ai.classifai.util.type.AnnotationHandler; import ai.classifai.util.type.AnnotationType; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.ObjectMapper; import io.vertx.core.Future; import io.vertx.core.json.JsonObject; import io.vertx.ext.web.RoutingContext; @@ -202,7 +204,15 @@ public void getThumbnail(RoutingContext context) String uuid = context.request().getParam(ParamConfig.getUuidParam()); portfolioDB.getThumbnail(projectID, uuid) - .onSuccess(result -> HTTPResponseHandler.configureOK(context, result)) + .onSuccess(result -> { + ObjectMapper mp = new ObjectMapper(); + try { + HTTPResponseHandler.configureOK(context, new JsonObject(mp.writeValueAsString(result))); + } catch (JsonProcessingException e) { + HTTPResponseHandler.configureOK(context, + ReplyHandler.reportUserDefinedError("Error converting to JSON")); + } + }) .onFailure(cause -> HTTPResponseHandler.configureOK(context, ReplyHandler.reportUserDefinedError("Fail retrieving thumbnail"))); } diff --git a/classifai-core/src/main/java/ai/classifai/router/V2Endpoint.java b/classifai-core/src/main/java/ai/classifai/router/V2Endpoint.java index cff4e4ec..0493a3e4 100644 --- a/classifai-core/src/main/java/ai/classifai/router/V2Endpoint.java +++ b/classifai-core/src/main/java/ai/classifai/router/V2Endpoint.java @@ -37,7 +37,6 @@ import ai.classifai.util.type.AnnotationHandler; import ai.classifai.util.type.AnnotationType; import io.vertx.core.Future; -import io.vertx.core.json.JsonArray; import io.vertx.core.json.JsonObject; import io.vertx.ext.web.RoutingContext; import lombok.Setter; @@ -574,8 +573,8 @@ public void deleteProjectData(RoutingContext context) context.request().bodyHandler(handler -> { JsonObject request = Objects.requireNonNull(ConversionHandler.json2JSONObject(handler.toJson())); - JsonArray uuidListArray = request.getJsonArray(ParamConfig.getUuidListParam()); - JsonArray uuidImgPathList = request.getJsonArray(ParamConfig.getImgPathListParam()); + List uuidListArray = ConversionHandler.jsonArray2StringList(request.getJsonArray(ParamConfig.getUuidListParam())); + List uuidImgPathList = ConversionHandler.jsonArray2StringList(request.getJsonArray(ParamConfig.getImgPathListParam())); portfolioDB.deleteProjectData(projectID, uuidListArray, uuidImgPathList) .onSuccess(result -> HTTPResponseHandler.configureOK(context, diff --git a/pom.xml b/pom.xml index b04c60df..190a3748 100644 --- a/pom.xml +++ b/pom.xml @@ -99,6 +99,7 @@ 2.0.0-alpha2 dev 4.5.1-2 + 2.12.3 @@ -263,6 +264,11 @@ opencv ${opencv.version} + + com.fasterxml.jackson.core + jackson-core + ${jackson.version} + From bbf5c80b8c114b8ff6e151850b4d8ba25efa6f34 Mon Sep 17 00:00:00 2001 From: devenyantis Date: Mon, 20 Sep 2021 15:41:14 +0800 Subject: [PATCH 05/16] :construction: Change generic tp dto --- .../database/portfolio/PortfolioDB.java | 18 ++--- .../database/portfolio/PortfolioVerticle.java | 70 ++++++++++++------- .../dto/AnnotationPointProperties.java | 36 ++++++++++ .../dto/DistanceToImageProperties.java | 15 ++++ ...ctMeta.java => ProjectMetaProperties.java} | 3 +- ...humbnail.java => ThumbnailProperties.java} | 7 +- .../java/ai/classifai/router/V1Endpoint.java | 4 +- 7 files changed, 112 insertions(+), 41 deletions(-) create mode 100644 classifai-core/src/main/java/ai/classifai/dto/AnnotationPointProperties.java create mode 100644 classifai-core/src/main/java/ai/classifai/dto/DistanceToImageProperties.java rename classifai-core/src/main/java/ai/classifai/dto/{ProjectMeta.java => ProjectMetaProperties.java} (93%) rename classifai-core/src/main/java/ai/classifai/dto/{Thumbnail.java => ThumbnailProperties.java} (88%) diff --git a/classifai-core/src/main/java/ai/classifai/database/portfolio/PortfolioDB.java b/classifai-core/src/main/java/ai/classifai/database/portfolio/PortfolioDB.java index 3df54964..ed29b46d 100644 --- a/classifai-core/src/main/java/ai/classifai/database/portfolio/PortfolioDB.java +++ b/classifai-core/src/main/java/ai/classifai/database/portfolio/PortfolioDB.java @@ -25,8 +25,8 @@ import ai.classifai.database.versioning.Annotation; import ai.classifai.database.versioning.AnnotationVersion; import ai.classifai.database.versioning.ProjectVersion; -import ai.classifai.dto.ProjectMeta; -import ai.classifai.dto.Thumbnail; +import ai.classifai.dto.ProjectMetaProperties; +import ai.classifai.dto.ThumbnailProperties; import ai.classifai.loader.ProjectLoader; import ai.classifai.util.ParamConfig; import ai.classifai.util.collection.ConversionHandler; @@ -204,10 +204,10 @@ public Future reloadProject(String projectId) { return promise.future(); } - public Future> getProjectMetadata(String projectId) { + public Future> getProjectMetadata(String projectId) { - Promise> promise = Promise.promise(); - List result = new ArrayList<>(); + Promise> promise = Promise.promise(); + List result = new ArrayList<>(); PortfolioVerticle.getProjectMetadata(result, projectId); promise.complete(result); @@ -215,12 +215,12 @@ public Future> getProjectMetadata(String projectId) { return promise.future(); } - public Future> getAllProjectsMeta(int annotationType) { + public Future> getAllProjectsMeta(int annotationType) { Tuple params = Tuple.of(annotationType); return runQuery(PortfolioDbQuery.getRetrieveAllProjectsForAnnotationType(), params) .map(result -> { - List projectData = new ArrayList<>(); + List projectData = new ArrayList<>(); for (Row row : result) { String projectName = row.getString(0); @@ -269,8 +269,8 @@ public Future loadProject(String projectId) { return promise.future(); } - public Future getThumbnail(String projectId, String uuid) { - Promise promise = Promise.promise(); + public Future getThumbnail(String projectId, String uuid) { + Promise promise = Promise.promise(); ProjectLoader loader = Objects.requireNonNull(ProjectHandler.getProjectLoader(projectId)); String annotationKey = PortfolioVerticle.getAnnotationKey(loader); diff --git a/classifai-core/src/main/java/ai/classifai/database/portfolio/PortfolioVerticle.java b/classifai-core/src/main/java/ai/classifai/database/portfolio/PortfolioVerticle.java index 494b1f33..709cad3b 100644 --- a/classifai-core/src/main/java/ai/classifai/database/portfolio/PortfolioVerticle.java +++ b/classifai-core/src/main/java/ai/classifai/database/portfolio/PortfolioVerticle.java @@ -30,8 +30,10 @@ import ai.classifai.database.versioning.AnnotationVersion; import ai.classifai.database.versioning.ProjectVersion; import ai.classifai.database.versioning.Version; -import ai.classifai.dto.ProjectMeta; -import ai.classifai.dto.Thumbnail; +import ai.classifai.dto.AnnotationPointProperties; +import ai.classifai.dto.DistanceToImageProperties; +import ai.classifai.dto.ProjectMetaProperties; +import ai.classifai.dto.ThumbnailProperties; import ai.classifai.loader.NameGenerator; import ai.classifai.loader.ProjectLoader; import ai.classifai.loader.ProjectLoaderStatus; @@ -418,7 +420,7 @@ public void getProjectMetadata(Message message) { String projectId = message.body().getString(ParamConfig.getProjectIdParam()); - List result = new ArrayList<>(); + List result = new ArrayList<>(); getProjectMetadata(result, projectId); @@ -428,7 +430,7 @@ public void getProjectMetadata(Message message) message.replyAndRequest(response); } - public static void getProjectMetadata(@NonNull List result, @NonNull String projectId) + public static void getProjectMetadata(@NonNull List result, @NonNull String projectId) { ProjectLoader loader = Objects.requireNonNull(ProjectHandler.getProjectLoader(projectId)); @@ -443,7 +445,7 @@ public static void getProjectMetadata(@NonNull List result, @NonNul List existingDataInDir = ImageHandler.getValidImagesFromFolder(projectPath); - result.add(new ProjectMeta( + result.add(new ProjectMetaProperties( loader.getProjectName(), loader.getProjectPath().getAbsolutePath(), loader.getIsProjectNew(), @@ -472,7 +474,7 @@ public void getAllProjectsMetadata(Message message) .execute(params) .onComplete(DBUtils.handleResponse( result -> { - List projectData = new ArrayList<>(); + List projectData = new ArrayList<>(); for (Row row : result) { @@ -574,7 +576,7 @@ public void reloadProject(Message message) ImageHandler.loadProjectRootPath(loader); } - public static Thumbnail queryData(String projectId, String uuid, @NonNull String annotationKey) + public static ThumbnailProperties queryData(String projectId, String uuid, @NonNull String annotationKey) { ProjectLoader loader = Objects.requireNonNull(ProjectHandler.getProjectLoader(projectId)); Annotation annotation = loader.getUuidAnnotationDict().get(uuid); @@ -616,29 +618,13 @@ public static Thumbnail queryData(String projectId, String uuid, @NonNull String } } + List versionAnnotations = getAnnotations(version); -// JsonObject response = ReplyHandler.getOkReply(); -// -// response.put(ParamConfig.getUuidParam(), uuid); -// response.put(ParamConfig.getProjectNameParam(), loader.getProjectName()); -// -// response.put(ParamConfig.getImgPathParam(), dataPath); -// response.put(annotationKey, version.getAnnotation()); -// response.put(ParamConfig.getImgDepth(), Integer.parseInt(imgData.get(ParamConfig.getImgDepth()))); -// response.put(ParamConfig.getImgXParam(), version.getImgX()); -// response.put(ParamConfig.getImgYParam(), version.getImgY()); -// response.put(ParamConfig.getImgWParam(), version.getImgW()); -// response.put(ParamConfig.getImgHParam(), version.getImgH()); -// response.put(ParamConfig.getFileSizeParam(), annotation.getFileSize()); -// response.put(ParamConfig.getImgOriWParam(), Integer.parseInt(imgData.get(ParamConfig.getImgOriWParam()))); -// response.put(ParamConfig.getImgOriHParam(), Integer.parseInt(imgData.get(ParamConfig.getImgOriHParam()))); -// response.put(ParamConfig.getImgThumbnailParam(), imgData.get(ParamConfig.getBase64Param())); - - return new Thumbnail( + return new ThumbnailProperties( uuid, loader.getProjectName(), dataPath, - version.getAnnotation(), + versionAnnotations, Integer.parseInt(imgData.get(ParamConfig.getImgDepth())), version.getImgX(), version.getImgY(), @@ -651,6 +637,38 @@ public static Thumbnail queryData(String projectId, String uuid, @NonNull String ); } + private static List getAnnotations(AnnotationVersion version) { + List versionAnnotations = new ArrayList<>(); + + version.getAnnotation().forEach(arr -> { + JsonObject jsonAnnotation = (JsonObject) arr; + JsonObject jsonDistToImg = jsonAnnotation.getJsonObject("distancetoImg"); + + // Get distance to image + DistanceToImageProperties distanceToImg = new DistanceToImageProperties( + jsonDistToImg.getInteger("x"), + jsonDistToImg.getInteger("y") + ); + + // Get Annotation point + AnnotationPointProperties annotationPoint = new AnnotationPointProperties( + jsonAnnotation.getInteger("x1"), + jsonAnnotation.getInteger("y1"), + jsonAnnotation.getInteger("x2"), + jsonAnnotation.getInteger("y2"), + jsonAnnotation.getInteger("lineWidth"), + jsonAnnotation.getString("color"), + distanceToImg, + jsonAnnotation.getString("label"), + jsonAnnotation.getString("id") + ); + + versionAnnotations.add(annotationPoint); + }); + + return versionAnnotations; + } + public static String getAnnotationKey(ProjectLoader loader) { if(loader.getAnnotationType().equals(AnnotationType.BOUNDINGBOX.ordinal())) { return ParamConfig.getBoundingBoxParam(); diff --git a/classifai-core/src/main/java/ai/classifai/dto/AnnotationPointProperties.java b/classifai-core/src/main/java/ai/classifai/dto/AnnotationPointProperties.java new file mode 100644 index 00000000..dd1ed24f --- /dev/null +++ b/classifai-core/src/main/java/ai/classifai/dto/AnnotationPointProperties.java @@ -0,0 +1,36 @@ +package ai.classifai.dto; + +import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.AllArgsConstructor; +import lombok.Data; + +@AllArgsConstructor +@Data +public class AnnotationPointProperties { + @JsonProperty + Integer x1; + + @JsonProperty + Integer y1; + + @JsonProperty + Integer x2; + + @JsonProperty + Integer y2; + + @JsonProperty + Integer lineWidth; + + @JsonProperty + String color; + + @JsonProperty + DistanceToImageProperties distancetoImg; + + @JsonProperty + String label; + + @JsonProperty + String id; +} \ No newline at end of file diff --git a/classifai-core/src/main/java/ai/classifai/dto/DistanceToImageProperties.java b/classifai-core/src/main/java/ai/classifai/dto/DistanceToImageProperties.java new file mode 100644 index 00000000..5fdd380e --- /dev/null +++ b/classifai-core/src/main/java/ai/classifai/dto/DistanceToImageProperties.java @@ -0,0 +1,15 @@ +package ai.classifai.dto; + +import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.AllArgsConstructor; +import lombok.Data; + +@AllArgsConstructor +@Data +public class DistanceToImageProperties { + @JsonProperty + Integer x; + + @JsonProperty + Integer y; +} diff --git a/classifai-core/src/main/java/ai/classifai/dto/ProjectMeta.java b/classifai-core/src/main/java/ai/classifai/dto/ProjectMetaProperties.java similarity index 93% rename from classifai-core/src/main/java/ai/classifai/dto/ProjectMeta.java rename to classifai-core/src/main/java/ai/classifai/dto/ProjectMetaProperties.java index 5c890370..de13da17 100644 --- a/classifai-core/src/main/java/ai/classifai/dto/ProjectMeta.java +++ b/classifai-core/src/main/java/ai/classifai/dto/ProjectMetaProperties.java @@ -1,6 +1,5 @@ package ai.classifai.dto; -import ai.classifai.util.ParamConfig; import ai.classifai.util.project.ProjectInfra; import com.fasterxml.jackson.annotation.JsonProperty; import lombok.AllArgsConstructor; @@ -8,7 +7,7 @@ @AllArgsConstructor @Data -public class ProjectMeta { +public class ProjectMetaProperties { @JsonProperty("project_name") String projectName; diff --git a/classifai-core/src/main/java/ai/classifai/dto/Thumbnail.java b/classifai-core/src/main/java/ai/classifai/dto/ThumbnailProperties.java similarity index 88% rename from classifai-core/src/main/java/ai/classifai/dto/Thumbnail.java rename to classifai-core/src/main/java/ai/classifai/dto/ThumbnailProperties.java index b8140155..c99cc324 100644 --- a/classifai-core/src/main/java/ai/classifai/dto/Thumbnail.java +++ b/classifai-core/src/main/java/ai/classifai/dto/ThumbnailProperties.java @@ -1,13 +1,14 @@ package ai.classifai.dto; import com.fasterxml.jackson.annotation.JsonProperty; -import io.vertx.core.json.JsonArray; import lombok.AllArgsConstructor; import lombok.Data; +import java.util.List; + @AllArgsConstructor @Data -public class Thumbnail { +public class ThumbnailProperties { @JsonProperty("uuid") String uuidParam; @@ -19,7 +20,7 @@ public class Thumbnail { String imgPathParam; @JsonProperty("bnd_box") - JsonArray boundingBoxParam; + List boundingBoxParam; @JsonProperty("img_depth") Integer imgDepth; diff --git a/classifai-core/src/main/java/ai/classifai/router/V1Endpoint.java b/classifai-core/src/main/java/ai/classifai/router/V1Endpoint.java index d583b1b1..0ed295bd 100644 --- a/classifai-core/src/main/java/ai/classifai/router/V1Endpoint.java +++ b/classifai-core/src/main/java/ai/classifai/router/V1Endpoint.java @@ -207,7 +207,9 @@ public void getThumbnail(RoutingContext context) .onSuccess(result -> { ObjectMapper mp = new ObjectMapper(); try { - HTTPResponseHandler.configureOK(context, new JsonObject(mp.writeValueAsString(result))); + String jsonString = mp.writeValueAsString(result); + JsonObject response = new JsonObject(jsonString); + HTTPResponseHandler.configureOK(context, response); } catch (JsonProcessingException e) { HTTPResponseHandler.configureOK(context, ReplyHandler.reportUserDefinedError("Error converting to JSON")); From bd87514afa23d8e74d240bceeb205a3df1494039 Mon Sep 17 00:00:00 2001 From: devenyantis Date: Mon, 20 Sep 2021 21:16:30 +0800 Subject: [PATCH 06/16] :construction: Change generic export content to dto --- .../ai/classifai/action/FileGenerator.java | 3 +- .../ai/classifai/action/ProjectExport.java | 38 ++++++----- .../action/parser/PortfolioParser.java | 44 ++++++++---- .../action/parser/ProjectParser.java | 68 ++++++++++++++----- .../database/portfolio/PortfolioDB.java | 3 +- .../database/portfolio/PortfolioVerticle.java | 58 ++++++++-------- .../dto/AnnotationConfigProperties.java | 33 +++++++++ .../dto/ProjectConfigProperties.java | 57 ++++++++++++++++ .../dto/VersionConfigProperties.java | 19 ++++++ 9 files changed, 246 insertions(+), 77 deletions(-) create mode 100644 classifai-core/src/main/java/ai/classifai/dto/AnnotationConfigProperties.java create mode 100644 classifai-core/src/main/java/ai/classifai/dto/ProjectConfigProperties.java create mode 100644 classifai-core/src/main/java/ai/classifai/dto/VersionConfigProperties.java diff --git a/classifai-core/src/main/java/ai/classifai/action/FileGenerator.java b/classifai-core/src/main/java/ai/classifai/action/FileGenerator.java index cd3ea770..b018de03 100644 --- a/classifai-core/src/main/java/ai/classifai/action/FileGenerator.java +++ b/classifai-core/src/main/java/ai/classifai/action/FileGenerator.java @@ -15,6 +15,7 @@ */ package ai.classifai.action; +import ai.classifai.dto.ProjectConfigProperties; import ai.classifai.loader.ProjectLoader; import io.vertx.core.json.JsonObject; import lombok.NonNull; @@ -31,7 +32,7 @@ @Slf4j public class FileGenerator { - public void run(@NonNull ProjectLoader loader, @NonNull JsonObject configContent, @NonNull int exportType) { + public void run(@NonNull ProjectLoader loader, @NonNull ProjectConfigProperties configContent, @NonNull int exportType) { EventQueue.invokeLater(() -> { String exportPath = null; if(exportType == ActionConfig.ExportType.CONFIG_WITH_DATA.ordinal()) diff --git a/classifai-core/src/main/java/ai/classifai/action/ProjectExport.java b/classifai-core/src/main/java/ai/classifai/action/ProjectExport.java index 13ae502d..cd590689 100644 --- a/classifai-core/src/main/java/ai/classifai/action/ProjectExport.java +++ b/classifai-core/src/main/java/ai/classifai/action/ProjectExport.java @@ -17,11 +17,14 @@ import ai.classifai.action.parser.PortfolioParser; import ai.classifai.action.parser.ProjectParser; +import ai.classifai.dto.AnnotationConfigProperties; +import ai.classifai.dto.ProjectConfigProperties; import ai.classifai.loader.ProjectLoader; import ai.classifai.util.ParamConfig; import ai.classifai.util.data.ImageHandler; import ai.classifai.util.datetime.DateTime; import ai.classifai.util.project.ProjectHandler; +import com.fasterxml.jackson.databind.ObjectMapper; import io.vertx.core.json.JsonObject; import io.vertx.sqlclient.Row; import io.vertx.sqlclient.RowSet; @@ -30,6 +33,7 @@ import java.io.*; import java.nio.file.Paths; +import java.util.HashMap; import java.util.List; import java.util.Objects; import java.util.zip.ZipEntry; @@ -57,15 +61,7 @@ public enum ProjectExportStatus { @Getter @Setter private static String exportPath = ""; - public static JsonObject getConfigSkeletonStructure() - { - return new JsonObject() - .put(ActionConfig.getToolParam(), ActionConfig.getToolName()) - .put(ActionConfig.getToolVersionParam(), ActionConfig.getToolVersion()) - .put(ActionConfig.getUpdatedDateParam(), new DateTime().toString()); - } - - public static String exportToFile(@NonNull String projectId, @NonNull JsonObject jsonObject) + public static String exportToFile(@NonNull String projectId, @NonNull ProjectConfigProperties configProperties) { ProjectLoader loader = Objects.requireNonNull(ProjectHandler.getProjectLoader(projectId)); @@ -76,7 +72,10 @@ public static String exportToFile(@NonNull String projectId, @NonNull JsonObject { FileWriter file = new FileWriter(configPath); - file.write(jsonObject.encodePrettily()); + ObjectMapper mp = new ObjectMapper(); + String jsonString = mp.writeValueAsString(configProperties); + + file.write(new JsonObject(jsonString).encodePrettily()); file.close(); @@ -90,7 +89,7 @@ public static String exportToFile(@NonNull String projectId, @NonNull JsonObject return configPath; } - public static String exportToFileWithData(ProjectLoader loader, String projectId, JsonObject configContent) throws IOException + public static String exportToFileWithData(ProjectLoader loader, String projectId, ProjectConfigProperties configContent) throws IOException { String configPath = exportToFile(projectId, configContent); File zipFile = Paths.get(loader.getProjectPath().getAbsolutePath(), loader.getProjectName() + ".zip").toFile(); @@ -146,7 +145,7 @@ private static void addToEntry(File filePath, ZipOutputStream out, File dir) thr } } - public static JsonObject getConfigContent(@NonNull RowSet rowSet, @NonNull RowSet projectRowSet) + public static ProjectConfigProperties getConfigContent(@NonNull RowSet rowSet, @NonNull RowSet projectRowSet) { if(rowSet.size() == 0) { @@ -154,8 +153,10 @@ public static JsonObject getConfigContent(@NonNull RowSet rowSet, @NonNull return null; } - JsonObject configContent = getConfigSkeletonStructure(); - PortfolioParser.parseOut(rowSet.iterator().next(), configContent); + ProjectConfigProperties projectConfig = PortfolioParser.parseOut(rowSet.iterator().next()); + projectConfig.setToolName(ActionConfig.getToolName()); + projectConfig.setToolVersion(ActionConfig.getToolVersion()); + projectConfig.setUpdateDate(new DateTime().toString()); if(projectRowSet.size() == 0) { @@ -163,11 +164,12 @@ public static JsonObject getConfigContent(@NonNull RowSet rowSet, @NonNull return null; } - ProjectParser.parseOut( - configContent.getString(ParamConfig.getProjectPathParam()), - projectRowSet.iterator(), configContent); + HashMap configProperties = ProjectParser.parseOut( + projectConfig.getProjectPath(), projectRowSet.iterator()); + + projectConfig.setContent(configProperties); - return configContent; + return projectConfig; } public static ActionConfig.ExportType getExportType(String exportType) diff --git a/classifai-core/src/main/java/ai/classifai/action/parser/PortfolioParser.java b/classifai-core/src/main/java/ai/classifai/action/parser/PortfolioParser.java index 393fee33..d83f89ee 100644 --- a/classifai-core/src/main/java/ai/classifai/action/parser/PortfolioParser.java +++ b/classifai-core/src/main/java/ai/classifai/action/parser/PortfolioParser.java @@ -19,6 +19,7 @@ import ai.classifai.action.ActionOps; import ai.classifai.database.versioning.ProjectVersion; import ai.classifai.database.versioning.Version; +import ai.classifai.dto.ProjectConfigProperties; import ai.classifai.loader.ProjectLoader; import ai.classifai.loader.ProjectLoaderStatus; import ai.classifai.util.ParamConfig; @@ -49,25 +50,40 @@ public class PortfolioParser /** * Extracting portfolio content and parse to JsonObject, preparing for saving * @param row - * @param jsonObject */ - public static void parseOut(@NonNull Row row, @NonNull JsonObject jsonObject) + public static ProjectConfigProperties parseOut(@NonNull Row row) { String annotationName = AnnotationHandler.getType(row.getInteger(2)).name(); - jsonObject.put(ParamConfig.getProjectIdParam(), row.getString(0)); //project_id - jsonObject.put(ParamConfig.getProjectNameParam(), row.getString(1)); //project_name - jsonObject.put(ParamConfig.getAnnotationTypeParam(), annotationName.toLowerCase(Locale.ROOT)); //annotation_type (in string) +// jsonObject.put(ParamConfig.getProjectIdParam(), row.getString(0)); //project_id +// jsonObject.put(ParamConfig.getProjectNameParam(), row.getString(1)); //project_name +// jsonObject.put(ParamConfig.getAnnotationTypeParam(), annotationName.toLowerCase(Locale.ROOT)); //annotation_type (in string) +// +// jsonObject.put(ParamConfig.getProjectPathParam(), row.getString(3)); //project_path +// jsonObject.put(ParamConfig.getIsNewParam(), row.getBoolean(4)); //is_new +// jsonObject.put(ParamConfig.getIsStarredParam(), row.getBoolean(5)); //is_starred +// +// jsonObject.put(ParamConfig.getProjectInfraParam(), row.getString(6).toLowerCase()); //project_infra +// jsonObject.put(ParamConfig.getCurrentVersionParam(), row.getString(7)); //current version +// jsonObject.put(ParamConfig.getProjectVersionParam(), row.getString(8)); //project version +// jsonObject.put(ParamConfig.getUuidVersionListParam(), row.getString(9)); //uuid_version_list +// jsonObject.put(ParamConfig.getLabelVersionListParam(), row.getString(10)); //label_version_list + + ProjectConfigProperties config = new ProjectConfigProperties(); + config.setProjectID(row.getString(0)); + config.setProjectName(row.getString(1)); + config.setAnnotationType(annotationName.toLowerCase(Locale.ROOT)); + config.setProjectPath(row.getString(3)); + config.setIsNew(row.getBoolean(4)); + config.setIsStarred(row.getBoolean(5)); + config.setProjectInfra(row.getString(6).toLowerCase()); + config.setCurrentVersion(row.getString(7)); + config.setProjectVersion(row.getString(8)); + config.setUuidVersionList(row.getString(9)); + config.setLabelVersionList(row.getString(10)); + + return config; - jsonObject.put(ParamConfig.getProjectPathParam(), row.getString(3)); //project_path - jsonObject.put(ParamConfig.getIsNewParam(), row.getBoolean(4)); //is_new - jsonObject.put(ParamConfig.getIsStarredParam(), row.getBoolean(5)); //is_starred - - jsonObject.put(ParamConfig.getProjectInfraParam(), row.getString(6).toLowerCase()); //project_infra - jsonObject.put(ParamConfig.getCurrentVersionParam(), row.getString(7)); //current version - jsonObject.put(ParamConfig.getProjectVersionParam(), row.getString(8)); //project version - jsonObject.put(ParamConfig.getUuidVersionListParam(), row.getString(9)); //uuid_version_list - jsonObject.put(ParamConfig.getLabelVersionListParam(), row.getString(10)); //label_version_list } public static ProjectLoader parseIn(@NonNull JsonObject jsonObject) diff --git a/classifai-core/src/main/java/ai/classifai/action/parser/ProjectParser.java b/classifai-core/src/main/java/ai/classifai/action/parser/ProjectParser.java index 27fd157b..50ef20fa 100644 --- a/classifai-core/src/main/java/ai/classifai/action/parser/ProjectParser.java +++ b/classifai-core/src/main/java/ai/classifai/action/parser/ProjectParser.java @@ -16,8 +16,12 @@ package ai.classifai.action.parser; import ai.classifai.database.annotation.AnnotationVerticle; +import ai.classifai.database.portfolio.PortfolioVerticle; import ai.classifai.database.versioning.Annotation; import ai.classifai.database.versioning.AnnotationVersion; +import ai.classifai.dto.AnnotationConfigProperties; +import ai.classifai.dto.AnnotationPointProperties; +import ai.classifai.dto.VersionConfigProperties; import ai.classifai.loader.ProjectLoader; import ai.classifai.util.Hash; import ai.classifai.util.ParamConfig; @@ -33,10 +37,7 @@ import java.io.File; import java.nio.file.Paths; -import java.util.HashMap; -import java.util.Iterator; -import java.util.Map; -import java.util.Set; +import java.util.*; /*** * Parsing Project Table in and out classifai with configuration file @@ -47,9 +48,9 @@ @NoArgsConstructor(access = AccessLevel.PRIVATE) public class ProjectParser { - public static void parseOut(@NonNull String projectPath, @NonNull RowIterator rowIterator, @NonNull JsonObject jsonObject) + public static HashMap parseOut(@NonNull String projectPath, @NonNull RowIterator rowIterator) { - JsonObject content = new JsonObject(); + HashMap content = new HashMap<>(); while(rowIterator.hasNext()) { @@ -61,23 +62,58 @@ public static void parseOut(@NonNull String projectPath, @NonNull RowIterator getVersionList(String versionListString) { + JsonArray versionListArray = new JsonArray(versionListString); + + List config = new ArrayList<>(); + + for(int i=0; i < versionListArray.size(); ++i) { + JsonObject jsonAnnotation = versionListArray.getJsonObject(i); + + VersionConfigProperties versionConfig = new VersionConfigProperties(); + versionConfig.setVersionUuid(jsonAnnotation.getString(ParamConfig.getVersionUuidParam())); + JsonArray annotationConfigArray = jsonAnnotation.getJsonObject(ParamConfig.getAnnotationDataParam()) + .getJsonArray(ParamConfig.getAnnotationParam()); + List annotationPoints = new ArrayList<>(); + for(int j=0; j < annotationConfigArray.size(); ++j) { + JsonObject jsonAnnotationConfig = annotationConfigArray.getJsonObject(j); + annotationPoints.add(PortfolioVerticle.getAnnotations(jsonAnnotationConfig)); + } + versionConfig.setAnnotationData(new HashMap<>() {{ + put("annotation", annotationPoints); + }}); + } + + return config; + } + public static void parseIn(@NonNull ProjectLoader loader, @NonNull JsonObject contentJsonBody) { String projectId = loader.getProjectId(); diff --git a/classifai-core/src/main/java/ai/classifai/database/portfolio/PortfolioDB.java b/classifai-core/src/main/java/ai/classifai/database/portfolio/PortfolioDB.java index ed29b46d..5383ea5b 100644 --- a/classifai-core/src/main/java/ai/classifai/database/portfolio/PortfolioDB.java +++ b/classifai-core/src/main/java/ai/classifai/database/portfolio/PortfolioDB.java @@ -25,6 +25,7 @@ import ai.classifai.database.versioning.Annotation; import ai.classifai.database.versioning.AnnotationVersion; import ai.classifai.database.versioning.ProjectVersion; +import ai.classifai.dto.ProjectConfigProperties; import ai.classifai.dto.ProjectMetaProperties; import ai.classifai.dto.ThumbnailProperties; import ai.classifai.loader.ProjectLoader; @@ -105,7 +106,7 @@ public Future exportProject(String projectId, int exportType) { .onComplete(annotationFetch -> { if (annotationFetch.succeeded()) { - JsonObject configContent = ProjectExport.getConfigContent(result, + ProjectConfigProperties configContent = ProjectExport.getConfigContent(result, annotationFetch.result()); if(configContent == null) return; diff --git a/classifai-core/src/main/java/ai/classifai/database/portfolio/PortfolioVerticle.java b/classifai-core/src/main/java/ai/classifai/database/portfolio/PortfolioVerticle.java index 709cad3b..caee34e7 100644 --- a/classifai-core/src/main/java/ai/classifai/database/portfolio/PortfolioVerticle.java +++ b/classifai-core/src/main/java/ai/classifai/database/portfolio/PortfolioVerticle.java @@ -30,10 +30,7 @@ import ai.classifai.database.versioning.AnnotationVersion; import ai.classifai.database.versioning.ProjectVersion; import ai.classifai.database.versioning.Version; -import ai.classifai.dto.AnnotationPointProperties; -import ai.classifai.dto.DistanceToImageProperties; -import ai.classifai.dto.ProjectMetaProperties; -import ai.classifai.dto.ThumbnailProperties; +import ai.classifai.dto.*; import ai.classifai.loader.NameGenerator; import ai.classifai.loader.ProjectLoader; import ai.classifai.loader.ProjectLoaderStatus; @@ -56,6 +53,7 @@ import io.vertx.core.Promise; import io.vertx.core.Vertx; import io.vertx.core.eventbus.Message; +import io.vertx.core.json.JsonArray; import io.vertx.core.json.JsonObject; import io.vertx.jdbcclient.JDBCPool; import io.vertx.sqlclient.Row; @@ -301,7 +299,7 @@ public void exportProject(Message message) private void exportProjectOnSuccess(RowSet projectRowSet, RowSet rowSet, ProjectLoader loader, int exportType) { - JsonObject configContent = ProjectExport.getConfigContent(rowSet, projectRowSet); + ProjectConfigProperties configContent = ProjectExport.getConfigContent(rowSet, projectRowSet); if(configContent == null) return; fileGenerator.run(loader, configContent, exportType); @@ -642,33 +640,39 @@ private static List getAnnotations(AnnotationVersion version.getAnnotation().forEach(arr -> { JsonObject jsonAnnotation = (JsonObject) arr; - JsonObject jsonDistToImg = jsonAnnotation.getJsonObject("distancetoImg"); - - // Get distance to image - DistanceToImageProperties distanceToImg = new DistanceToImageProperties( - jsonDistToImg.getInteger("x"), - jsonDistToImg.getInteger("y") - ); - - // Get Annotation point - AnnotationPointProperties annotationPoint = new AnnotationPointProperties( - jsonAnnotation.getInteger("x1"), - jsonAnnotation.getInteger("y1"), - jsonAnnotation.getInteger("x2"), - jsonAnnotation.getInteger("y2"), - jsonAnnotation.getInteger("lineWidth"), - jsonAnnotation.getString("color"), - distanceToImg, - jsonAnnotation.getString("label"), - jsonAnnotation.getString("id") - ); - - versionAnnotations.add(annotationPoint); + versionAnnotations.add(getAnnotations(jsonAnnotation)); }); return versionAnnotations; } + public static AnnotationPointProperties getAnnotations(JsonObject jsonAnnotation) { + + JsonObject jsonDistToImg = jsonAnnotation.getJsonObject("distancetoImg"); + + // Get distance to image + DistanceToImageProperties distanceToImg = new DistanceToImageProperties( + jsonDistToImg.getInteger("x"), + jsonDistToImg.getInteger("y") + ); + + // Get Annotation point + AnnotationPointProperties annotationPoint = new AnnotationPointProperties( + jsonAnnotation.getInteger("x1"), + jsonAnnotation.getInteger("y1"), + jsonAnnotation.getInteger("x2"), + jsonAnnotation.getInteger("y2"), + jsonAnnotation.getInteger("lineWidth"), + jsonAnnotation.getString("color"), + distanceToImg, + jsonAnnotation.getString("label"), + jsonAnnotation.getString("id") + ); + + return annotationPoint; + + } + public static String getAnnotationKey(ProjectLoader loader) { if(loader.getAnnotationType().equals(AnnotationType.BOUNDINGBOX.ordinal())) { return ParamConfig.getBoundingBoxParam(); diff --git a/classifai-core/src/main/java/ai/classifai/dto/AnnotationConfigProperties.java b/classifai-core/src/main/java/ai/classifai/dto/AnnotationConfigProperties.java new file mode 100644 index 00000000..86eb2305 --- /dev/null +++ b/classifai-core/src/main/java/ai/classifai/dto/AnnotationConfigProperties.java @@ -0,0 +1,33 @@ +package ai.classifai.dto; + +import com.fasterxml.jackson.annotation.JsonProperty; +import io.vertx.core.json.JsonArray; +import lombok.AllArgsConstructor; +import lombok.Data; + +import java.util.List; + +@AllArgsConstructor +@Data +public class AnnotationConfigProperties { + @JsonProperty + String checksum; + + @JsonProperty("img_path") + String imgPath; + + @JsonProperty("version_list") + List versionList; + + @JsonProperty("img_depth") + Integer imgDepth; + + @JsonProperty("img_ori_w") + Integer imgOriW; + + @JsonProperty("img_ori_h") + Integer imgOriH; + + @JsonProperty("file_size") + Integer fileSize; +} diff --git a/classifai-core/src/main/java/ai/classifai/dto/ProjectConfigProperties.java b/classifai-core/src/main/java/ai/classifai/dto/ProjectConfigProperties.java new file mode 100644 index 00000000..e6988a97 --- /dev/null +++ b/classifai-core/src/main/java/ai/classifai/dto/ProjectConfigProperties.java @@ -0,0 +1,57 @@ +package ai.classifai.dto; + +import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.util.HashMap; + +@NoArgsConstructor +@Data +public class ProjectConfigProperties { + @JsonProperty("tool") + String toolName; + + @JsonProperty("tool_version") + String toolVersion; + + @JsonProperty("updated_date") + String updateDate; + + @JsonProperty("project_id") + String projectID; + + @JsonProperty("project_name") + String projectName; + + @JsonProperty("annotation_type") + String annotationType; + + @JsonProperty("project_path") + String projectPath; + + @JsonProperty("is_new") + Boolean isNew; + + @JsonProperty("is_starred") + Boolean isStarred; + + @JsonProperty("project_infra") + String projectInfra; + + @JsonProperty("current_version") + String currentVersion; + + @JsonProperty("project_version") + String projectVersion; + + @JsonProperty("uuid_version_list") + String uuidVersionList; + + @JsonProperty("label_version_list") + String labelVersionList; + + @JsonProperty + HashMap content; +} diff --git a/classifai-core/src/main/java/ai/classifai/dto/VersionConfigProperties.java b/classifai-core/src/main/java/ai/classifai/dto/VersionConfigProperties.java new file mode 100644 index 00000000..e58887cb --- /dev/null +++ b/classifai-core/src/main/java/ai/classifai/dto/VersionConfigProperties.java @@ -0,0 +1,19 @@ +package ai.classifai.dto; + +import com.fasterxml.jackson.annotation.JsonProperty; +import io.vertx.core.json.JsonArray; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.util.HashMap; +import java.util.List; + +@NoArgsConstructor +@Data +public class VersionConfigProperties { + @JsonProperty("version_uuid") + String versionUuid; + + @JsonProperty("annotation_data") + HashMap> annotationData; +} From d14f4fb0e3ec9ef4381c95962a033616d1c46674 Mon Sep 17 00:00:00 2001 From: devenyantis Date: Mon, 20 Sep 2021 23:00:47 +0800 Subject: [PATCH 07/16] :construction: WIP --- .../database/portfolio/PortfolioVerticle.java | 36 +++++++++++-------- .../dto/AnnotationConfigProperties.java | 1 - .../dto/ProjectConfigProperties.java | 1 - .../ai/classifai/dto/ThumbnailProperties.java | 10 ++++-- .../dto/VersionConfigProperties.java | 1 - 5 files changed, 29 insertions(+), 20 deletions(-) diff --git a/classifai-core/src/main/java/ai/classifai/database/portfolio/PortfolioVerticle.java b/classifai-core/src/main/java/ai/classifai/database/portfolio/PortfolioVerticle.java index caee34e7..1971ebc1 100644 --- a/classifai-core/src/main/java/ai/classifai/database/portfolio/PortfolioVerticle.java +++ b/classifai-core/src/main/java/ai/classifai/database/portfolio/PortfolioVerticle.java @@ -618,21 +618,27 @@ public static ThumbnailProperties queryData(String projectId, String uuid, @NonN List versionAnnotations = getAnnotations(version); - return new ThumbnailProperties( - uuid, - loader.getProjectName(), - dataPath, - versionAnnotations, - Integer.parseInt(imgData.get(ParamConfig.getImgDepth())), - version.getImgX(), - version.getImgY(), - version.getImgW(), - version.getImgH(), - annotation.getFileSize(), - Integer.parseInt(imgData.get(ParamConfig.getImgOriWParam())), - Integer.parseInt(imgData.get(ParamConfig.getImgOriHParam())), - imgData.get(ParamConfig.getBase64Param()) - ); + ThumbnailProperties thumbnailProperties = new ThumbnailProperties(); + thumbnailProperties.setUuidParam(uuid); + thumbnailProperties.setProjectNameParam(loader.getProjectName()); + thumbnailProperties.setImgPathParam(dataPath); + thumbnailProperties.setImgDepth(Integer.parseInt(imgData.get(ParamConfig.getImgDepth()))); + thumbnailProperties.setImgXParam(version.getImgX()); + thumbnailProperties.setImgYParam(version.getImgY()); + thumbnailProperties.setImgWParam(version.getImgW()); + thumbnailProperties.setImgHParam(version.getImgH()); + thumbnailProperties.setFileSizeParam(annotation.getFileSize()); + thumbnailProperties.setImgOriWParam(Integer.parseInt(imgData.get(ParamConfig.getImgOriWParam()))); + thumbnailProperties.setImgOriHParam(Integer.parseInt(imgData.get(ParamConfig.getImgOriHParam()))); + thumbnailProperties.setImgThumbnailParam(imgData.get(ParamConfig.getBase64Param())); + + if(annotationKey.equals(ParamConfig.getBoundingBoxParam())) { + thumbnailProperties.setBoundingBoxParam(versionAnnotations); + } else if(annotationKey.equals(ParamConfig.getSegmentationParam())) { + thumbnailProperties.setSegmentationParam(versionAnnotations); + } + + return thumbnailProperties; } private static List getAnnotations(AnnotationVersion version) { diff --git a/classifai-core/src/main/java/ai/classifai/dto/AnnotationConfigProperties.java b/classifai-core/src/main/java/ai/classifai/dto/AnnotationConfigProperties.java index 86eb2305..aeb0e44e 100644 --- a/classifai-core/src/main/java/ai/classifai/dto/AnnotationConfigProperties.java +++ b/classifai-core/src/main/java/ai/classifai/dto/AnnotationConfigProperties.java @@ -1,7 +1,6 @@ package ai.classifai.dto; import com.fasterxml.jackson.annotation.JsonProperty; -import io.vertx.core.json.JsonArray; import lombok.AllArgsConstructor; import lombok.Data; diff --git a/classifai-core/src/main/java/ai/classifai/dto/ProjectConfigProperties.java b/classifai-core/src/main/java/ai/classifai/dto/ProjectConfigProperties.java index e6988a97..363f2c74 100644 --- a/classifai-core/src/main/java/ai/classifai/dto/ProjectConfigProperties.java +++ b/classifai-core/src/main/java/ai/classifai/dto/ProjectConfigProperties.java @@ -1,7 +1,6 @@ package ai.classifai.dto; import com.fasterxml.jackson.annotation.JsonProperty; -import lombok.AllArgsConstructor; import lombok.Data; import lombok.NoArgsConstructor; diff --git a/classifai-core/src/main/java/ai/classifai/dto/ThumbnailProperties.java b/classifai-core/src/main/java/ai/classifai/dto/ThumbnailProperties.java index c99cc324..35f94c6a 100644 --- a/classifai-core/src/main/java/ai/classifai/dto/ThumbnailProperties.java +++ b/classifai-core/src/main/java/ai/classifai/dto/ThumbnailProperties.java @@ -1,12 +1,13 @@ package ai.classifai.dto; +import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonProperty; -import lombok.AllArgsConstructor; import lombok.Data; +import lombok.NoArgsConstructor; import java.util.List; -@AllArgsConstructor +@NoArgsConstructor @Data public class ThumbnailProperties { @@ -19,6 +20,11 @@ public class ThumbnailProperties { @JsonProperty("img_path") String imgPathParam; + @JsonInclude(JsonInclude.Include.NON_NULL) + @JsonProperty("polygons") + List segmentationParam; + + @JsonInclude(JsonInclude.Include.NON_NULL) @JsonProperty("bnd_box") List boundingBoxParam; diff --git a/classifai-core/src/main/java/ai/classifai/dto/VersionConfigProperties.java b/classifai-core/src/main/java/ai/classifai/dto/VersionConfigProperties.java index e58887cb..6c2e1461 100644 --- a/classifai-core/src/main/java/ai/classifai/dto/VersionConfigProperties.java +++ b/classifai-core/src/main/java/ai/classifai/dto/VersionConfigProperties.java @@ -1,7 +1,6 @@ package ai.classifai.dto; import com.fasterxml.jackson.annotation.JsonProperty; -import io.vertx.core.json.JsonArray; import lombok.Data; import lombok.NoArgsConstructor; From 76a8fcef3eaca86c38157cfdfc60485b18ef2afc Mon Sep 17 00:00:00 2001 From: devenyantis Date: Tue, 21 Sep 2021 11:20:07 +0800 Subject: [PATCH 08/16] :construction: Add nonnull decorator --- .../database/portfolio/PortfolioVerticle.java | 36 +++++++++---------- .../dto/AnnotationConfigProperties.java | 2 ++ .../dto/AnnotationPointProperties.java | 2 ++ .../dto/DistanceToImageProperties.java | 2 ++ .../dto/ProjectConfigProperties.java | 2 ++ .../classifai/dto/ProjectMetaProperties.java | 2 ++ .../ai/classifai/dto/ThumbnailProperties.java | 16 +++++++++ .../dto/VersionConfigProperties.java | 2 ++ 8 files changed, 45 insertions(+), 19 deletions(-) diff --git a/classifai-core/src/main/java/ai/classifai/database/portfolio/PortfolioVerticle.java b/classifai-core/src/main/java/ai/classifai/database/portfolio/PortfolioVerticle.java index 1971ebc1..ff2d7559 100644 --- a/classifai-core/src/main/java/ai/classifai/database/portfolio/PortfolioVerticle.java +++ b/classifai-core/src/main/java/ai/classifai/database/portfolio/PortfolioVerticle.java @@ -53,7 +53,6 @@ import io.vertx.core.Promise; import io.vertx.core.Vertx; import io.vertx.core.eventbus.Message; -import io.vertx.core.json.JsonArray; import io.vertx.core.json.JsonObject; import io.vertx.jdbcclient.JDBCPool; import io.vertx.sqlclient.Row; @@ -616,29 +615,28 @@ public static ThumbnailProperties queryData(String projectId, String uuid, @NonN } } - List versionAnnotations = getAnnotations(version); - - ThumbnailProperties thumbnailProperties = new ThumbnailProperties(); - thumbnailProperties.setUuidParam(uuid); - thumbnailProperties.setProjectNameParam(loader.getProjectName()); - thumbnailProperties.setImgPathParam(dataPath); - thumbnailProperties.setImgDepth(Integer.parseInt(imgData.get(ParamConfig.getImgDepth()))); - thumbnailProperties.setImgXParam(version.getImgX()); - thumbnailProperties.setImgYParam(version.getImgY()); - thumbnailProperties.setImgWParam(version.getImgW()); - thumbnailProperties.setImgHParam(version.getImgH()); - thumbnailProperties.setFileSizeParam(annotation.getFileSize()); - thumbnailProperties.setImgOriWParam(Integer.parseInt(imgData.get(ParamConfig.getImgOriWParam()))); - thumbnailProperties.setImgOriHParam(Integer.parseInt(imgData.get(ParamConfig.getImgOriHParam()))); - thumbnailProperties.setImgThumbnailParam(imgData.get(ParamConfig.getBase64Param())); + ThumbnailProperties thmbProps = new ThumbnailProperties(); if(annotationKey.equals(ParamConfig.getBoundingBoxParam())) { - thumbnailProperties.setBoundingBoxParam(versionAnnotations); + thmbProps.setBoundingBoxParam(getAnnotations(version)); } else if(annotationKey.equals(ParamConfig.getSegmentationParam())) { - thumbnailProperties.setSegmentationParam(versionAnnotations); + thmbProps.setSegmentationParam(getAnnotations(version)); } - return thumbnailProperties; + thmbProps.setUuidParam(uuid); + thmbProps.setProjectNameParam(loader.getProjectName()); + thmbProps.setImgPathParam(dataPath); + thmbProps.setImgDepth(Integer.parseInt(imgData.get(ParamConfig.getImgDepth()))); + thmbProps.setImgXParam(version.getImgX()); + thmbProps.setImgYParam(version.getImgY()); + thmbProps.setImgWParam(version.getImgW()); + thmbProps.setImgHParam(version.getImgH()); + thmbProps.setFileSizeParam(annotation.getFileSize()); + thmbProps.setImgOriWParam(Integer.parseInt(imgData.get(ParamConfig.getImgOriWParam()))); + thmbProps.setImgOriHParam(Integer.parseInt(imgData.get(ParamConfig.getImgOriHParam()))); + thmbProps.setImgThumbnailParam(imgData.get(ParamConfig.getBase64Param())); + + return thmbProps; } private static List getAnnotations(AnnotationVersion version) { diff --git a/classifai-core/src/main/java/ai/classifai/dto/AnnotationConfigProperties.java b/classifai-core/src/main/java/ai/classifai/dto/AnnotationConfigProperties.java index aeb0e44e..e4bf237a 100644 --- a/classifai-core/src/main/java/ai/classifai/dto/AnnotationConfigProperties.java +++ b/classifai-core/src/main/java/ai/classifai/dto/AnnotationConfigProperties.java @@ -3,9 +3,11 @@ import com.fasterxml.jackson.annotation.JsonProperty; import lombok.AllArgsConstructor; import lombok.Data; +import lombok.NonNull; import java.util.List; +@NonNull @AllArgsConstructor @Data public class AnnotationConfigProperties { diff --git a/classifai-core/src/main/java/ai/classifai/dto/AnnotationPointProperties.java b/classifai-core/src/main/java/ai/classifai/dto/AnnotationPointProperties.java index dd1ed24f..e44f83d5 100644 --- a/classifai-core/src/main/java/ai/classifai/dto/AnnotationPointProperties.java +++ b/classifai-core/src/main/java/ai/classifai/dto/AnnotationPointProperties.java @@ -3,7 +3,9 @@ import com.fasterxml.jackson.annotation.JsonProperty; import lombok.AllArgsConstructor; import lombok.Data; +import lombok.NonNull; +@NonNull @AllArgsConstructor @Data public class AnnotationPointProperties { diff --git a/classifai-core/src/main/java/ai/classifai/dto/DistanceToImageProperties.java b/classifai-core/src/main/java/ai/classifai/dto/DistanceToImageProperties.java index 5fdd380e..8f08615f 100644 --- a/classifai-core/src/main/java/ai/classifai/dto/DistanceToImageProperties.java +++ b/classifai-core/src/main/java/ai/classifai/dto/DistanceToImageProperties.java @@ -3,7 +3,9 @@ import com.fasterxml.jackson.annotation.JsonProperty; import lombok.AllArgsConstructor; import lombok.Data; +import lombok.NonNull; +@NonNull @AllArgsConstructor @Data public class DistanceToImageProperties { diff --git a/classifai-core/src/main/java/ai/classifai/dto/ProjectConfigProperties.java b/classifai-core/src/main/java/ai/classifai/dto/ProjectConfigProperties.java index 363f2c74..22116f03 100644 --- a/classifai-core/src/main/java/ai/classifai/dto/ProjectConfigProperties.java +++ b/classifai-core/src/main/java/ai/classifai/dto/ProjectConfigProperties.java @@ -3,9 +3,11 @@ import com.fasterxml.jackson.annotation.JsonProperty; import lombok.Data; import lombok.NoArgsConstructor; +import lombok.NonNull; import java.util.HashMap; +@NonNull @NoArgsConstructor @Data public class ProjectConfigProperties { diff --git a/classifai-core/src/main/java/ai/classifai/dto/ProjectMetaProperties.java b/classifai-core/src/main/java/ai/classifai/dto/ProjectMetaProperties.java index de13da17..61a7d310 100644 --- a/classifai-core/src/main/java/ai/classifai/dto/ProjectMetaProperties.java +++ b/classifai-core/src/main/java/ai/classifai/dto/ProjectMetaProperties.java @@ -4,7 +4,9 @@ import com.fasterxml.jackson.annotation.JsonProperty; import lombok.AllArgsConstructor; import lombok.Data; +import lombok.NonNull; +@NonNull @AllArgsConstructor @Data public class ProjectMetaProperties { diff --git a/classifai-core/src/main/java/ai/classifai/dto/ThumbnailProperties.java b/classifai-core/src/main/java/ai/classifai/dto/ThumbnailProperties.java index 35f94c6a..54da0fec 100644 --- a/classifai-core/src/main/java/ai/classifai/dto/ThumbnailProperties.java +++ b/classifai-core/src/main/java/ai/classifai/dto/ThumbnailProperties.java @@ -4,6 +4,7 @@ import com.fasterxml.jackson.annotation.JsonProperty; import lombok.Data; import lombok.NoArgsConstructor; +import lombok.NonNull; import java.util.List; @@ -11,12 +12,18 @@ @Data public class ThumbnailProperties { + @JsonProperty + int message = 1; + + @NonNull @JsonProperty("uuid") String uuidParam; + @NonNull @JsonProperty("project_name") String projectNameParam; + @NonNull @JsonProperty("img_path") String imgPathParam; @@ -28,30 +35,39 @@ public class ThumbnailProperties { @JsonProperty("bnd_box") List boundingBoxParam; + @NonNull @JsonProperty("img_depth") Integer imgDepth; + @NonNull @JsonProperty("img_x") Integer imgXParam; + @NonNull @JsonProperty("img_y") Integer imgYParam; + @NonNull @JsonProperty("img_w") Integer imgWParam; + @NonNull @JsonProperty("img_h") Integer imgHParam; + @NonNull @JsonProperty("file_size") Integer fileSizeParam; + @NonNull @JsonProperty("img_ori_w") Integer imgOriWParam; + @NonNull @JsonProperty("img_ori_h") Integer imgOriHParam; + @NonNull @JsonProperty("img_thumbnail") String imgThumbnailParam; } diff --git a/classifai-core/src/main/java/ai/classifai/dto/VersionConfigProperties.java b/classifai-core/src/main/java/ai/classifai/dto/VersionConfigProperties.java index 6c2e1461..c97b5a00 100644 --- a/classifai-core/src/main/java/ai/classifai/dto/VersionConfigProperties.java +++ b/classifai-core/src/main/java/ai/classifai/dto/VersionConfigProperties.java @@ -3,10 +3,12 @@ import com.fasterxml.jackson.annotation.JsonProperty; import lombok.Data; import lombok.NoArgsConstructor; +import lombok.NonNull; import java.util.HashMap; import java.util.List; +@NonNull @NoArgsConstructor @Data public class VersionConfigProperties { From 1e6d769b759c8805fac9353c0beecfdd8bc99fa7 Mon Sep 17 00:00:00 2001 From: devenyantis Date: Wed, 22 Sep 2021 01:18:48 +0800 Subject: [PATCH 09/16] :recycle: Change to builder & clean --- .../ai/classifai/action/ProjectExport.java | 6 +- .../action/parser/PortfolioParser.java | 41 +++------ .../action/parser/ProjectParser.java | 32 +++---- .../database/portfolio/PortfolioVerticle.java | 90 +++++++++---------- .../dto/AnnotationConfigProperties.java | 4 +- .../dto/AnnotationPointProperties.java | 4 +- .../dto/DistanceToImageProperties.java | 4 +- .../dto/ProjectConfigProperties.java | 4 +- .../classifai/dto/ProjectMetaProperties.java | 4 +- .../ai/classifai/dto/ThumbnailProperties.java | 4 +- .../dto/VersionConfigProperties.java | 4 +- 11 files changed, 86 insertions(+), 111 deletions(-) diff --git a/classifai-core/src/main/java/ai/classifai/action/ProjectExport.java b/classifai-core/src/main/java/ai/classifai/action/ProjectExport.java index cd590689..a3448b40 100644 --- a/classifai-core/src/main/java/ai/classifai/action/ProjectExport.java +++ b/classifai-core/src/main/java/ai/classifai/action/ProjectExport.java @@ -20,12 +20,10 @@ import ai.classifai.dto.AnnotationConfigProperties; import ai.classifai.dto.ProjectConfigProperties; import ai.classifai.loader.ProjectLoader; -import ai.classifai.util.ParamConfig; import ai.classifai.util.data.ImageHandler; import ai.classifai.util.datetime.DateTime; import ai.classifai.util.project.ProjectHandler; import com.fasterxml.jackson.databind.ObjectMapper; -import io.vertx.core.json.JsonObject; import io.vertx.sqlclient.Row; import io.vertx.sqlclient.RowSet; import lombok.*; @@ -73,9 +71,9 @@ public static String exportToFile(@NonNull String projectId, @NonNull ProjectCon FileWriter file = new FileWriter(configPath); ObjectMapper mp = new ObjectMapper(); - String jsonString = mp.writeValueAsString(configProperties); + String jsonString = mp.writerWithDefaultPrettyPrinter().writeValueAsString(configProperties); - file.write(new JsonObject(jsonString).encodePrettily()); + file.write(jsonString); file.close(); diff --git a/classifai-core/src/main/java/ai/classifai/action/parser/PortfolioParser.java b/classifai-core/src/main/java/ai/classifai/action/parser/PortfolioParser.java index d83f89ee..a3d879ae 100644 --- a/classifai-core/src/main/java/ai/classifai/action/parser/PortfolioParser.java +++ b/classifai-core/src/main/java/ai/classifai/action/parser/PortfolioParser.java @@ -55,34 +55,19 @@ public static ProjectConfigProperties parseOut(@NonNull Row row) { String annotationName = AnnotationHandler.getType(row.getInteger(2)).name(); -// jsonObject.put(ParamConfig.getProjectIdParam(), row.getString(0)); //project_id -// jsonObject.put(ParamConfig.getProjectNameParam(), row.getString(1)); //project_name -// jsonObject.put(ParamConfig.getAnnotationTypeParam(), annotationName.toLowerCase(Locale.ROOT)); //annotation_type (in string) -// -// jsonObject.put(ParamConfig.getProjectPathParam(), row.getString(3)); //project_path -// jsonObject.put(ParamConfig.getIsNewParam(), row.getBoolean(4)); //is_new -// jsonObject.put(ParamConfig.getIsStarredParam(), row.getBoolean(5)); //is_starred -// -// jsonObject.put(ParamConfig.getProjectInfraParam(), row.getString(6).toLowerCase()); //project_infra -// jsonObject.put(ParamConfig.getCurrentVersionParam(), row.getString(7)); //current version -// jsonObject.put(ParamConfig.getProjectVersionParam(), row.getString(8)); //project version -// jsonObject.put(ParamConfig.getUuidVersionListParam(), row.getString(9)); //uuid_version_list -// jsonObject.put(ParamConfig.getLabelVersionListParam(), row.getString(10)); //label_version_list - - ProjectConfigProperties config = new ProjectConfigProperties(); - config.setProjectID(row.getString(0)); - config.setProjectName(row.getString(1)); - config.setAnnotationType(annotationName.toLowerCase(Locale.ROOT)); - config.setProjectPath(row.getString(3)); - config.setIsNew(row.getBoolean(4)); - config.setIsStarred(row.getBoolean(5)); - config.setProjectInfra(row.getString(6).toLowerCase()); - config.setCurrentVersion(row.getString(7)); - config.setProjectVersion(row.getString(8)); - config.setUuidVersionList(row.getString(9)); - config.setLabelVersionList(row.getString(10)); - - return config; + return ProjectConfigProperties.builder() + .projectID(row.getString(0)) + .projectName(row.getString(1)) + .annotationType(annotationName.toLowerCase(Locale.ROOT)) + .projectPath(row.getString(3)) + .isNew(row.getBoolean(4)) + .isStarred(row.getBoolean(5)) + .projectInfra(row.getString(6).toLowerCase()) + .currentVersion(row.getString(7)) + .projectVersion(row.getString(8)) + .uuidVersionList(row.getString(9)) + .labelVersionList(row.getString(10)) + .build(); } diff --git a/classifai-core/src/main/java/ai/classifai/action/parser/ProjectParser.java b/classifai-core/src/main/java/ai/classifai/action/parser/ProjectParser.java index 50ef20fa..d5e09da6 100644 --- a/classifai-core/src/main/java/ai/classifai/action/parser/ProjectParser.java +++ b/classifai-core/src/main/java/ai/classifai/action/parser/ProjectParser.java @@ -62,24 +62,15 @@ public static HashMap parseOut(@NonNull Stri String hash = Hash.getHash256String(new File(fullPath)); -// JsonObject annotationJsonObject = new JsonObject() -// .put(ParamConfig.getCheckSumParam(), hash) -// .put(ParamConfig.getImgPathParam(), imgPath) //img_path -// .put(ParamConfig.getVersionListParam(), new JsonArray(row.getString(2))) //version_list -// .put(ParamConfig.getImgDepth(), row.getInteger(3)) //img_depth -// .put(ParamConfig.getImgOriWParam(), row.getInteger(4)) //img_ori_w -// .put(ParamConfig.getImgOriHParam(), row.getInteger(5)) //img_ori_h -// .put(ParamConfig.getFileSizeParam(), row.getInteger(6)); - - AnnotationConfigProperties config = new AnnotationConfigProperties( - hash, - imgPath, - getVersionList(row.getString(2)), - row.getInteger(3), - row.getInteger(4), - row.getInteger(5), - row.getInteger(6) - ); + AnnotationConfigProperties config = AnnotationConfigProperties.builder() + .checksum(hash) + .imgPath(imgPath) + .versionList(getVersionList(row.getString(2))) + .imgDepth(row.getInteger(3)) + .imgOriW(row.getInteger(4)) + .imgOriH(row.getInteger(5)) + .fileSize(row.getInteger(6)) + .build(); //uuid, version, content content.put(row.getString(0), config); @@ -97,8 +88,9 @@ private static List getVersionList(String versionListSt for(int i=0; i < versionListArray.size(); ++i) { JsonObject jsonAnnotation = versionListArray.getJsonObject(i); - VersionConfigProperties versionConfig = new VersionConfigProperties(); - versionConfig.setVersionUuid(jsonAnnotation.getString(ParamConfig.getVersionUuidParam())); + VersionConfigProperties versionConfig = VersionConfigProperties.builder() + .versionUuid(jsonAnnotation.getString(ParamConfig.getVersionUuidParam())) + .build(); JsonArray annotationConfigArray = jsonAnnotation.getJsonObject(ParamConfig.getAnnotationDataParam()) .getJsonArray(ParamConfig.getAnnotationParam()); List annotationPoints = new ArrayList<>(); diff --git a/classifai-core/src/main/java/ai/classifai/database/portfolio/PortfolioVerticle.java b/classifai-core/src/main/java/ai/classifai/database/portfolio/PortfolioVerticle.java index ff2d7559..199d643b 100644 --- a/classifai-core/src/main/java/ai/classifai/database/portfolio/PortfolioVerticle.java +++ b/classifai-core/src/main/java/ai/classifai/database/portfolio/PortfolioVerticle.java @@ -442,20 +442,22 @@ public static void getProjectMetadata(@NonNull List resul List existingDataInDir = ImageHandler.getValidImagesFromFolder(projectPath); - result.add(new ProjectMetaProperties( - loader.getProjectName(), - loader.getProjectPath().getAbsolutePath(), - loader.getIsProjectNew(), - loader.getIsProjectStarred(), - loader.getIsLoadedFrontEndToggle(), - loader.isCloud(), - loader.getProjectInfra(), - currentVersion.getCreatedDate().toString(), - currentVersion.getLastModifiedDate().toString(), - currentVersion.getVersionUuid(), - existingDataInDir.size(), - projectPath.exists() - )); + result.add(ProjectMetaProperties.builder() + .projectName(loader.getProjectName()) + .projectPath(loader.getProjectPath().getAbsolutePath()) + .isNewParam(loader.getIsProjectNew()) + .isStarredParam(loader.getIsProjectStarred()) + .isLoadedParam(loader.getIsLoadedFrontEndToggle()) + .isCloud(loader.isCloud()) + .projectInfraParam(loader.getProjectInfra()) + .createdDateParam(currentVersion.getCreatedDate().toString()) + .lastModifiedDate(currentVersion.getLastModifiedDate().toString()) + .currentVersionParam(currentVersion.getVersionUuid()) + .totalUuidParam(existingDataInDir.size()) + .isRootPathValidParam(projectPath.exists()) + .build() + ); + } /** @@ -615,7 +617,20 @@ public static ThumbnailProperties queryData(String projectId, String uuid, @NonN } } - ThumbnailProperties thmbProps = new ThumbnailProperties(); + ThumbnailProperties thmbProps = ThumbnailProperties.builder() + .uuidParam(uuid) + .projectNameParam(loader.getProjectName()) + .imgPathParam(dataPath) + .imgDepth(Integer.parseInt(imgData.get(ParamConfig.getImgDepth()))) + .imgXParam(version.getImgX()) + .imgYParam(version.getImgY()) + .imgWParam(version.getImgW()) + .imgHParam(version.getImgH()) + .fileSizeParam(annotation.getFileSize()) + .imgOriWParam(Integer.parseInt(imgData.get(ParamConfig.getImgOriWParam()))) + .imgOriHParam(Integer.parseInt(imgData.get(ParamConfig.getImgOriHParam()))) + .imgThumbnailParam(imgData.get(ParamConfig.getBase64Param())) + .build(); if(annotationKey.equals(ParamConfig.getBoundingBoxParam())) { thmbProps.setBoundingBoxParam(getAnnotations(version)); @@ -623,19 +638,6 @@ public static ThumbnailProperties queryData(String projectId, String uuid, @NonN thmbProps.setSegmentationParam(getAnnotations(version)); } - thmbProps.setUuidParam(uuid); - thmbProps.setProjectNameParam(loader.getProjectName()); - thmbProps.setImgPathParam(dataPath); - thmbProps.setImgDepth(Integer.parseInt(imgData.get(ParamConfig.getImgDepth()))); - thmbProps.setImgXParam(version.getImgX()); - thmbProps.setImgYParam(version.getImgY()); - thmbProps.setImgWParam(version.getImgW()); - thmbProps.setImgHParam(version.getImgH()); - thmbProps.setFileSizeParam(annotation.getFileSize()); - thmbProps.setImgOriWParam(Integer.parseInt(imgData.get(ParamConfig.getImgOriWParam()))); - thmbProps.setImgOriHParam(Integer.parseInt(imgData.get(ParamConfig.getImgOriHParam()))); - thmbProps.setImgThumbnailParam(imgData.get(ParamConfig.getBase64Param())); - return thmbProps; } @@ -655,25 +657,23 @@ public static AnnotationPointProperties getAnnotations(JsonObject jsonAnnotation JsonObject jsonDistToImg = jsonAnnotation.getJsonObject("distancetoImg"); // Get distance to image - DistanceToImageProperties distanceToImg = new DistanceToImageProperties( - jsonDistToImg.getInteger("x"), - jsonDistToImg.getInteger("y") - ); + DistanceToImageProperties distanceToImg = DistanceToImageProperties.builder() + .x(jsonDistToImg.getInteger("x")) + .y(jsonDistToImg.getInteger("y")) + .build(); // Get Annotation point - AnnotationPointProperties annotationPoint = new AnnotationPointProperties( - jsonAnnotation.getInteger("x1"), - jsonAnnotation.getInteger("y1"), - jsonAnnotation.getInteger("x2"), - jsonAnnotation.getInteger("y2"), - jsonAnnotation.getInteger("lineWidth"), - jsonAnnotation.getString("color"), - distanceToImg, - jsonAnnotation.getString("label"), - jsonAnnotation.getString("id") - ); - - return annotationPoint; + return AnnotationPointProperties.builder() + .x1(jsonAnnotation.getInteger("x1")) + .y1(jsonAnnotation.getInteger("y1")) + .x2(jsonAnnotation.getInteger("x2")) + .y2(jsonAnnotation.getInteger("y2")) + .lineWidth(jsonAnnotation.getInteger("lineWidth")) + .color(jsonAnnotation.getString("color")) + .distancetoImg(distanceToImg) + .label(jsonAnnotation.getString("label")) + .id(jsonAnnotation.getString("id")) + .build(); } diff --git a/classifai-core/src/main/java/ai/classifai/dto/AnnotationConfigProperties.java b/classifai-core/src/main/java/ai/classifai/dto/AnnotationConfigProperties.java index e4bf237a..8368d1ca 100644 --- a/classifai-core/src/main/java/ai/classifai/dto/AnnotationConfigProperties.java +++ b/classifai-core/src/main/java/ai/classifai/dto/AnnotationConfigProperties.java @@ -1,14 +1,14 @@ package ai.classifai.dto; import com.fasterxml.jackson.annotation.JsonProperty; -import lombok.AllArgsConstructor; +import lombok.Builder; import lombok.Data; import lombok.NonNull; import java.util.List; @NonNull -@AllArgsConstructor +@Builder @Data public class AnnotationConfigProperties { @JsonProperty diff --git a/classifai-core/src/main/java/ai/classifai/dto/AnnotationPointProperties.java b/classifai-core/src/main/java/ai/classifai/dto/AnnotationPointProperties.java index e44f83d5..76a84559 100644 --- a/classifai-core/src/main/java/ai/classifai/dto/AnnotationPointProperties.java +++ b/classifai-core/src/main/java/ai/classifai/dto/AnnotationPointProperties.java @@ -1,12 +1,12 @@ package ai.classifai.dto; import com.fasterxml.jackson.annotation.JsonProperty; -import lombok.AllArgsConstructor; +import lombok.Builder; import lombok.Data; import lombok.NonNull; @NonNull -@AllArgsConstructor +@Builder @Data public class AnnotationPointProperties { @JsonProperty diff --git a/classifai-core/src/main/java/ai/classifai/dto/DistanceToImageProperties.java b/classifai-core/src/main/java/ai/classifai/dto/DistanceToImageProperties.java index 8f08615f..dcff4cb4 100644 --- a/classifai-core/src/main/java/ai/classifai/dto/DistanceToImageProperties.java +++ b/classifai-core/src/main/java/ai/classifai/dto/DistanceToImageProperties.java @@ -1,12 +1,12 @@ package ai.classifai.dto; import com.fasterxml.jackson.annotation.JsonProperty; -import lombok.AllArgsConstructor; +import lombok.Builder; import lombok.Data; import lombok.NonNull; @NonNull -@AllArgsConstructor +@Builder @Data public class DistanceToImageProperties { @JsonProperty diff --git a/classifai-core/src/main/java/ai/classifai/dto/ProjectConfigProperties.java b/classifai-core/src/main/java/ai/classifai/dto/ProjectConfigProperties.java index 22116f03..bb9f4427 100644 --- a/classifai-core/src/main/java/ai/classifai/dto/ProjectConfigProperties.java +++ b/classifai-core/src/main/java/ai/classifai/dto/ProjectConfigProperties.java @@ -1,14 +1,14 @@ package ai.classifai.dto; import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.Builder; import lombok.Data; -import lombok.NoArgsConstructor; import lombok.NonNull; import java.util.HashMap; @NonNull -@NoArgsConstructor +@Builder @Data public class ProjectConfigProperties { @JsonProperty("tool") diff --git a/classifai-core/src/main/java/ai/classifai/dto/ProjectMetaProperties.java b/classifai-core/src/main/java/ai/classifai/dto/ProjectMetaProperties.java index 61a7d310..54d4fd5d 100644 --- a/classifai-core/src/main/java/ai/classifai/dto/ProjectMetaProperties.java +++ b/classifai-core/src/main/java/ai/classifai/dto/ProjectMetaProperties.java @@ -2,12 +2,12 @@ import ai.classifai.util.project.ProjectInfra; import com.fasterxml.jackson.annotation.JsonProperty; -import lombok.AllArgsConstructor; +import lombok.Builder; import lombok.Data; import lombok.NonNull; @NonNull -@AllArgsConstructor +@Builder @Data public class ProjectMetaProperties { @JsonProperty("project_name") diff --git a/classifai-core/src/main/java/ai/classifai/dto/ThumbnailProperties.java b/classifai-core/src/main/java/ai/classifai/dto/ThumbnailProperties.java index 54da0fec..1ac613b8 100644 --- a/classifai-core/src/main/java/ai/classifai/dto/ThumbnailProperties.java +++ b/classifai-core/src/main/java/ai/classifai/dto/ThumbnailProperties.java @@ -2,13 +2,13 @@ import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.Builder; import lombok.Data; -import lombok.NoArgsConstructor; import lombok.NonNull; import java.util.List; -@NoArgsConstructor +@Builder @Data public class ThumbnailProperties { diff --git a/classifai-core/src/main/java/ai/classifai/dto/VersionConfigProperties.java b/classifai-core/src/main/java/ai/classifai/dto/VersionConfigProperties.java index c97b5a00..fe0dc055 100644 --- a/classifai-core/src/main/java/ai/classifai/dto/VersionConfigProperties.java +++ b/classifai-core/src/main/java/ai/classifai/dto/VersionConfigProperties.java @@ -1,15 +1,15 @@ package ai.classifai.dto; import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.Builder; import lombok.Data; -import lombok.NoArgsConstructor; import lombok.NonNull; import java.util.HashMap; import java.util.List; @NonNull -@NoArgsConstructor +@Builder @Data public class VersionConfigProperties { @JsonProperty("version_uuid") From a2035b262a85fc44ad6223e65dd3666c86b8d28f Mon Sep 17 00:00:00 2001 From: devenyantis Date: Wed, 22 Sep 2021 01:54:22 +0800 Subject: [PATCH 10/16] :recycle: Fix code smell --- .../src/main/java/ai/classifai/action/ProjectExport.java | 4 ++-- .../java/ai/classifai/action/parser/ProjectParser.java | 8 ++++---- .../java/ai/classifai/dto/ProjectConfigProperties.java | 4 ++-- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/classifai-core/src/main/java/ai/classifai/action/ProjectExport.java b/classifai-core/src/main/java/ai/classifai/action/ProjectExport.java index a3448b40..dc318309 100644 --- a/classifai-core/src/main/java/ai/classifai/action/ProjectExport.java +++ b/classifai-core/src/main/java/ai/classifai/action/ProjectExport.java @@ -31,8 +31,8 @@ import java.io.*; import java.nio.file.Paths; -import java.util.HashMap; import java.util.List; +import java.util.Map; import java.util.Objects; import java.util.zip.ZipEntry; import java.util.zip.ZipOutputStream; @@ -162,7 +162,7 @@ public static ProjectConfigProperties getConfigContent(@NonNull RowSet rowS return null; } - HashMap configProperties = ProjectParser.parseOut( + Map configProperties = ProjectParser.parseOut( projectConfig.getProjectPath(), projectRowSet.iterator()); projectConfig.setContent(configProperties); diff --git a/classifai-core/src/main/java/ai/classifai/action/parser/ProjectParser.java b/classifai-core/src/main/java/ai/classifai/action/parser/ProjectParser.java index d5e09da6..6a08e741 100644 --- a/classifai-core/src/main/java/ai/classifai/action/parser/ProjectParser.java +++ b/classifai-core/src/main/java/ai/classifai/action/parser/ProjectParser.java @@ -48,7 +48,7 @@ @NoArgsConstructor(access = AccessLevel.PRIVATE) public class ProjectParser { - public static HashMap parseOut(@NonNull String projectPath, @NonNull RowIterator rowIterator) + public static Map parseOut(@NonNull String projectPath, @NonNull RowIterator rowIterator) { HashMap content = new HashMap<>(); @@ -98,9 +98,9 @@ private static List getVersionList(String versionListSt JsonObject jsonAnnotationConfig = annotationConfigArray.getJsonObject(j); annotationPoints.add(PortfolioVerticle.getAnnotations(jsonAnnotationConfig)); } - versionConfig.setAnnotationData(new HashMap<>() {{ - put("annotation", annotationPoints); - }}); + HashMap> annotationData = new HashMap<>(); + annotationData.put("annotation", annotationPoints); + versionConfig.setAnnotationData(annotationData); } return config; diff --git a/classifai-core/src/main/java/ai/classifai/dto/ProjectConfigProperties.java b/classifai-core/src/main/java/ai/classifai/dto/ProjectConfigProperties.java index bb9f4427..e3fd8cfc 100644 --- a/classifai-core/src/main/java/ai/classifai/dto/ProjectConfigProperties.java +++ b/classifai-core/src/main/java/ai/classifai/dto/ProjectConfigProperties.java @@ -5,7 +5,7 @@ import lombok.Data; import lombok.NonNull; -import java.util.HashMap; +import java.util.Map; @NonNull @Builder @@ -54,5 +54,5 @@ public class ProjectConfigProperties { String labelVersionList; @JsonProperty - HashMap content; + Map content; } From a7582414ef7e709e18bed99d56959ab68b96a6b6 Mon Sep 17 00:00:00 2001 From: devenyantis Date: Wed, 22 Sep 2021 04:27:03 +0800 Subject: [PATCH 11/16] :recycle: Fix export config content --- .../ai/classifai/action/ProjectExport.java | 4 +-- .../action/parser/ProjectParser.java | 35 ++++++++++++------- .../database/portfolio/PortfolioVerticle.java | 2 +- .../ai/classifai/dto/DataInfoProperties.java | 29 +++++++++++++++ ...operties.java => ImageDataProperties.java} | 2 +- .../dto/ProjectConfigProperties.java | 2 +- .../ai/classifai/dto/ThumbnailProperties.java | 2 +- .../dto/VersionConfigProperties.java | 5 +-- 8 files changed, 58 insertions(+), 23 deletions(-) create mode 100644 classifai-core/src/main/java/ai/classifai/dto/DataInfoProperties.java rename classifai-core/src/main/java/ai/classifai/dto/{AnnotationConfigProperties.java => ImageDataProperties.java} (93%) diff --git a/classifai-core/src/main/java/ai/classifai/action/ProjectExport.java b/classifai-core/src/main/java/ai/classifai/action/ProjectExport.java index dc318309..f377c695 100644 --- a/classifai-core/src/main/java/ai/classifai/action/ProjectExport.java +++ b/classifai-core/src/main/java/ai/classifai/action/ProjectExport.java @@ -17,7 +17,7 @@ import ai.classifai.action.parser.PortfolioParser; import ai.classifai.action.parser.ProjectParser; -import ai.classifai.dto.AnnotationConfigProperties; +import ai.classifai.dto.ImageDataProperties; import ai.classifai.dto.ProjectConfigProperties; import ai.classifai.loader.ProjectLoader; import ai.classifai.util.data.ImageHandler; @@ -162,7 +162,7 @@ public static ProjectConfigProperties getConfigContent(@NonNull RowSet rowS return null; } - Map configProperties = ProjectParser.parseOut( + Map configProperties = ProjectParser.parseOut( projectConfig.getProjectPath(), projectRowSet.iterator()); projectConfig.setContent(configProperties); diff --git a/classifai-core/src/main/java/ai/classifai/action/parser/ProjectParser.java b/classifai-core/src/main/java/ai/classifai/action/parser/ProjectParser.java index 6a08e741..85828b86 100644 --- a/classifai-core/src/main/java/ai/classifai/action/parser/ProjectParser.java +++ b/classifai-core/src/main/java/ai/classifai/action/parser/ProjectParser.java @@ -19,7 +19,8 @@ import ai.classifai.database.portfolio.PortfolioVerticle; import ai.classifai.database.versioning.Annotation; import ai.classifai.database.versioning.AnnotationVersion; -import ai.classifai.dto.AnnotationConfigProperties; +import ai.classifai.dto.DataInfoProperties; +import ai.classifai.dto.ImageDataProperties; import ai.classifai.dto.AnnotationPointProperties; import ai.classifai.dto.VersionConfigProperties; import ai.classifai.loader.ProjectLoader; @@ -48,9 +49,9 @@ @NoArgsConstructor(access = AccessLevel.PRIVATE) public class ProjectParser { - public static Map parseOut(@NonNull String projectPath, @NonNull RowIterator rowIterator) + public static Map parseOut(@NonNull String projectPath, @NonNull RowIterator rowIterator) { - HashMap content = new HashMap<>(); + HashMap content = new HashMap<>(); while(rowIterator.hasNext()) { @@ -62,7 +63,7 @@ public static Map parseOut(@NonNull String p String hash = Hash.getHash256String(new File(fullPath)); - AnnotationConfigProperties config = AnnotationConfigProperties.builder() + ImageDataProperties config = ImageDataProperties.builder() .checksum(hash) .imgPath(imgPath) .versionList(getVersionList(row.getString(2))) @@ -87,20 +88,28 @@ private static List getVersionList(String versionListSt for(int i=0; i < versionListArray.size(); ++i) { JsonObject jsonAnnotation = versionListArray.getJsonObject(i); - - VersionConfigProperties versionConfig = VersionConfigProperties.builder() - .versionUuid(jsonAnnotation.getString(ParamConfig.getVersionUuidParam())) - .build(); - JsonArray annotationConfigArray = jsonAnnotation.getJsonObject(ParamConfig.getAnnotationDataParam()) - .getJsonArray(ParamConfig.getAnnotationParam()); + JsonObject annotationConfig = jsonAnnotation.getJsonObject(ParamConfig.getAnnotationDataParam()); + JsonArray annotationConfigArray = annotationConfig.getJsonArray(ParamConfig.getAnnotationParam()); List annotationPoints = new ArrayList<>(); for(int j=0; j < annotationConfigArray.size(); ++j) { JsonObject jsonAnnotationConfig = annotationConfigArray.getJsonObject(j); annotationPoints.add(PortfolioVerticle.getAnnotations(jsonAnnotationConfig)); } - HashMap> annotationData = new HashMap<>(); - annotationData.put("annotation", annotationPoints); - versionConfig.setAnnotationData(annotationData); + + DataInfoProperties annotationData = DataInfoProperties.builder() + .annotation(annotationPoints) + .imgX(annotationConfig.getInteger(ParamConfig.getImgXParam())) + .imgY(annotationConfig.getInteger(ParamConfig.getImgYParam())) + .imgW(annotationConfig.getInteger(ParamConfig.getImgWParam())) + .imgH(annotationConfig.getInteger(ParamConfig.getImgHParam())) + .build(); + + VersionConfigProperties versionConfig = VersionConfigProperties.builder() + .versionUuid(jsonAnnotation.getString(ParamConfig.getVersionUuidParam())) + .annotationData(annotationData) + .build(); + + config.add(versionConfig); } return config; diff --git a/classifai-core/src/main/java/ai/classifai/database/portfolio/PortfolioVerticle.java b/classifai-core/src/main/java/ai/classifai/database/portfolio/PortfolioVerticle.java index 199d643b..6cf9aab3 100644 --- a/classifai-core/src/main/java/ai/classifai/database/portfolio/PortfolioVerticle.java +++ b/classifai-core/src/main/java/ai/classifai/database/portfolio/PortfolioVerticle.java @@ -580,7 +580,6 @@ public static ThumbnailProperties queryData(String projectId, String uuid, @NonN ProjectLoader loader = Objects.requireNonNull(ProjectHandler.getProjectLoader(projectId)); Annotation annotation = loader.getUuidAnnotationDict().get(uuid); AnnotationVersion version = annotation.getAnnotationDict().get(loader.getCurrentVersionUuid()); - Map imgData = new HashMap<>(); String dataPath = ""; @@ -618,6 +617,7 @@ public static ThumbnailProperties queryData(String projectId, String uuid, @NonN } ThumbnailProperties thmbProps = ThumbnailProperties.builder() + .message(1) .uuidParam(uuid) .projectNameParam(loader.getProjectName()) .imgPathParam(dataPath) diff --git a/classifai-core/src/main/java/ai/classifai/dto/DataInfoProperties.java b/classifai-core/src/main/java/ai/classifai/dto/DataInfoProperties.java new file mode 100644 index 00000000..8539bf0c --- /dev/null +++ b/classifai-core/src/main/java/ai/classifai/dto/DataInfoProperties.java @@ -0,0 +1,29 @@ +package ai.classifai.dto; + +import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.Builder; +import lombok.Data; +import lombok.NonNull; + +import java.util.List; + +@NonNull +@Builder +@Data +public class DataInfoProperties { + + @JsonProperty("annotation") + List annotation; + + @JsonProperty("img_x") + int imgX; + + @JsonProperty("img_y") + int imgY; + + @JsonProperty("img_w") + int imgW; + + @JsonProperty("img_h") + int imgH; +} diff --git a/classifai-core/src/main/java/ai/classifai/dto/AnnotationConfigProperties.java b/classifai-core/src/main/java/ai/classifai/dto/ImageDataProperties.java similarity index 93% rename from classifai-core/src/main/java/ai/classifai/dto/AnnotationConfigProperties.java rename to classifai-core/src/main/java/ai/classifai/dto/ImageDataProperties.java index 8368d1ca..3698aa16 100644 --- a/classifai-core/src/main/java/ai/classifai/dto/AnnotationConfigProperties.java +++ b/classifai-core/src/main/java/ai/classifai/dto/ImageDataProperties.java @@ -10,7 +10,7 @@ @NonNull @Builder @Data -public class AnnotationConfigProperties { +public class ImageDataProperties { @JsonProperty String checksum; diff --git a/classifai-core/src/main/java/ai/classifai/dto/ProjectConfigProperties.java b/classifai-core/src/main/java/ai/classifai/dto/ProjectConfigProperties.java index e3fd8cfc..4cc88f78 100644 --- a/classifai-core/src/main/java/ai/classifai/dto/ProjectConfigProperties.java +++ b/classifai-core/src/main/java/ai/classifai/dto/ProjectConfigProperties.java @@ -54,5 +54,5 @@ public class ProjectConfigProperties { String labelVersionList; @JsonProperty - Map content; + Map content; } diff --git a/classifai-core/src/main/java/ai/classifai/dto/ThumbnailProperties.java b/classifai-core/src/main/java/ai/classifai/dto/ThumbnailProperties.java index 1ac613b8..1fba5571 100644 --- a/classifai-core/src/main/java/ai/classifai/dto/ThumbnailProperties.java +++ b/classifai-core/src/main/java/ai/classifai/dto/ThumbnailProperties.java @@ -13,7 +13,7 @@ public class ThumbnailProperties { @JsonProperty - int message = 1; + int message; @NonNull @JsonProperty("uuid") diff --git a/classifai-core/src/main/java/ai/classifai/dto/VersionConfigProperties.java b/classifai-core/src/main/java/ai/classifai/dto/VersionConfigProperties.java index fe0dc055..a750c3d7 100644 --- a/classifai-core/src/main/java/ai/classifai/dto/VersionConfigProperties.java +++ b/classifai-core/src/main/java/ai/classifai/dto/VersionConfigProperties.java @@ -5,9 +5,6 @@ import lombok.Data; import lombok.NonNull; -import java.util.HashMap; -import java.util.List; - @NonNull @Builder @Data @@ -16,5 +13,5 @@ public class VersionConfigProperties { String versionUuid; @JsonProperty("annotation_data") - HashMap> annotationData; + DataInfoProperties annotationData; } From 32d4de5cf5c5f8c1d71d75dc8dcb70b70245db68 Mon Sep 17 00:00:00 2001 From: devenyantis Date: Thu, 23 Sep 2021 03:13:40 +0800 Subject: [PATCH 12/16] :recycle: Change json deserializer & add license --- .../action/parser/ProjectParser.java | 61 +++++++++++-------- .../database/portfolio/PortfolioVerticle.java | 40 ++++-------- .../dto/AnnotationPointProperties.java | 25 ++++++-- .../ai/classifai/dto/DataInfoProperties.java | 25 ++++++-- .../dto/DistanceToImageProperties.java | 25 ++++++-- .../ai/classifai/dto/ImageDataProperties.java | 25 ++++++-- .../dto/ProjectConfigProperties.java | 10 +-- .../classifai/dto/ProjectMetaProperties.java | 10 +-- .../ai/classifai/dto/ThumbnailProperties.java | 24 ++++++-- .../dto/VersionConfigProperties.java | 25 ++++++-- 10 files changed, 178 insertions(+), 92 deletions(-) diff --git a/classifai-core/src/main/java/ai/classifai/action/parser/ProjectParser.java b/classifai-core/src/main/java/ai/classifai/action/parser/ProjectParser.java index 85828b86..f698a17b 100644 --- a/classifai-core/src/main/java/ai/classifai/action/parser/ProjectParser.java +++ b/classifai-core/src/main/java/ai/classifai/action/parser/ProjectParser.java @@ -16,17 +16,19 @@ package ai.classifai.action.parser; import ai.classifai.database.annotation.AnnotationVerticle; -import ai.classifai.database.portfolio.PortfolioVerticle; import ai.classifai.database.versioning.Annotation; import ai.classifai.database.versioning.AnnotationVersion; +import ai.classifai.dto.AnnotationPointProperties; import ai.classifai.dto.DataInfoProperties; import ai.classifai.dto.ImageDataProperties; -import ai.classifai.dto.AnnotationPointProperties; import ai.classifai.dto.VersionConfigProperties; import ai.classifai.loader.ProjectLoader; import ai.classifai.util.Hash; import ai.classifai.util.ParamConfig; import ai.classifai.util.data.StringHandler; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.ObjectMapper; import io.vertx.core.json.JsonArray; import io.vertx.core.json.JsonObject; import io.vertx.sqlclient.Row; @@ -37,6 +39,8 @@ import lombok.extern.slf4j.Slf4j; import java.io.File; +import java.io.IOException; +import java.io.StringReader; import java.nio.file.Paths; import java.util.*; @@ -83,33 +87,40 @@ public static Map parseOut(@NonNull String projectP private static List getVersionList(String versionListString) { JsonArray versionListArray = new JsonArray(versionListString); - List config = new ArrayList<>(); + ObjectMapper mp = new ObjectMapper(); for(int i=0; i < versionListArray.size(); ++i) { - JsonObject jsonAnnotation = versionListArray.getJsonObject(i); - JsonObject annotationConfig = jsonAnnotation.getJsonObject(ParamConfig.getAnnotationDataParam()); - JsonArray annotationConfigArray = annotationConfig.getJsonArray(ParamConfig.getAnnotationParam()); - List annotationPoints = new ArrayList<>(); - for(int j=0; j < annotationConfigArray.size(); ++j) { - JsonObject jsonAnnotationConfig = annotationConfigArray.getJsonObject(j); - annotationPoints.add(PortfolioVerticle.getAnnotations(jsonAnnotationConfig)); + try { + JsonNode rootNode = mp.readTree(new StringReader(versionListArray.getJsonObject(i).toString())); + + List annotationPoints = new ArrayList<>(); + rootNode.path("annotation_data").path("annotation").forEach(node -> { + try { + annotationPoints.add(mp.readValue(node.toString(), AnnotationPointProperties.class)); + } catch (JsonProcessingException e) { + log.info("Fail to AnnotationPointProperties: " + e); + } + }); + + DataInfoProperties annotationData = DataInfoProperties.builder() + .annotation(annotationPoints) + .imgX(rootNode.path("annotation_data").path("img_x").intValue()) + .imgY(rootNode.path("annotation_data").path("img_y").intValue()) + .imgW(rootNode.path("annotation_data").path("img_w").intValue()) + .imgH(rootNode.path("annotation_data").path("img_h").intValue()) + .build(); + + VersionConfigProperties versionConfig = VersionConfigProperties.builder() + .versionUuid(rootNode.path("version_uuid").textValue()) + .annotationData(annotationData) + .build(); + + config.add(versionConfig); + + } catch (IOException e) { + log.info("Fail to convert string to object: " + e); } - - DataInfoProperties annotationData = DataInfoProperties.builder() - .annotation(annotationPoints) - .imgX(annotationConfig.getInteger(ParamConfig.getImgXParam())) - .imgY(annotationConfig.getInteger(ParamConfig.getImgYParam())) - .imgW(annotationConfig.getInteger(ParamConfig.getImgWParam())) - .imgH(annotationConfig.getInteger(ParamConfig.getImgHParam())) - .build(); - - VersionConfigProperties versionConfig = VersionConfigProperties.builder() - .versionUuid(jsonAnnotation.getString(ParamConfig.getVersionUuidParam())) - .annotationData(annotationData) - .build(); - - config.add(versionConfig); } return config; diff --git a/classifai-core/src/main/java/ai/classifai/database/portfolio/PortfolioVerticle.java b/classifai-core/src/main/java/ai/classifai/database/portfolio/PortfolioVerticle.java index 6cf9aab3..8cca5a2c 100644 --- a/classifai-core/src/main/java/ai/classifai/database/portfolio/PortfolioVerticle.java +++ b/classifai-core/src/main/java/ai/classifai/database/portfolio/PortfolioVerticle.java @@ -30,7 +30,10 @@ import ai.classifai.database.versioning.AnnotationVersion; import ai.classifai.database.versioning.ProjectVersion; import ai.classifai.database.versioning.Version; -import ai.classifai.dto.*; +import ai.classifai.dto.AnnotationPointProperties; +import ai.classifai.dto.ProjectConfigProperties; +import ai.classifai.dto.ProjectMetaProperties; +import ai.classifai.dto.ThumbnailProperties; import ai.classifai.loader.NameGenerator; import ai.classifai.loader.ProjectLoader; import ai.classifai.loader.ProjectLoaderStatus; @@ -49,6 +52,8 @@ import ai.classifai.util.type.database.H2; import ai.classifai.util.type.database.RelationalDb; import ai.classifai.wasabis3.WasabiImageHandler; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.ObjectMapper; import io.vertx.core.AbstractVerticle; import io.vertx.core.Promise; import io.vertx.core.Vertx; @@ -643,40 +648,19 @@ public static ThumbnailProperties queryData(String projectId, String uuid, @NonN private static List getAnnotations(AnnotationVersion version) { List versionAnnotations = new ArrayList<>(); + ObjectMapper mp = new ObjectMapper(); version.getAnnotation().forEach(arr -> { - JsonObject jsonAnnotation = (JsonObject) arr; - versionAnnotations.add(getAnnotations(jsonAnnotation)); + try { + versionAnnotations.add(mp.readValue(arr.toString(), AnnotationPointProperties.class)); + } catch (JsonProcessingException e) { + log.info("Fail convert to AnnotationPointProperties: " + e); + } }); return versionAnnotations; } - public static AnnotationPointProperties getAnnotations(JsonObject jsonAnnotation) { - - JsonObject jsonDistToImg = jsonAnnotation.getJsonObject("distancetoImg"); - - // Get distance to image - DistanceToImageProperties distanceToImg = DistanceToImageProperties.builder() - .x(jsonDistToImg.getInteger("x")) - .y(jsonDistToImg.getInteger("y")) - .build(); - - // Get Annotation point - return AnnotationPointProperties.builder() - .x1(jsonAnnotation.getInteger("x1")) - .y1(jsonAnnotation.getInteger("y1")) - .x2(jsonAnnotation.getInteger("x2")) - .y2(jsonAnnotation.getInteger("y2")) - .lineWidth(jsonAnnotation.getInteger("lineWidth")) - .color(jsonAnnotation.getString("color")) - .distancetoImg(distanceToImg) - .label(jsonAnnotation.getString("label")) - .id(jsonAnnotation.getString("id")) - .build(); - - } - public static String getAnnotationKey(ProjectLoader loader) { if(loader.getAnnotationType().equals(AnnotationType.BOUNDINGBOX.ordinal())) { return ParamConfig.getBoundingBoxParam(); diff --git a/classifai-core/src/main/java/ai/classifai/dto/AnnotationPointProperties.java b/classifai-core/src/main/java/ai/classifai/dto/AnnotationPointProperties.java index 76a84559..f61753cc 100644 --- a/classifai-core/src/main/java/ai/classifai/dto/AnnotationPointProperties.java +++ b/classifai-core/src/main/java/ai/classifai/dto/AnnotationPointProperties.java @@ -1,13 +1,28 @@ +/* + * Copyright (c) 2021 CertifAI Sdn. Bhd. + * + * This program and the accompanying materials are made available under the + * terms of the Apache License, Version 2.0 which is available at + * https://www.apache.org/licenses/LICENSE-2.0. + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + * SPDX-License-Identifier: Apache-2.0 + */ package ai.classifai.dto; import com.fasterxml.jackson.annotation.JsonProperty; -import lombok.Builder; -import lombok.Data; -import lombok.NonNull; +import lombok.*; -@NonNull -@Builder @Data +@Builder +@NoArgsConstructor +@AllArgsConstructor +@NonNull public class AnnotationPointProperties { @JsonProperty Integer x1; diff --git a/classifai-core/src/main/java/ai/classifai/dto/DataInfoProperties.java b/classifai-core/src/main/java/ai/classifai/dto/DataInfoProperties.java index 8539bf0c..dd9432e0 100644 --- a/classifai-core/src/main/java/ai/classifai/dto/DataInfoProperties.java +++ b/classifai-core/src/main/java/ai/classifai/dto/DataInfoProperties.java @@ -1,15 +1,30 @@ +/* + * Copyright (c) 2021 CertifAI Sdn. Bhd. + * + * This program and the accompanying materials are made available under the + * terms of the Apache License, Version 2.0 which is available at + * https://www.apache.org/licenses/LICENSE-2.0. + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + * SPDX-License-Identifier: Apache-2.0 + */ package ai.classifai.dto; import com.fasterxml.jackson.annotation.JsonProperty; -import lombok.Builder; -import lombok.Data; -import lombok.NonNull; +import lombok.*; import java.util.List; -@NonNull -@Builder @Data +@Builder +@NoArgsConstructor +@AllArgsConstructor +@NonNull public class DataInfoProperties { @JsonProperty("annotation") diff --git a/classifai-core/src/main/java/ai/classifai/dto/DistanceToImageProperties.java b/classifai-core/src/main/java/ai/classifai/dto/DistanceToImageProperties.java index dcff4cb4..589cfc52 100644 --- a/classifai-core/src/main/java/ai/classifai/dto/DistanceToImageProperties.java +++ b/classifai-core/src/main/java/ai/classifai/dto/DistanceToImageProperties.java @@ -1,13 +1,28 @@ +/* + * Copyright (c) 2021 CertifAI Sdn. Bhd. + * + * This program and the accompanying materials are made available under the + * terms of the Apache License, Version 2.0 which is available at + * https://www.apache.org/licenses/LICENSE-2.0. + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + * SPDX-License-Identifier: Apache-2.0 + */ package ai.classifai.dto; import com.fasterxml.jackson.annotation.JsonProperty; -import lombok.Builder; -import lombok.Data; -import lombok.NonNull; +import lombok.*; -@NonNull -@Builder @Data +@Builder +@NoArgsConstructor +@AllArgsConstructor +@NonNull public class DistanceToImageProperties { @JsonProperty Integer x; diff --git a/classifai-core/src/main/java/ai/classifai/dto/ImageDataProperties.java b/classifai-core/src/main/java/ai/classifai/dto/ImageDataProperties.java index 3698aa16..ff695634 100644 --- a/classifai-core/src/main/java/ai/classifai/dto/ImageDataProperties.java +++ b/classifai-core/src/main/java/ai/classifai/dto/ImageDataProperties.java @@ -1,15 +1,30 @@ +/* + * Copyright (c) 2021 CertifAI Sdn. Bhd. + * + * This program and the accompanying materials are made available under the + * terms of the Apache License, Version 2.0 which is available at + * https://www.apache.org/licenses/LICENSE-2.0. + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + * SPDX-License-Identifier: Apache-2.0 + */ package ai.classifai.dto; import com.fasterxml.jackson.annotation.JsonProperty; -import lombok.Builder; -import lombok.Data; -import lombok.NonNull; +import lombok.*; import java.util.List; -@NonNull -@Builder @Data +@Builder +@NoArgsConstructor +@AllArgsConstructor +@NonNull public class ImageDataProperties { @JsonProperty String checksum; diff --git a/classifai-core/src/main/java/ai/classifai/dto/ProjectConfigProperties.java b/classifai-core/src/main/java/ai/classifai/dto/ProjectConfigProperties.java index 4cc88f78..2dd79b12 100644 --- a/classifai-core/src/main/java/ai/classifai/dto/ProjectConfigProperties.java +++ b/classifai-core/src/main/java/ai/classifai/dto/ProjectConfigProperties.java @@ -1,15 +1,15 @@ package ai.classifai.dto; import com.fasterxml.jackson.annotation.JsonProperty; -import lombok.Builder; -import lombok.Data; -import lombok.NonNull; +import lombok.*; import java.util.Map; -@NonNull -@Builder @Data +@Builder +@NoArgsConstructor +@AllArgsConstructor +@NonNull public class ProjectConfigProperties { @JsonProperty("tool") String toolName; diff --git a/classifai-core/src/main/java/ai/classifai/dto/ProjectMetaProperties.java b/classifai-core/src/main/java/ai/classifai/dto/ProjectMetaProperties.java index 54d4fd5d..212502e7 100644 --- a/classifai-core/src/main/java/ai/classifai/dto/ProjectMetaProperties.java +++ b/classifai-core/src/main/java/ai/classifai/dto/ProjectMetaProperties.java @@ -2,13 +2,13 @@ import ai.classifai.util.project.ProjectInfra; import com.fasterxml.jackson.annotation.JsonProperty; -import lombok.Builder; -import lombok.Data; -import lombok.NonNull; +import lombok.*; -@NonNull -@Builder @Data +@Builder +@NoArgsConstructor +@AllArgsConstructor +@NonNull public class ProjectMetaProperties { @JsonProperty("project_name") String projectName; diff --git a/classifai-core/src/main/java/ai/classifai/dto/ThumbnailProperties.java b/classifai-core/src/main/java/ai/classifai/dto/ThumbnailProperties.java index 1fba5571..733fcf55 100644 --- a/classifai-core/src/main/java/ai/classifai/dto/ThumbnailProperties.java +++ b/classifai-core/src/main/java/ai/classifai/dto/ThumbnailProperties.java @@ -1,15 +1,31 @@ +/* + * Copyright (c) 2021 CertifAI Sdn. Bhd. + * + * This program and the accompanying materials are made available under the + * terms of the Apache License, Version 2.0 which is available at + * https://www.apache.org/licenses/LICENSE-2.0. + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + * SPDX-License-Identifier: Apache-2.0 + */ package ai.classifai.dto; import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonProperty; -import lombok.Builder; -import lombok.Data; -import lombok.NonNull; +import lombok.*; import java.util.List; -@Builder @Data +@Builder +@NoArgsConstructor +@AllArgsConstructor +@NonNull public class ThumbnailProperties { @JsonProperty diff --git a/classifai-core/src/main/java/ai/classifai/dto/VersionConfigProperties.java b/classifai-core/src/main/java/ai/classifai/dto/VersionConfigProperties.java index a750c3d7..8579aafa 100644 --- a/classifai-core/src/main/java/ai/classifai/dto/VersionConfigProperties.java +++ b/classifai-core/src/main/java/ai/classifai/dto/VersionConfigProperties.java @@ -1,13 +1,28 @@ +/* + * Copyright (c) 2021 CertifAI Sdn. Bhd. + * + * This program and the accompanying materials are made available under the + * terms of the Apache License, Version 2.0 which is available at + * https://www.apache.org/licenses/LICENSE-2.0. + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + * SPDX-License-Identifier: Apache-2.0 + */ package ai.classifai.dto; import com.fasterxml.jackson.annotation.JsonProperty; -import lombok.Builder; -import lombok.Data; -import lombok.NonNull; +import lombok.*; -@NonNull -@Builder @Data +@Builder +@NoArgsConstructor +@AllArgsConstructor +@NonNull public class VersionConfigProperties { @JsonProperty("version_uuid") String versionUuid; From c82e749fa0c776bddd3a6a7efb79e2b86bf29ff2 Mon Sep 17 00:00:00 2001 From: devenyantis Date: Thu, 23 Sep 2021 03:20:12 +0800 Subject: [PATCH 13/16] :recycle: Fix code smell --- .../ai/classifai/action/parser/ProjectParser.java | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/classifai-core/src/main/java/ai/classifai/action/parser/ProjectParser.java b/classifai-core/src/main/java/ai/classifai/action/parser/ProjectParser.java index f698a17b..61b786c5 100644 --- a/classifai-core/src/main/java/ai/classifai/action/parser/ProjectParser.java +++ b/classifai-core/src/main/java/ai/classifai/action/parser/ProjectParser.java @@ -95,7 +95,7 @@ private static List getVersionList(String versionListSt JsonNode rootNode = mp.readTree(new StringReader(versionListArray.getJsonObject(i).toString())); List annotationPoints = new ArrayList<>(); - rootNode.path("annotation_data").path("annotation").forEach(node -> { + rootNode.path(ParamConfig.getAnnotationDataParam()).path(ParamConfig.getAnnotationParam()).forEach(node -> { try { annotationPoints.add(mp.readValue(node.toString(), AnnotationPointProperties.class)); } catch (JsonProcessingException e) { @@ -105,14 +105,14 @@ private static List getVersionList(String versionListSt DataInfoProperties annotationData = DataInfoProperties.builder() .annotation(annotationPoints) - .imgX(rootNode.path("annotation_data").path("img_x").intValue()) - .imgY(rootNode.path("annotation_data").path("img_y").intValue()) - .imgW(rootNode.path("annotation_data").path("img_w").intValue()) - .imgH(rootNode.path("annotation_data").path("img_h").intValue()) + .imgX(rootNode.path(ParamConfig.getAnnotationDataParam()).path(ParamConfig.getImgXParam()).intValue()) + .imgY(rootNode.path(ParamConfig.getAnnotationDataParam()).path(ParamConfig.getImgYParam()).intValue()) + .imgW(rootNode.path(ParamConfig.getAnnotationDataParam()).path(ParamConfig.getImgWParam()).intValue()) + .imgH(rootNode.path(ParamConfig.getAnnotationDataParam()).path(ParamConfig.getImgHParam()).intValue()) .build(); VersionConfigProperties versionConfig = VersionConfigProperties.builder() - .versionUuid(rootNode.path("version_uuid").textValue()) + .versionUuid(rootNode.path(ParamConfig.getVersionUuidParam()).textValue()) .annotationData(annotationData) .build(); From 245abb950d0868f44cb17c9771f8a785cd6a72d3 Mon Sep 17 00:00:00 2001 From: devenyantis Date: Fri, 24 Sep 2021 11:10:45 +0800 Subject: [PATCH 14/16] :recycle: modify convert string to object --- .../action/parser/ProjectParser.java | 57 ++----------------- .../util/collection/ConversionHandler.java | 15 +++++ 2 files changed, 21 insertions(+), 51 deletions(-) diff --git a/classifai-core/src/main/java/ai/classifai/action/parser/ProjectParser.java b/classifai-core/src/main/java/ai/classifai/action/parser/ProjectParser.java index 61b786c5..1da3bd67 100644 --- a/classifai-core/src/main/java/ai/classifai/action/parser/ProjectParser.java +++ b/classifai-core/src/main/java/ai/classifai/action/parser/ProjectParser.java @@ -18,17 +18,12 @@ import ai.classifai.database.annotation.AnnotationVerticle; import ai.classifai.database.versioning.Annotation; import ai.classifai.database.versioning.AnnotationVersion; -import ai.classifai.dto.AnnotationPointProperties; -import ai.classifai.dto.DataInfoProperties; import ai.classifai.dto.ImageDataProperties; -import ai.classifai.dto.VersionConfigProperties; import ai.classifai.loader.ProjectLoader; import ai.classifai.util.Hash; import ai.classifai.util.ParamConfig; +import ai.classifai.util.collection.ConversionHandler; import ai.classifai.util.data.StringHandler; -import com.fasterxml.jackson.core.JsonProcessingException; -import com.fasterxml.jackson.databind.JsonNode; -import com.fasterxml.jackson.databind.ObjectMapper; import io.vertx.core.json.JsonArray; import io.vertx.core.json.JsonObject; import io.vertx.sqlclient.Row; @@ -39,10 +34,11 @@ import lombok.extern.slf4j.Slf4j; import java.io.File; -import java.io.IOException; -import java.io.StringReader; import java.nio.file.Paths; -import java.util.*; +import java.util.HashMap; +import java.util.Iterator; +import java.util.Map; +import java.util.Set; /*** * Parsing Project Table in and out classifai with configuration file @@ -70,7 +66,7 @@ public static Map parseOut(@NonNull String projectP ImageDataProperties config = ImageDataProperties.builder() .checksum(hash) .imgPath(imgPath) - .versionList(getVersionList(row.getString(2))) + .versionList(ConversionHandler.strToObj(row.getString(2))) .imgDepth(row.getInteger(3)) .imgOriW(row.getInteger(4)) .imgOriH(row.getInteger(5)) @@ -85,47 +81,6 @@ public static Map parseOut(@NonNull String projectP } - private static List getVersionList(String versionListString) { - JsonArray versionListArray = new JsonArray(versionListString); - List config = new ArrayList<>(); - ObjectMapper mp = new ObjectMapper(); - - for(int i=0; i < versionListArray.size(); ++i) { - try { - JsonNode rootNode = mp.readTree(new StringReader(versionListArray.getJsonObject(i).toString())); - - List annotationPoints = new ArrayList<>(); - rootNode.path(ParamConfig.getAnnotationDataParam()).path(ParamConfig.getAnnotationParam()).forEach(node -> { - try { - annotationPoints.add(mp.readValue(node.toString(), AnnotationPointProperties.class)); - } catch (JsonProcessingException e) { - log.info("Fail to AnnotationPointProperties: " + e); - } - }); - - DataInfoProperties annotationData = DataInfoProperties.builder() - .annotation(annotationPoints) - .imgX(rootNode.path(ParamConfig.getAnnotationDataParam()).path(ParamConfig.getImgXParam()).intValue()) - .imgY(rootNode.path(ParamConfig.getAnnotationDataParam()).path(ParamConfig.getImgYParam()).intValue()) - .imgW(rootNode.path(ParamConfig.getAnnotationDataParam()).path(ParamConfig.getImgWParam()).intValue()) - .imgH(rootNode.path(ParamConfig.getAnnotationDataParam()).path(ParamConfig.getImgHParam()).intValue()) - .build(); - - VersionConfigProperties versionConfig = VersionConfigProperties.builder() - .versionUuid(rootNode.path(ParamConfig.getVersionUuidParam()).textValue()) - .annotationData(annotationData) - .build(); - - config.add(versionConfig); - - } catch (IOException e) { - log.info("Fail to convert string to object: " + e); - } - } - - return config; - } - public static void parseIn(@NonNull ProjectLoader loader, @NonNull JsonObject contentJsonBody) { String projectId = loader.getProjectId(); diff --git a/classifai-core/src/main/java/ai/classifai/util/collection/ConversionHandler.java b/classifai-core/src/main/java/ai/classifai/util/collection/ConversionHandler.java index 6501503f..46fbf765 100644 --- a/classifai-core/src/main/java/ai/classifai/util/collection/ConversionHandler.java +++ b/classifai-core/src/main/java/ai/classifai/util/collection/ConversionHandler.java @@ -15,6 +15,9 @@ */ package ai.classifai.util.collection; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.core.type.TypeReference; +import com.fasterxml.jackson.databind.ObjectMapper; import io.vertx.core.json.JsonArray; import io.vertx.core.json.JsonObject; import lombok.extern.slf4j.Slf4j; @@ -296,4 +299,16 @@ public static JSONObject map2JSONObjectParser(Map inputDict) } return jsonOutput; } + + public static T strToObj(String versionListString) { + ObjectMapper mp = new ObjectMapper(); + + try { + return mp.readValue(versionListString, new TypeReference<>() {}); + } catch (JsonProcessingException e) { + log.info("Convert to object fail\n" + e); + return null; + } + } + } \ No newline at end of file From f828c14bb067e6a329b45134d92630232219a126 Mon Sep 17 00:00:00 2001 From: devenyantis Date: Mon, 27 Sep 2021 15:00:11 +0800 Subject: [PATCH 15/16] :recycle: Add getVersionList --- .../action/parser/ProjectParser.java | 23 ++++++++++++++----- .../util/collection/ConversionHandler.java | 15 ------------ 2 files changed, 17 insertions(+), 21 deletions(-) diff --git a/classifai-core/src/main/java/ai/classifai/action/parser/ProjectParser.java b/classifai-core/src/main/java/ai/classifai/action/parser/ProjectParser.java index 1da3bd67..ed7c655d 100644 --- a/classifai-core/src/main/java/ai/classifai/action/parser/ProjectParser.java +++ b/classifai-core/src/main/java/ai/classifai/action/parser/ProjectParser.java @@ -19,11 +19,14 @@ import ai.classifai.database.versioning.Annotation; import ai.classifai.database.versioning.AnnotationVersion; import ai.classifai.dto.ImageDataProperties; +import ai.classifai.dto.VersionConfigProperties; import ai.classifai.loader.ProjectLoader; import ai.classifai.util.Hash; import ai.classifai.util.ParamConfig; -import ai.classifai.util.collection.ConversionHandler; import ai.classifai.util.data.StringHandler; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.core.type.TypeReference; +import com.fasterxml.jackson.databind.ObjectMapper; import io.vertx.core.json.JsonArray; import io.vertx.core.json.JsonObject; import io.vertx.sqlclient.Row; @@ -35,10 +38,7 @@ import java.io.File; import java.nio.file.Paths; -import java.util.HashMap; -import java.util.Iterator; -import java.util.Map; -import java.util.Set; +import java.util.*; /*** * Parsing Project Table in and out classifai with configuration file @@ -66,7 +66,7 @@ public static Map parseOut(@NonNull String projectP ImageDataProperties config = ImageDataProperties.builder() .checksum(hash) .imgPath(imgPath) - .versionList(ConversionHandler.strToObj(row.getString(2))) + .versionList(getVersionList(row.getString(2))) .imgDepth(row.getInteger(3)) .imgOriW(row.getInteger(4)) .imgOriH(row.getInteger(5)) @@ -81,6 +81,17 @@ public static Map parseOut(@NonNull String projectP } + private static List getVersionList(String versionListString) { + ObjectMapper mp = new ObjectMapper(); + + try { + return mp.readValue(versionListString, new TypeReference>() {}); + } catch (JsonProcessingException e) { + log.info("Convert to object fail\n" + e); + return null; + } + } + public static void parseIn(@NonNull ProjectLoader loader, @NonNull JsonObject contentJsonBody) { String projectId = loader.getProjectId(); diff --git a/classifai-core/src/main/java/ai/classifai/util/collection/ConversionHandler.java b/classifai-core/src/main/java/ai/classifai/util/collection/ConversionHandler.java index 46fbf765..6501503f 100644 --- a/classifai-core/src/main/java/ai/classifai/util/collection/ConversionHandler.java +++ b/classifai-core/src/main/java/ai/classifai/util/collection/ConversionHandler.java @@ -15,9 +15,6 @@ */ package ai.classifai.util.collection; -import com.fasterxml.jackson.core.JsonProcessingException; -import com.fasterxml.jackson.core.type.TypeReference; -import com.fasterxml.jackson.databind.ObjectMapper; import io.vertx.core.json.JsonArray; import io.vertx.core.json.JsonObject; import lombok.extern.slf4j.Slf4j; @@ -299,16 +296,4 @@ public static JSONObject map2JSONObjectParser(Map inputDict) } return jsonOutput; } - - public static T strToObj(String versionListString) { - ObjectMapper mp = new ObjectMapper(); - - try { - return mp.readValue(versionListString, new TypeReference<>() {}); - } catch (JsonProcessingException e) { - log.info("Convert to object fail\n" + e); - return null; - } - } - } \ No newline at end of file From 6675cb702d1a4669e4fdd696235b4b8fe93bc47c Mon Sep 17 00:00:00 2001 From: devenyantis Date: Mon, 27 Sep 2021 15:04:06 +0800 Subject: [PATCH 16/16] :recycle: Fix code smell --- .../src/main/java/ai/classifai/action/parser/ProjectParser.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/classifai-core/src/main/java/ai/classifai/action/parser/ProjectParser.java b/classifai-core/src/main/java/ai/classifai/action/parser/ProjectParser.java index ed7c655d..5b7f0218 100644 --- a/classifai-core/src/main/java/ai/classifai/action/parser/ProjectParser.java +++ b/classifai-core/src/main/java/ai/classifai/action/parser/ProjectParser.java @@ -88,7 +88,7 @@ private static List getVersionList(String versionListSt return mp.readValue(versionListString, new TypeReference>() {}); } catch (JsonProcessingException e) { log.info("Convert to object fail\n" + e); - return null; + return Collections.emptyList(); } }