How can I improve this code with nested null check statements?
public class AcrCategoryService extends BaseActionService<AcrCategoryModel> {
@SuppressWarnings({ "rawtypes", "unchecked" })
public Map getCategoryList(String categoryCd, String categoryNm, String rgstTrgt) throws Exception{
Map model = new HashMap();
fileService.setIsGetFile(true);
try {
List<AcrCategoryModel> cateData = acrCategoryDao.getCategoryList(categoryCd, categoryNm, rgstTrgt);
for(AcrCategoryModel acr : cateData)
{
if(acr.getAttrNo() == null)
{
System.out.println("------------------------getAttrNo is null");
} else
{
System.out.println("======getAttrNo===================>>>>>>>>>>>>>>>>>"+acr.getAttrNo());
FileModel file = (FileModel)fileService.get(acr.getAttrNo()).get("fileList");
acr.setListImg("<img src='"+file.getFilebyte()+"' height='25' width=100>");
}
}
model.put("categoryList", cateData);
} catch(Exception e) {
throw new Exception(e);
}
return model;
}
@SuppressWarnings({ "rawtypes", "unchecked" })
public Map get(String categoryId, Integer attrNo) throws Exception{
Map model = new HashMap();
fileService.setIsGetFile(true);
try {
AcrCategoryModel categoryInfo = (AcrCategoryModel)acrCategoryDao.get(categoryId);
model.put("categoryInfo", categoryInfo);
List<AcrCategoryModel> subCateList = acrCategoryDao.getSubCate(categoryId);
model.put("subCateList", subCateList);
List<AcrCategoryModel> accAreaList = acrCategoryDao.getAccArea(categoryId);
model.put("accAreaList", accAreaList);
if(categoryInfo.getAttrNo() == null)
{
} else
{
model.put("fileList", fileService.getList(categoryId, categoryInfo.getAttrNo()).get("fileList"));
}
} catch (Exception e) {
throw e;
}
return model;
}
}
public class AcrColorService extends BaseActionService<AcrColorModel> {
@Autowired
private AcrColorDao acrColorDao;
@Autowired
private FileService fileService;
@SuppressWarnings({ "rawtypes", "unchecked" })
public Map getColorList(String colorCd, String colorNm) throws Exception{
Map model = new HashMap();
fileService.setIsGetFile(true);
try {
List<AcrColorModel> colorData = acrColorDao.getColorList(colorCd, colorNm);
for(AcrColorModel acr : colorData)
{
if(acr.getAttrNo() == null)
{
System.out.println("------------------------getAttrNo is null");
} else
{
System.out.println("======getAttrNo===================>>>>>>>>>>>>>>>>>"+acr.getAttrNo());
FileModel file = (FileModel)fileService.get(acr.getAttrNo()).get("fileList");
acr.setListImg("<img src='"+file.getFilebyte()+"' height='15' width=200>");
}
}
model.put("colorList", colorData);
} catch(Exception e) {
throw new Exception(e);
}
return model;
}
public void deleteTrgStatusAction(AcrColorModel colorModel) throws Exception {
// TODO Auto-generated method stub
for (Map<String,String> colorInfo : colorModel.getColorList()) {
if(colorInfo.get("attrNo") != null && !colorInfo.get("attrNo").equals(""))
{
FileModel fileModel = new FileModel();
fileModel.setFileSeq(colorInfo.get("colorId").toString());
fileModel.setAttrNo(Integer.parseInt(colorInfo.get("attrNo")));
fileService.remove(fileModel);
}
acrColorDao.remove(colorInfo);
}
}
public void updateTrgStatusAction(AcrColorModel colorModel, Map model) throws Exception {
// TODO Auto-generated method stub
if(colorModel.getImgPath()!=null && colorModel.getImgPath().getSize()>0)
{
if(colorModel.getAttrNo() != null)
{
FileModel fileModel = new FileModel();
fileModel.setFileSeq(colorModel.getColorId().toString());
fileModel.setAttrNo(colorModel.getAttrNo());
fileService.remove(fileModel);
}
int attrNo = 0;
attrNo = fileService.fileWrite(Constants.ServiceId.ACR_COLOR, colorModel.getColorId().toString(), colorModel.getImgPath());
if(attrNo != 0)
colorModel.setAttrNo(attrNo);
}
acrColorDao.modify(colorModel);
}
@SuppressWarnings({ "rawtypes", "unchecked" })
public void createTrgStatusAction(AcrColorModel colorModel, Map model) throws Exception {
// TODO Auto-generated method stub
acrColorDao.add(colorModel);
colorModel.setTrStatus(Constants.TrStatus.UPDATE);
int attrNo = 0;
if(colorModel.getImgPath()!=null && colorModel.getImgPath().getSize()>0)
attrNo = fileService.fileWrite(Constants.ServiceId.ACR_COLOR, colorModel.getColorId().toString(), colorModel.getImgPath());
if(attrNo != 0)
{
colorModel.setAttrNo(attrNo);
acrColorDao.modify(colorModel);
}
model.put("colorInfo", colorModel);
}
@SuppressWarnings({ "rawtypes", "unchecked" })
public Map get(String colorId) throws Exception{
Map model = new HashMap();
fileService.setIsGetFile(true);
try {
AcrColorModel acrColorInfo = (AcrColorModel)acrColorDao.get(colorId);
model.put("colorInfo", acrColorInfo);
if(acrColorInfo.getAttrNo() == null)
{
} else
{
model.put("fileList", fileService.getList(colorId, acrColorInfo.getAttrNo()).get("fileList"));
}
} catch (Exception e) {
throw e;
}
return model;
}
}
I hate nested null check among different classes in this code. Can I make a method and move it up to a super class?