Skip to content

Commit

Permalink
swagger configuration and api changes
Browse files Browse the repository at this point in the history
  • Loading branch information
indraniBan authored and indraniBan committed Jun 14, 2024
1 parent e7375a3 commit 335099b
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 78 deletions.
56 changes: 16 additions & 40 deletions src/main/java/com/iemr/inventory/config/SwaggerConfig.java
Original file line number Diff line number Diff line change
@@ -1,48 +1,24 @@
/*
* AMRIT – Accessible Medical Records via Integrated Technology
* Integrated EHR (Electronic Health Records) Solution
*
* Copyright (C) "Piramal Swasthya Management and Research Institute"
*
* This file is part of AMRIT.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see https://www.gnu.org/licenses/.
*/
package com.iemr.inventory.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.service.Contact;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

@EnableSwagger2
import io.swagger.v3.oas.models.Components;
import io.swagger.v3.oas.models.OpenAPI;
import io.swagger.v3.oas.models.info.Info;
import io.swagger.v3.oas.models.security.SecurityRequirement;
import io.swagger.v3.oas.models.security.SecurityScheme;

@Configuration
public class SwaggerConfig {

@Bean
public Docket productApi() {
return new Docket(DocumentationType.SWAGGER_2).select()
.apis(RequestHandlerSelectors.basePackage("com.iemr.inventory.controller"))
.build().apiInfo(metaData());
}
public OpenAPI customOpenAPI() {
return new OpenAPI().info(new
Info().title("Inventory API").version("version").description("A microservice for the creation and management of beneficiaries."))
.addSecurityItem(new SecurityRequirement().addList("my security"))
.components(new Components().addSecuritySchemes("my security",
new SecurityScheme().name("my security").type(SecurityScheme.Type.HTTP).scheme("bearer")));
}

private ApiInfo metaData() {
ApiInfo apiInfo = new ApiInfo("Inventory API", "A medicine inventory management and dispensing unit that helps in distributing the medicine to the patients as per the prescription.",
"1.0", "Terms of service", new Contact("AMRIT", "https://psmri.github.io/PSMRI/", "[email protected]"), "",
"", null);
return apiInfo;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -202,41 +202,20 @@ public List<AllocateItemMap> getItemStockFromItemID(Integer facilityID, List<Ite
if (totalQty >= itemStockExit.getQuantity()) {
stock.setQuantity(stock.getQuantityInHand() - totalQty + itemStockExit.getQuantity());
break;
} else if (totalQty < itemStockExit.getQuantity()) {
logger.info("Insufficent Qty for '" + item.getItemName() + "'. Available Qty is : " + totalQty);
break;
}

}
}
if (totalQty < itemStockExit.getQuantity()) {
throw new InventoryException(
"Insufficent Qty for '" + item.getItemName() + "'. Available Qty is : " + totalQty);
}
// if (totalQty < itemStockExit.getQuantity()) {
// throw new InventoryException(
// "Insufficent Qty for '" + item.getItemName() + "'. Available Qty is : " + totalQty);
//
// }

List<ItemBatchList> stockBatch = itemBatchListMap.getItemStockExitMapList(itemStockList);
// if(stockBatch != null && stockBatch.size() > 0) {
for (ItemBatchList objList : stockBatch) {
if (objList.getExpiryDate() != null)
objList.setExpiresIn(calculateExpiryDateInDays(new Timestamp(objList.getExpiryDate().getTime())));
}
allocateItemMap.setItemBatchList(stockBatch);
allocateItemMapList.add(allocateItemMap);
// } else {
// ItemBatchList obj = new ItemBatchList();
// obj.setQuantity(0);
// obj.setQuantityInHand(0);
// obj.setItemID(itemID);
// obj.setFacilityID(facilityID);
//
// List<ItemBatchList> stockbatchList = new ArrayList<>();
// stockbatchList.add(obj);
// allocateItemMap.setItemBatchList(stockbatchList);
// allocateItemMapList.add(allocateItemMap);
// }

}

return allocateItemMapList;
}

Expand Down Expand Up @@ -327,14 +306,10 @@ public List<ItemStockEntry> getItemMastersPartialSearch(String itemName, Integer

itemID[i] = (Integer) objects[0];
}

}

itemForsubStore = itemStockEntryRepo.findByItemIDInAndQuantityInHandGreaterThanAndFacilityID(itemID, 0,
facilityID);

}

return itemForsubStore;
}

Expand All @@ -344,7 +319,6 @@ public List<ItemStockEntry> getPhysicalStockEntryItems(Long phySEID) {

return itemStockEntryRepo.findByEntryTypeIDAndSyncFacilityIDAndEntryType(pse.getVanSerialNo(),
pse.getSyncFacilityID(), "physicalStockEntry");

}

@Override
Expand All @@ -361,7 +335,6 @@ public List<ItemMasterWithQuantityMap> getItemwithQuantityPartialSearch(String i

itemID[i] = (Integer) objects[0];
}

}
Date now = new Date();
List<Object[]> itemForsubStoreObj = itemStockEntryRepo
Expand Down Expand Up @@ -391,14 +364,10 @@ public List<ItemStockEntry> getItemMastersPartialSearchWithZero(String itemName,

itemID[i] = (Integer) objects[0];
}

}

itemForsubStore = itemStockEntryRepo.findByItemIDInAndFacilityIDOrderByItemStockEntryIDDesc(itemID,
facilityID);

}

return itemForsubStore;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,13 @@ public boolean preHandle(HttpServletRequest request, HttpServletResponse respons
if (request.getRequestURI().toLowerCase().contains("swagger-ui"))
return status;

String authorization = request.getHeader("Authorization");
// String authorization = request.getHeader("Authorization");
String authorization = null;
String preAuth = request.getHeader("Authorization");
if(null != preAuth && preAuth.contains("Bearer "))
authorization=preAuth.replace("Bearer ", "");
else
authorization = preAuth;
if (!request.getMethod().equalsIgnoreCase("OPTIONS")) {
try {
String[] requestURIParts = request.getRequestURI().split("/");
Expand Down Expand Up @@ -109,7 +115,13 @@ public void postHandle(HttpServletRequest request, HttpServletResponse response,
logger.info("http interceptor - post Handle");
try {

String authorization = request.getHeader("Authorization");
//String authorization = request.getHeader("Authorization");
String authorization = null;
String postAuth = request.getHeader("Authorization");
if(null != postAuth && postAuth.contains("Bearer "))
authorization=postAuth.replace("Bearer ", "");
else
authorization = postAuth;
logger.debug("RequestURI::" + request.getRequestURI() + " || Authorization ::" + authorization);
if (authorization != null) {
redisStorage.updateConcurrentSessionObject(redisStorage.getSessionObject(authorization));
Expand Down

0 comments on commit 335099b

Please sign in to comment.