EntityManager em = JpaConnection.getInstance().getCurrentEntityManager();
CustomAttributeGroupMaintActionForm form = (CustomAttributeGroupMaintActionForm) actionForm;
AdminBean adminBean = getAdminBean(request);
Site site = adminBean.getSite();
JSONEscapeObject jsonResult = new JSONEscapeObject();
jsonResult.put("status", Constants.WEBSERVICE_STATUS_SUCCESS);
Long customAttribGroupId = Format.getLong(form.getCustomAttribGroupId());
CustomAttributeGroup customAttributeGroup = CustomAttributeGroupDAO.load(site.getSiteId(), customAttribGroupId);
String customAttribDetailIds[] = form.getCustomAttribDetailIds();
if (customAttribDetailIds != null) {
for (int i = 0; i < customAttribDetailIds.length; i++) {
CustomAttributeDetail customAttributeDetail = (CustomAttributeDetail) em.find(CustomAttributeDetail.class, Format.getLong(customAttribDetailIds[i]));
if (customAttributeDetail.getCustomAttribute().getCustomAttribTypeCode() == Constants.CUSTOM_ATTRIBUTE_TYPE_SKU_MAKEUP) {
String sql = "select count(*) " +
"from ItemAttributeDetail itemAttributeDetail " +
"where itemAttributeDetail.customAttributeDetail = :customAttributeDetail " +
"and itemAttributeDetail.item.itemTypeCd = :itemTypeCd";
Query query = em.createQuery(sql);
query.setParameter("customAttributeDetail", customAttributeDetail);
query.setParameter("itemTypeCd", Constants.ITEM_TYPE_SKU);
Long count = (Long) query.getSingleResult();
if (count.intValue() > 0) {
jsonResult.put("status", Constants.WEBSERVICE_STATUS_FAILED);
jsonResult.put("reason", Constants.WEBSERVICE_REASON_INUSE);
streamWebService(response, jsonResult.toHtmlString());
return null;
}
}
String sql = "delete " +
"from ItemAttributeDetail itemAttributeDetail " +
"where itemAttributeDetail.customAttributeDetail = :customAttributeDetail ";
Query query = em.createQuery(sql);
query.setParameter("customAttributeDetail", customAttributeDetail);
query.executeUpdate();
customAttributeGroup.getCustomAttributeDetails().remove(customAttributeDetail);
em.remove(customAttributeDetail);
}
}
streamWebService(response, jsonResult.toHtmlString());
return null;
}