diff --git a/src/main/kotlin/com/restapi/Main.kt b/src/main/kotlin/com/restapi/Main.kt index 42fe33e..b5525d5 100644 --- a/src/main/kotlin/com/restapi/Main.kt +++ b/src/main/kotlin/com/restapi/Main.kt @@ -113,80 +113,173 @@ fun main(args: Array) { it.json(mapOf("status" to true)) } - path("/vendor"){ - path("/"){ + path("/vendor") { + path("/") { post("", Vendor::create, Roles(Role.Explicit(listOf("ROLE_VENDOR_CREATE", "ROLE_ADMIN")))) - get("", Vendor::get, Roles(Role.Explicit(listOf("ROLE_VENDOR_VIEW", "ROLE_VENDOR_CREATE", "ROLE_ADMIN")))) - get("quotes/{id}", Vendor::getQuotes, Roles(Role.Explicit(listOf("ROLE_ADMIN", "ROLE_QUOTE_VIEW", "ROLE_QUOTE_CREATE", "ROLE_VENDOR_VIEW")))) - get("pos/{id}", Vendor::getPos, Roles(Role.Explicit(listOf("ROLE_ADMIN", "ROLE_PO_VIEW", "ROLE_PO_CREATE`")))) + get( + "", + Vendor::get, + Roles(Role.Explicit(listOf("ROLE_VENDOR_VIEW", "ROLE_VENDOR_CREATE", "ROLE_ADMIN"))) + ) + get( + "quotes/{id}", + Vendor::getQuotes, + Roles( + Role.Explicit( + listOf( + "ROLE_ADMIN", + "ROLE_QUOTE_VIEW", + "ROLE_QUOTE_CREATE", + "ROLE_VENDOR_VIEW" + ) + ) + ) + ) + get( + "pos/{id}", + Vendor::getPos, + Roles(Role.Explicit(listOf("ROLE_ADMIN", "ROLE_PO_VIEW", "ROLE_PO_CREATE`"))) + ) put("/rate/{id}/{rating}", Vendor::rate, Roles(Role.Explicit(listOf("ROLE_VENDOR_CREATE")))) } - path("/po"){ + path("/po") { post("", PurchaseOrder::create, Roles(Role.Explicit(listOf("ROLE_PO_CREATE", "ROLE_ADMIN")))) - get("/{id}", PurchaseOrder::get, Roles(Role.Explicit(listOf("ROLE_PO_CREATE", "ROLE_PO_VIEW", "ROLE_QUOTE_CREATE")))) - put("/approve/{id}", PurchaseOrder::approve, Roles(Role.Explicit(listOf("ROLE_ADMIN", "ROLE_APPROVE")))) - put("/reject/{id}", PurchaseOrder::reject, Roles(Role.Explicit(listOf("ROLE_ADMIN", "ROLE_APPROVE")))) - get("/refQuote/{id}", PurchaseOrder::quoteReference, Roles(Role.Explicit(listOf("ROLE_PO_CREATE", "ROLE_PO_VIEW")))) + get( + "/{id}", + PurchaseOrder::get, + Roles(Role.Explicit(listOf("ROLE_PO_CREATE", "ROLE_PO_VIEW", "ROLE_QUOTE_CREATE"))) + ) + put( + "/approve/{id}", + PurchaseOrder::approve, + Roles(Role.Explicit(listOf("ROLE_ADMIN", "ROLE_APPROVE"))) + ) + put( + "/reject/{id}", + PurchaseOrder::reject, + Roles(Role.Explicit(listOf("ROLE_ADMIN", "ROLE_APPROVE"))) + ) + get( + "/refQuote/{id}", + PurchaseOrder::quoteReference, + Roles(Role.Explicit(listOf("ROLE_PO_CREATE", "ROLE_PO_VIEW"))) + ) } - path("/quote"){ + path("/quote") { post("", Quotation::create, Roles(Role.Explicit(listOf("ROLE_QUOTE_CREATE", "ROLE_ADMIN")))) - get("/{id}", Quotation::get, Roles(Role.Explicit(listOf("ROLE_QUOTE_VIEW", "ROLE_ADMIN", "ROLE_PO_CREATE", "ROLE_QUOTE_CREATE")))) - get("/po/{id}", Quotation::generatePO, Roles(Role.Explicit(listOf("ROLE_ADMIN", "ROLE_PO_CRETE")))) - get("/rfq/{rfqNum}", Quotation::reqForQuote, Roles(Role.Explicit(listOf("ROLE_QUOTE_CREATE", "ROLE_QUOTE_VIEW")))) - delete("/{id}", Quotation::delete, Roles(Role.Explicit(listOf("ROLE_QUOTE_CREATE", "ROLE_ADMIN")))) + get( + "/{id}", + Quotation::get, + Roles( + Role.Explicit( + listOf( + "ROLE_QUOTE_VIEW", + "ROLE_ADMIN", + "ROLE_PO_CREATE", + "ROLE_QUOTE_CREATE" + ) + ) + ) + ) + get( + "/po/{id}", + Quotation::generatePO, + Roles(Role.Explicit(listOf("ROLE_ADMIN", "ROLE_PO_CRETE"))) + ) + get( + "/rfq/{rfqNum}", + Quotation::reqForQuote, + Roles(Role.Explicit(listOf("ROLE_QUOTE_CREATE", "ROLE_QUOTE_VIEW"))) + ) + delete( + "/{id}", + Quotation::delete, + Roles(Role.Explicit(listOf("ROLE_QUOTE_CREATE", "ROLE_ADMIN"))) + ) } - path("/product"){ + path("/product") { post("", ProductCtrl::create, Roles(Role.Explicit(listOf("ROLE_PRODUCT_CREATE", "ROLE_ADMIN")))) //get("/{hsnCode}", ProductCtrl::get, Roles(Role.Explicit(listOf("ROLE_PRODUCT_VIEW", "ROLE_ADMIN")))) - put("/{id}", ProductCtrl::update, Roles(Role.Explicit(listOf("ROLE_PRODUCT_UPDATE", "ROLE_ADMIN")))) + put( + "/{id}", + ProductCtrl::update, + Roles(Role.Explicit(listOf("ROLE_PRODUCT_UPDATE", "ROLE_ADMIN"))) + ) //patch("/{id}", ProductCtrl::patch, Roles(Role.Explicit(listOf("ROLE_PRODUCT_UPDATE", "ROLE_ADMIN")))) - delete("/{id}", ProductCtrl::delete, Roles(Role.Explicit(listOf("ROLE_PRODUCT_DELETE", "ROLE_ADMIN")))) + delete( + "/{id}", + ProductCtrl::delete, + Roles(Role.Explicit(listOf("ROLE_PRODUCT_DELETE", "ROLE_ADMIN"))) + ) get("", ProductCtrl::getAll, Roles(Role.Explicit(listOf("ROLE_PRODUCT_VIEW", "ROLE_ADMIN")))) post("/product-excel", ProductCtrl::prodExcel) - get("/product-import"){ ctx -> ctx.json(ExcelRead())} + get("/product-import") { ctx -> //ctx.json(ExcelRead())} + val fileItem = ctx.uploadedFiles("file") + if (fileItem != null) { + ctx.result("Data imported successfully!") + } else { + ctx.result("No file uploaded") + } + } } - path("/doc"){ - post("", Document::create, Roles(Role.Explicit(listOf("ROLE_DOC_CREATE", "ROLE_ADMIN")))) - //why type and refid are clubbed ?? - get("/{type}/{refId}", Document::getWithRefId, Roles(Role.Explicit(listOf("ROLE_DOC_VIEW", "ROLE_ADMIN", "ROLE_PRODUCT_CREATE")))) - get("/{id}", Document::get, Roles(Role.Explicit(listOf("ROLE_DOC_VIEW", "ROLE_ADMIN", "ROLE_PRODUCT_CREATE")))) - get("/print/{id}", Document::print, Roles(Role.Explicit(listOf("ROLE_DOC_CREATE", "ROLE_DOC_VIEW")))) - delete("/{id}", Document::delete, Roles(Role.Explicit(listOf("ROLE_DOC_CREATE")))) - } - path("/reqForQuote"){ - post("", RequestForQuote::create, Roles(Role.Explicit(listOf("ROLE_RFQ_CREATE")))) - get("/{id}", RequestForQuote::get, Roles(Role.Explicit(listOf("ROLE_RFQ_CREATE", "ROLE_RFQ_VIEW")))) - put("/{id}", RequestForQuote::update, Roles(Role.Explicit(listOf("ROLE_RFQ_CREATE")))) + path("/doc") { + post("", Document::create, Roles(Role.Explicit(listOf("ROLE_DOC_CREATE", "ROLE_ADMIN")))) + //why type and refid are clubbed ?? + get( + "/{type}/{refId}", + Document::getWithRefId, + Roles(Role.Explicit(listOf("ROLE_DOC_VIEW", "ROLE_ADMIN", "ROLE_PRODUCT_CREATE"))) + ) + get( + "/{id}", + Document::get, + Roles(Role.Explicit(listOf("ROLE_DOC_VIEW", "ROLE_ADMIN", "ROLE_PRODUCT_CREATE"))) + ) + get( + "/print/{id}", + Document::print, + Roles(Role.Explicit(listOf("ROLE_DOC_CREATE", "ROLE_DOC_VIEW"))) + ) + delete("/{id}", Document::delete, Roles(Role.Explicit(listOf("ROLE_DOC_CREATE")))) + } + path("/reqForQuote") { + post("", RequestForQuote::create, Roles(Role.Explicit(listOf("ROLE_RFQ_CREATE")))) + get( + "/{id}", + RequestForQuote::get, + Roles(Role.Explicit(listOf("ROLE_RFQ_CREATE", "ROLE_RFQ_VIEW"))) + ) + put("/{id}", RequestForQuote::update, Roles(Role.Explicit(listOf("ROLE_RFQ_CREATE")))) + } } + post("/script/database/{name}", Entities::executeStoredProcedure, Roles(adminRole, Role.DbOps)) + post("/script/{file}/{name}", Entities::executeScript, Roles(adminRole, Role.DbOps)) + + get("/{entity}/{id}", Entities::view, Roles(adminRole, viewRole)) + post("/{entity}/query/{id}", Entities::sqlQueryById, Roles(adminRole, viewRole)) + post("/{entity}/query", Entities::sqlQueryRaw, Roles(adminRole, viewRole)) + post("/{entity}", Entities::create, Roles(adminRole, createRole)) + + put("/{entity}/approve/{id}", Entities::approve, Roles(adminRole, approveOrRejectRole)) + put("/{entity}/reject/{id}", Entities::reject, Roles(adminRole, approveOrRejectRole)) + put("/{entity}/{action}/{id}", Entities::action, Roles(adminRole, Role.Entity)) + + put("/{entity}/{id}", Entities::update, Roles(adminRole, updateRole)) + patch("/{entity}/{id}", Entities::patch, Roles(adminRole, updateRole)) + delete("/{entity}/{id}", Entities::delete, Roles(adminRole, Role.Standard(Action.DELETE))) } - post("/script/database/{name}", Entities::executeStoredProcedure, Roles(adminRole, Role.DbOps)) - post("/script/{file}/{name}", Entities::executeScript, Roles(adminRole, Role.DbOps)) - - get("/{entity}/{id}", Entities::view, Roles(adminRole, viewRole)) - post("/{entity}/query/{id}", Entities::sqlQueryById, Roles(adminRole, viewRole)) - post("/{entity}/query", Entities::sqlQueryRaw, Roles(adminRole, viewRole)) - post("/{entity}", Entities::create, Roles(adminRole, createRole)) - - put("/{entity}/approve/{id}", Entities::approve, Roles(adminRole, approveOrRejectRole)) - put("/{entity}/reject/{id}", Entities::reject, Roles(adminRole, approveOrRejectRole)) - put("/{entity}/{action}/{id}", Entities::action, Roles(adminRole, Role.Entity)) - - put("/{entity}/{id}", Entities::update, Roles(adminRole, updateRole)) - patch("/{entity}/{id}", Entities::patch, Roles(adminRole, updateRole)) - delete("/{entity}/{id}", Entities::delete, Roles(adminRole, Role.Standard(Action.DELETE))) } + .exception(DuplicateKeyException::class.java, Exceptions.dupKeyExceptionHandler) + .exception(DataIntegrityException::class.java, Exceptions.dataIntegrityException) + .exception(DataNotFoundException::class.java, Exceptions.dataNotFoundException) + .exception(IllegalArgumentException::class.java, Exceptions.illegalArgumentException) + .exception(JsonMappingException::class.java, Exceptions.jsonMappingException) + .exception(InvalidJwtException::class.java, Exceptions.invalidJwtException) + .start(appConfig.portNumber()) } - .exception(DuplicateKeyException::class.java, Exceptions.dupKeyExceptionHandler) - .exception(DataIntegrityException::class.java, Exceptions.dataIntegrityException) - .exception(DataNotFoundException::class.java, Exceptions.dataNotFoundException) - .exception(IllegalArgumentException::class.java, Exceptions.illegalArgumentException) - .exception(JsonMappingException::class.java, Exceptions.jsonMappingException) - .exception(InvalidJwtException::class.java, Exceptions.invalidJwtException) - .start(appConfig.portNumber()) -} -private fun Context.getAuthHeader() = header("Authorization") - ?.replace("Bearer ", "") - ?.replace("Bearer: ", "") - ?.trim() + private fun Context.getAuthHeader() = header("Authorization") + ?.replace("Bearer ", "") + ?.replace("Bearer: ", "") + ?.trim() diff --git a/src/main/kotlin/com/restapi/controllers/Entities.kt b/src/main/kotlin/com/restapi/controllers/Entities.kt index 60cc77f..1994478 100644 --- a/src/main/kotlin/com/restapi/controllers/Entities.kt +++ b/src/main/kotlin/com/restapi/controllers/Entities.kt @@ -17,8 +17,10 @@ import com.restapi.integ.Scripting import io.ebean.CallableSql import io.ebean.RawSqlBuilder import io.javalin.http.* +import org.apache.poi.ss.usermodel.WorkbookFactory import org.slf4j.LoggerFactory import java.io.File +import java.io.FileInputStream import java.io.InputStream import java.sql.Types import java.time.LocalDate @@ -416,7 +418,6 @@ object PurchaseOrder { data class ProductSearch( var isSort: String? = null - ) object ProductCtrl { @@ -429,7 +430,7 @@ object ProductCtrl { fun getAll(ctx: Context){ val productList = Session.database.find(Product::class.java) .findList() - .sortedBy { it.hsnCode } + //.sortedBy { it.hsnCode } ctx.json(productList) } @@ -456,6 +457,33 @@ object ProductCtrl { .header("Content-Disposition", "attachment; filename=\"product.xlsx\"") } + data class ProductList( + val name: String, + val description: String, + val hsnCode: String, + val uom: String?, + ) + + fun excelToDb(it: Context){ + val inputStream = FileInputStream("C:\\Users\\vinay\\IdeaProjects\\readymixerp_modules_api_git\\Untitled 1.xlsx") + val workbook = WorkbookFactory.create(inputStream) + val workSheet = workbook.getSheetAt(0) + + val dataList = mutableListOf() + + for (row in workSheet) { + val cell1Value = row.getCell(0).stringCellValue + val cell2Value = row.getCell(1).stringCellValue + val cell3Value = row.getCell(2).stringCellValue + val cell4Value = row.getCell(3).stringCellValue + + val data = ProductList(cell1Value, cell2Value, cell3Value, cell4Value) + dataList.add(data) + + } + database.saveAll(dataList) + } + } object Quotation { diff --git a/src/main/kotlin/com/restapi/domain/models.kt b/src/main/kotlin/com/restapi/domain/models.kt index a9258b6..952489c 100644 --- a/src/main/kotlin/com/restapi/domain/models.kt +++ b/src/main/kotlin/com/restapi/domain/models.kt @@ -273,6 +273,7 @@ open class PurchaseOrder :BaseTenantModel() { enum class UOM { NOS, LTR, MTR, ALL } + @Entity open class Product :BaseTenantModel() { var id: Int? = null