- 浏览: 395128 次
- 性别:
- 来自: 上海
文章分类
- 全部博客 (171)
- 学习网站 (3)
- 生活点滴 (10)
- javascript (35)
- java (8)
- select/option (4)
- SQL (4)
- database存取 (5)
- intra-mart (1)
- java面试相关 (8)
- hibernate (2)
- IDE related (6)
- Websphere (6)
- software development (1)
- ibatis (4)
- JSF (5)
- dojo (6)
- java web (2)
- xml (0)
- DB2 (11)
- version control (4)
- xml,excel,json related (3)
- 工具收集 (1)
- BW (13)
- abap (1)
最新评论
-
Trying:
mysql会怎样呢?编程时,到底要不要排序呢?听说排序会对性能 ...
sql中没有order by,是否存在默认排序 -
yanwushu:
CASE WHEN 有两种表达式写法: ...
oracle case when的用法 -
Matol:
ok,不错的
java去除字符串中的空格、回车、换行符、制表符 -
jianxia801:
现在天下文章一大抄;实际没有这个fromString方法:准确 ...
JSON与JAVA的数据转换--String->Bean -
春隆隆:
精辟
java去除字符串中的空格、回车、换行符、制表符
public static String className = ManageAssetFacesBean.class.getName();
public static Log logger = LogFactory.getLog(ManageAssetFacesBean.class);
public static final String TYPE_CREATE = "create";
public static final String TYPE_COPY = "copy";
public static final String TYPE_UPDATE = "update";
private String operationType = TYPE_CREATE;
private Asset asset = new Asset();
private AssetPlan assetPlan;
//When do 'edit' asset operation, this asset will stores the original value retrieved from database,
//and "asset" attribute stores the updated data which will be pushed back to the database
private Asset assetCopy = new Asset();
private AssociateCUPlanBean associateBean = new AssociateCUPlanBean();
private boolean isSubmitOutputAssetDocNumber = false;
// the tip text when assoicate asset to asset plan ;
private String assoicateTipText;
private int subRequestCount = 0;
private int lastAssetType;
//onload method
public void onload(FacesContext context) throws SQLException{
// System.out.println("enter asset page onload..., subRequestCount is " + subRequestCount);
if (hasError()) {
return;
}
if(subRequestCount > 0){
subRequestCount--;
return;
}
HttpServletRequest request = getRequest();
operationType = request.getParameter("type");
if(operationType == null){
operationType = TYPE_CREATE;
}
asset = new Asset();
//This statement is just for create new asset type
asset.setStatus(Asset.STATUS_DRAFT);
String assetID = request.getParameter("assetID");
populateAsset(assetID);
//clear output asset doc number config info
if(TYPE_CREATE.equals(operationType)){
asset.getOutputAssetDocNumList().clear();
asset.setQuantity(1);
}
//populate available assetTypes
//List assetTypes = ManageAssetService.$.retrieveSuperModuleAssetTypes();
List assetTypes = ManageAssetService.$.retrieveAssetTypes(true);
List assetTypeItems = E2EUIUtility.composeSelectItemList(assetTypes);
asset.setAvaiAssetTypes(assetTypeItems);
}
/**
* When the doc number config page is loaded, this method will be called
* @param context
*/
public void onload_docNumConfig(FacesContext context) throws SQLException{
// System.out.println("enter doc number on load...");
if(this.isSubmitOutputAssetDocNumber == true){
this.isSubmitOutputAssetDocNumber = false;
}else{
int contentType = asset.getTypeID();
int oldType = assetCopy.getTypeID();
if(contentType == oldType){
asset.setOutputAssetDocNumList(assetCopy.getOutputAssetDocNumList());
}
else if(contentType !=lastAssetType){
lastAssetType = contentType;
List outputAssetTypeList = ManageAssetService.$.retrieveOutputAssetTypes(contentType);
List docNumList = new ArrayList();
if(outputAssetTypeList.size() > 0){ //is super module
// System.out.println("is output asset");
int childNum = outputAssetTypeList.size();
for(int i = 0; i < childNum; i++){
OutputAsset outputAsset = new OutputAsset();
outputAsset.setName(((AssetType)outputAssetTypeList.get(i)).getName());
docNumList.add(outputAsset);
}
}
asset.setOutputAssetDocNumList(docNumList);
}
}
}
/**
* setup output asset doc number
*
*/
public void setupOutputAssetDocNumber(){
this.isSubmitOutputAssetDocNumber = true;
}
//action methods
/**
* Load the default average page
*/
public void loadDefaultPageNum() throws SQLException {
this.subRequestCount++;
HttpServletRequest request = getRequest();
String assetTypeID = request.getParameter("assetTypeID");
AssetType type = ManageAssetService.$.retrieveAssetTypeByID(Integer.parseInt(assetTypeID));
int avgPage = type.getAvgPage();
asset.setAvgPages(avgPage);
}
/**
* Load the default average words per page
*
*/
public void loadDefaultWordNum() throws SQLException{
this.subRequestCount++;
HttpServletRequest request = getRequest();
String assetTypeID = request.getParameter("assetTypeID");
AssetType type = ManageAssetService.$.retrieveAssetTypeByID(Integer.parseInt(assetTypeID));
int avgWord = type.getAvgWordPerPage();
asset.setAvgWordsPerPage(avgWord);
}
/**
* Set asset content type before
*/
public void setAssetType(){
HttpServletRequest request = getRequest();
String assetTypeID = request.getParameter("assetTypeID");
asset.setTypeID(Integer.parseInt(assetTypeID));
}
/**
* Create Consumablue Unit-- The type could be
* Product CU or Asset CU
* @throws Exception
*/
public String createAsset() throws Exception{
asset.setId(0);
if (!asset.getStatus().equalsIgnoreCase(Asset.STATUS_DRAFT)) {
asset.setStatus(Asset.STATUS_DRAFT);
}
//We need to get the correct data before validation
ManageAssetService.$.getPreparedForDBOperation(asset);
if (!validateAsset(asset)) {
return "";
}
ManageAssetService.$.createAsset(asset);
this.operationType = TYPE_UPDATE;
return "createSuccess";
}
public boolean validateAsset(Asset tempAsset) {
boolean result = true;
if ("Yes".equals(tempAsset.getLink_to_ann())
&& (tempAsset.getAnnouncement() == null || tempAsset
.getAnnouncement().length() == 0)) {
FacesContext.getCurrentInstance().addMessage(
"form1:Ann",
new FacesMessage(FacesMessage.SEVERITY_ERROR,
"The announcement could not be empty.",
"The announcement could not be empty."));
result = false;
}
if (tempAsset.getTranslationStartDate().after(
tempAsset.getPublishDate())) {
FacesContext
.getCurrentInstance()
.addMessage(
"form1:translationStartDate",
new FacesMessage(
FacesMessage.SEVERITY_ERROR,
"The translation start date should not be after the publish date .",
"The translation start date should not be after the publish date ."));
result = false;
}
try {
if (ManageAssetService.$.isNameUsed(tempAsset.getName(), tempAsset
.getBuCode(), tempAsset.getId())) {
FacesContext.getCurrentInstance().addMessage(
"form1:assetName",
new FacesMessage("Please check the name.",
"The name has been used in \""
+ tempAsset.getBuCode() + "\"."));
result = false;
}
String message = checkBudget(tempAsset);
if(message.length()>0){
FacesContext.getCurrentInstance().addMessage(
"form1:translationCost",
new FacesMessage(FacesMessage.SEVERITY_ERROR,
message,
message + "Please add budget first."));
result = false;
}
} catch (SQLException e) {
e.printStackTrace();
result = false;
}
return result;
}
private String checkBudget(Asset asset) throws SQLException {
if (asset.getStatus() == Asset.STATUS_DRAFT || !"GTS".equals(asset.getBuCode())) {
return "";
}
List lAssets = asset.getTargetLanguages();
BudgetPlan bp = null;
String message = "";
String language = "";
for (Iterator it = lAssets.iterator(); it.hasNext();) {
LAsset lAsset = (LAsset) it.next();
if (lAsset.getPrioritized().equals(LAsset.PRIORITIZE_YES)) {
if (assetPlan == null) {
assetPlan = ManageAssetPlanService.$.
retrieveAssetPlan(Integer.valueOf(asset.getAssetPlanIDs()).intValue());
}
LBudgetPlan tempLBudgetPlan = null;
if (bp == null) {
bp = ManageBudgetPlanService.$.retrieveBudgetPlan(assetPlan.getBudgetPlanId());
if (bp == null) {
return "";
}
Map lbpMap = bp.getLanguageBudgets();
tempLBudgetPlan = (LBudgetPlan) lbpMap.get(lAsset.getLanguageID());
}
if (tempLBudgetPlan == null) {
return ("The selected language " + lAsset.getLanguageName()
+ " isn't included in budget plan " + bp.getName() + ". ");
}
double costEstimation = lAsset.getEstCost() + lAsset.getEstProCost();
double actualCost = lAsset.getActualProCost() + lAsset.getActualTransCost();
double remaining = tempLBudgetPlan.getRemainingAmount() + actualCost - costEstimation;
if (remaining < 0) {
language += "," + tempLBudgetPlan.getLanguageName();
}
}
}
if (!StringUtils.isBlank(language)) {
message = "There is no more budget for " + language + ".";
}
return message;
}
/**
* Update Consumable Unit -- The type could be Product CU or Asset CU
*
* @return
* @throws SQLException
*/
public String updateAsset() throws Exception{
//We need to get the correct data before validation
ManageAssetService.$.getPreparedForDBOperation(asset);
if(!validateAsset(asset)){
return "";
}
ManageAssetService.$.updateAsset(asset,assetPlan);
return "updateSuccess";
}
/**
* Refine the asset plan records, only active asset plan can be associated to
* @return
* @throws SQLException
*/
private String getBUCodebyAsset(String assetIDs) throws SQLException {
assoicateTipText = "";
System.out.println("assetIDs:"+assetIDs);
List BUs = ManageAssetService.$.retrieveAssetBU(assetIDs);
if (BUs != null && BUs.size() == 1) {
associateBean.setSelectedCUIDs(assetIDs);
return (String) BUs.get(0);
} else {
assoicateTipText = "The assets selected must belong to one business unit.";
}
return null;
}
private void retrieveLinkablePlans(String bu) throws SQLException {
assoicateTipText = "";
AssetPlanSearchCriteria criteria = new AssetPlanSearchCriteria();
criteria.setBuCode(bu);
// List statusList = new ArrayList();
// statusList.add(AssetPlan.STATUS_DRAFT);
// statusList.add(AssetPlan.STATUS_PUBLISH);
// statusList.add(AssetPlan.STATUS_PRIORIRIE_REQUESTED);
// statusList.add(AssetPlan.STATUS_PRIORIRIE_RETURNED);
// statusList.add(AssetPlan.STATUS_IN_TRANSLATION);
// statusList.add(AssetPlan.STATUS_IN_VALIDATION);
// statusList.add(AssetPlan.STATUS_COMPLETE);
// criteria.setStatusList(statusList);
List plans = ManageAssetPlanService.$.retrieveAssetPlanBySC(criteria);
if (plans == null || plans.size() == 0) {
assoicateTipText = "There is no Product/Program that can be assoicate to.";
} else {
this.associateBean.setAssociatedPlans(plans);
}
// System.out.println("assoicateTipText: " + assoicateTipText);
}
public void onload_associatePlanPage(FacesContext context)
throws SQLException {
String assetIDs = getRequest().getParameter("assetIDs");
System.out.println("assetIDs:"+assetIDs);
associateBean = new AssociateCUPlanBean();
if (assetIDs != null && assetIDs.length() > 0 && !"0".equals(assetIDs)) {
AssetPlan tempAssetPlan;
Integer assetID;
List assetIDList = Arrays.asList(assetIDs.split(","));
// check whether the linked asset plan is in translation status;
for (Iterator it = assetIDList.iterator(); it.hasNext();) {
assetID = Integer.valueOf((String) it.next());
tempAssetPlan = ManageAssetPlanService.$
.retrieveAssetPlanByAssetID(assetID.intValue());
if (tempAssetPlan != null) {
if (AssetPlan.STATUS_IN_TRANSLATION
.equalsIgnoreCase(tempAssetPlan.getStatus())
|| AssetPlan.STATUS_IN_VALIDATION
.equalsIgnoreCase(tempAssetPlan.getStatus())
|| AssetPlan.STATUS_COMPLETE
.equalsIgnoreCase(tempAssetPlan.getStatus())) {
// give some notification
assoicateTipText = "The asset has been linked to Product/Program \""
+ tempAssetPlan.getName()
+ "\" which is already in \""
+ tempAssetPlan.getStatus()
+ "\" status, change the link is not allowed.";
return;
} else {
associateBean.setSelectedPlanIDs(String.valueOf(tempAssetPlan.getId()));
}
} else {
associateBean.setSelectedPlanIDs("");
}
}
String bu = getBUCodebyAsset(assetIDs);
if (bu != null)
retrieveLinkablePlans(bu);
} else {
String bu = getRequest().getParameter("bu");
retrieveLinkablePlans(bu);
}
}
/**
* Associate Assets to Plans (currently it's asset to asset plans, in the
* future, we may support cu&idplan)
*
*/
public String associateAssetToAssetPlan() throws Exception {
String result = "";
List assetIDs = Arrays.asList(associateBean.getSelectedCUIDs().split(
","));
List assetPlanIDs = Arrays.asList(associateBean.getSelectedPlanIDs()
.split(","));
int assetId = Integer.valueOf((String) assetIDs.get(0)).intValue();
int assetPlanId = Integer.valueOf((String) assetPlanIDs.get(0))
.intValue();
if (assetId > 0 && assetPlanId > 0) {
Asset asset = ManageAssetService.$.retrieveAsset(assetId);
AssetPlan ap = ManageAssetPlanService.$
.retrieveAssetPlan(assetPlanId);
try {
BaseDao.startTransaction();
ManageAssetService.$.deleteAssetToAssetPlanLinksByAsset(asset
.getId());
ManageAssetService.$.associateAssetToAssetPlan(asset, ap);
BaseDao.commitTransaction();
} finally {
BaseDao.endTransaction();
}
result = "success";
} else {
}
return result;
}
/**
* Estimate budget for Asset CU
*
* @throws SQLException
*/
public void showBudget() throws SQLException {
HttpServletRequest request = getRequest();
Asset tempAsset = ManageAssetService.$.composeCostEstimatorAssetBean(request);
if (asset != null) {
tempAsset.setTargetLanguages(asset.getTargetLanguages());
}
//Compose target languages
ManageAssetService.$.composeLAssetList(tempAsset);
//Estimate the cost
CostEstimation costEstimation = CostEstimationService.$.calculateCost(tempAsset);
asset.setEN_COST(costEstimation.getTranslationAndCDLayoutCharges());
asset.setNLV_COST(costEstimation.getStiboProductionTranslationCost());
}
public void estimateBudget() throws SQLException {
this.subRequestCount++;
showBudget();
}
/**
* calculte the estimate budget for Asset CU By Sophia
*
* @throws SQLException
*/
public void editBudgetOk() throws SQLException{
HttpServletRequest request = getRequest();
// retrieve parameters
String hidEstProCosts = request.getParameter("hidEstProCosts");
String hidEstTransCosts = request.getParameter("hidEstTransCosts");
String hidActualHandlingCosts = request.getParameter("hidActualHandlingCosts");
String hidActualTransCosts = request.getParameter("hidactualTransCosts");
String[] estProCosts = new String[0];
String[] estTransCosts = new String[0];
String[] actualHandlingCosts = new String[0];
String[] actualTransCosts = new String[0];
if (hidEstProCosts != null) {
estProCosts = hidEstProCosts.split("#");
}
if (hidEstTransCosts != null) {
estTransCosts = hidEstTransCosts.split("#");
}
if (hidActualHandlingCosts != null) {
actualHandlingCosts = hidActualHandlingCosts.split("#");
}
if (hidActualTransCosts != null) {
actualTransCosts = hidActualTransCosts.split("#");
}
BigDecimal estProTotal = new BigDecimal(0.0);
BigDecimal estTransTotal = new BigDecimal(0.0);
//Set estimateProCost, estimateTransCost, actualProCost, actualTranCost to Asset
List tarLanguages = asset.getTargetLanguages();
for(int i=0;i<tarLanguages.size();i++){
LAsset lasset = (LAsset)tarLanguages.get(i);
double estProCost = Double.parseDouble(estProCosts[i]);
double estTransCost = Double.parseDouble(estTransCosts[i]);
lasset.setEstProCost(estProCost);
lasset.setEstCost(estTransCost);
lasset.setActualProCost(Double.parseDouble(actualHandlingCosts[i]));
lasset.setActualTransCost(Double.parseDouble(actualTransCosts[i]));
estProTotal = estProTotal.add(new BigDecimal(lasset.getEstProCost()));
estTransTotal = estTransTotal.add(new BigDecimal(lasset.getEstCost()));
}
asset.setEN_COST(estTransTotal.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue());
asset.setNLV_COST(estProTotal.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue());
}
/**
* Populate the Asset bean based on the assetid
* @param assetID
*/
private void populateAsset(String assetID) throws SQLException{
//ujjal added - retireve BUs based on user login ************
Role role = SessionAccess.getSessionUserProfile().getCurrentRole();
TreeSet buSet = role.getBuSet();
List buList = new ArrayList();
for (Iterator iter = buSet.iterator(); iter.hasNext();)
{
com.ibm.g11n.e2e.ui.bean.BusinessUnit bu = (com.ibm.g11n.e2e.ui.bean.BusinessUnit) iter.next();
BusinessUnit newBU = new BusinessUnit();
newBU.setCode(bu.getBuid());
newBU.setName(bu.getBuid());
buList.add(newBU);
}
// System.out.println("buList size: " + buList.size());
if(assetID == null){
String buID = null;
if(buList.size()>0)
buID = ((BusinessUnit)buList.get(0)).getCode();
// System.out.println("buID: " + buID);
List majors = MajorService.$.retrieveMajorsByBU(buID);
asset.setAvaiMajors(E2EUIUtility.composeSelectItemList(majors));
if(majors != null && majors.size() > 0){
int majorID = asset.getMajorID();
if(majorID ==0)
majorID = ((Major)majors.get(0)).getId();
List minors = MinorService.$.retrieveMinors(majorID);
asset.setAvaiMinors(E2EUIUtility.composeSelectItemList(minors));
}
}else{
asset = ManageAssetService.$.retrieveAsset(Integer.valueOf(assetID).intValue());
if(operationType.equals(TYPE_COPY)){
asset = ManageAssetService.$.retrieveAsset(Integer.valueOf(assetID).intValue());
asset.setStatus(Asset.STATUS_DRAFT);
asset.setCreatedDate(new Date());
asset.setTargetLanguages(new ArrayList());
asset.setAssetPlanIDList(new ArrayList());
asset.setAssetPlanIDs(null);
asset.setAssetPlanNameList(new ArrayList());
asset.setAssetPlanNames(null);
}
//stores an copy of the asset into attribute "assetCopy"
// assetCopy = ManageAssetService.$.retrieveAsset(Integer.valueOf(assetID).intValue());
List majors = MajorService.$.retrieveMajorsByBU(asset.getBuCode()); //need
asset.setAvaiMajors(E2EUIUtility.composeSelectItemList(majors));
if(majors != null && majors.size() > 0){
List minors = MinorService.$.retrieveMinors(asset.getMajorID());
asset.setAvaiMinors(E2EUIUtility.composeSelectItemList(minors));
}
associateBean.setSelectedPlanIDs(asset.getAssetPlanIDs());
}
//set available BU List
asset.setAvaiBUs(buList);
}
/**
* Populate brand and minor list after user change the selected BU
*
*/
public void populateMajorList(){
this.subRequestCount++;
HttpServletRequest request = getRequest();
String buID = request.getParameter("buID");
List majors = MajorService.$.retrieveMajorsByBU(buID);
asset.setAvaiMajors(E2EUIUtility.composeSelectItemList(majors));
}
/**
*Popuate(update) minor List after user change the selected brand
*/
public void populateMinorList(){
this.subRequestCount++;
HttpServletRequest request = getRequest();
String majorID = request.getParameter("majorID");
if(majorID != null){
List minors = MinorService.$.retrieveMinors(Integer.valueOf(majorID).intValue());
asset.setAvaiMinors(E2EUIUtility.composeSelectItemList(minors));
}else{
// System.out.println("retrieve minor...");
String buID = request.getParameter("buID");
// System.out.println("bu id: " + buID);
List majors = MajorService.$.retrieveMajorsByBU(buID);
this.asset.setMajor(null); // set the selected brand to null
if(majors != null && majors.size() > 0){
// System.out.println("major id: " + ((Major)majors.get(0)).getId());
List minors = MinorService.$.retrieveMinors(((Major)majors.get(0)).getId());
// System.out.println("minor size: " + minors.size());
asset.setAvaiMinors(E2EUIUtility.composeSelectItemList(minors));
}
}
}
/**
*Estimate translation begin date based on publish date
*/
public void estimateTrDate(){
this.subRequestCount++;
String publishDateStr = getRequest().getParameter("publishDate");
// System.out.println("publish date: " + publishDateStr);
try {
Calendar publishDate = E2EUtility.getCalendar(publishDateStr);
publishDate.add(Calendar.DAY_OF_MONTH, -15);
Date translationDate = publishDate.getTime();
asset.setTranslationStartDate(translationDate);
// System.out.println("translation date: " + translationDate.toString());
} catch (ParseException e) {
e.printStackTrace();
}
}
// getter and setter method
public String getOperationType() {
return operationType;
}
public void setOperationType(String operationType) {
this.operationType = operationType;
}
public AssociateCUPlanBean getAssociateBean() {
return associateBean;
}
public void setAssociateBean(AssociateCUPlanBean associateBean) {
this.associateBean = associateBean;
}
public Asset getAsset() {
return asset;
}
public void setAsset(Asset asset) {
this.asset = asset;
}
public String getAssoicateTipText() {
return assoicateTipText;
}
public void setAssoicateTipText(String assoicateTipText) {
this.assoicateTipText = assoicateTipText;
}
public int getSubRequestCount() {
return subRequestCount;
}
public void setSubRequestCount(int subRequestCount) {
this.subRequestCount = subRequestCount;
}
// public Asset getAssetCopy() {
// return assetCopy;
// }
//
// public void setAssetCopy(Asset assetCopy) {
// this.assetCopy = assetCopy;
// }
public String getAssetPlanStatus() {
String status = AssetPlan.STATUS_DRAFT;
if(operationType.equalsIgnoreCase(TYPE_UPDATE)){
try {
status = ManageAssetPlanService.$
.selectAssetPlanStatusByAsset(asset.getId());
} catch (SQLException e) {
e.printStackTrace();
}
}
return status;
}
public void setAssetPlanStatus(String status) {
}
public static Log logger = LogFactory.getLog(ManageAssetFacesBean.class);
public static final String TYPE_CREATE = "create";
public static final String TYPE_COPY = "copy";
public static final String TYPE_UPDATE = "update";
private String operationType = TYPE_CREATE;
private Asset asset = new Asset();
private AssetPlan assetPlan;
//When do 'edit' asset operation, this asset will stores the original value retrieved from database,
//and "asset" attribute stores the updated data which will be pushed back to the database
private Asset assetCopy = new Asset();
private AssociateCUPlanBean associateBean = new AssociateCUPlanBean();
private boolean isSubmitOutputAssetDocNumber = false;
// the tip text when assoicate asset to asset plan ;
private String assoicateTipText;
private int subRequestCount = 0;
private int lastAssetType;
//onload method
public void onload(FacesContext context) throws SQLException{
// System.out.println("enter asset page onload..., subRequestCount is " + subRequestCount);
if (hasError()) {
return;
}
if(subRequestCount > 0){
subRequestCount--;
return;
}
HttpServletRequest request = getRequest();
operationType = request.getParameter("type");
if(operationType == null){
operationType = TYPE_CREATE;
}
asset = new Asset();
//This statement is just for create new asset type
asset.setStatus(Asset.STATUS_DRAFT);
String assetID = request.getParameter("assetID");
populateAsset(assetID);
//clear output asset doc number config info
if(TYPE_CREATE.equals(operationType)){
asset.getOutputAssetDocNumList().clear();
asset.setQuantity(1);
}
//populate available assetTypes
//List assetTypes = ManageAssetService.$.retrieveSuperModuleAssetTypes();
List assetTypes = ManageAssetService.$.retrieveAssetTypes(true);
List assetTypeItems = E2EUIUtility.composeSelectItemList(assetTypes);
asset.setAvaiAssetTypes(assetTypeItems);
}
/**
* When the doc number config page is loaded, this method will be called
* @param context
*/
public void onload_docNumConfig(FacesContext context) throws SQLException{
// System.out.println("enter doc number on load...");
if(this.isSubmitOutputAssetDocNumber == true){
this.isSubmitOutputAssetDocNumber = false;
}else{
int contentType = asset.getTypeID();
int oldType = assetCopy.getTypeID();
if(contentType == oldType){
asset.setOutputAssetDocNumList(assetCopy.getOutputAssetDocNumList());
}
else if(contentType !=lastAssetType){
lastAssetType = contentType;
List outputAssetTypeList = ManageAssetService.$.retrieveOutputAssetTypes(contentType);
List docNumList = new ArrayList();
if(outputAssetTypeList.size() > 0){ //is super module
// System.out.println("is output asset");
int childNum = outputAssetTypeList.size();
for(int i = 0; i < childNum; i++){
OutputAsset outputAsset = new OutputAsset();
outputAsset.setName(((AssetType)outputAssetTypeList.get(i)).getName());
docNumList.add(outputAsset);
}
}
asset.setOutputAssetDocNumList(docNumList);
}
}
}
/**
* setup output asset doc number
*
*/
public void setupOutputAssetDocNumber(){
this.isSubmitOutputAssetDocNumber = true;
}
//action methods
/**
* Load the default average page
*/
public void loadDefaultPageNum() throws SQLException {
this.subRequestCount++;
HttpServletRequest request = getRequest();
String assetTypeID = request.getParameter("assetTypeID");
AssetType type = ManageAssetService.$.retrieveAssetTypeByID(Integer.parseInt(assetTypeID));
int avgPage = type.getAvgPage();
asset.setAvgPages(avgPage);
}
/**
* Load the default average words per page
*
*/
public void loadDefaultWordNum() throws SQLException{
this.subRequestCount++;
HttpServletRequest request = getRequest();
String assetTypeID = request.getParameter("assetTypeID");
AssetType type = ManageAssetService.$.retrieveAssetTypeByID(Integer.parseInt(assetTypeID));
int avgWord = type.getAvgWordPerPage();
asset.setAvgWordsPerPage(avgWord);
}
/**
* Set asset content type before
*/
public void setAssetType(){
HttpServletRequest request = getRequest();
String assetTypeID = request.getParameter("assetTypeID");
asset.setTypeID(Integer.parseInt(assetTypeID));
}
/**
* Create Consumablue Unit-- The type could be
* Product CU or Asset CU
* @throws Exception
*/
public String createAsset() throws Exception{
asset.setId(0);
if (!asset.getStatus().equalsIgnoreCase(Asset.STATUS_DRAFT)) {
asset.setStatus(Asset.STATUS_DRAFT);
}
//We need to get the correct data before validation
ManageAssetService.$.getPreparedForDBOperation(asset);
if (!validateAsset(asset)) {
return "";
}
ManageAssetService.$.createAsset(asset);
this.operationType = TYPE_UPDATE;
return "createSuccess";
}
public boolean validateAsset(Asset tempAsset) {
boolean result = true;
if ("Yes".equals(tempAsset.getLink_to_ann())
&& (tempAsset.getAnnouncement() == null || tempAsset
.getAnnouncement().length() == 0)) {
FacesContext.getCurrentInstance().addMessage(
"form1:Ann",
new FacesMessage(FacesMessage.SEVERITY_ERROR,
"The announcement could not be empty.",
"The announcement could not be empty."));
result = false;
}
if (tempAsset.getTranslationStartDate().after(
tempAsset.getPublishDate())) {
FacesContext
.getCurrentInstance()
.addMessage(
"form1:translationStartDate",
new FacesMessage(
FacesMessage.SEVERITY_ERROR,
"The translation start date should not be after the publish date .",
"The translation start date should not be after the publish date ."));
result = false;
}
try {
if (ManageAssetService.$.isNameUsed(tempAsset.getName(), tempAsset
.getBuCode(), tempAsset.getId())) {
FacesContext.getCurrentInstance().addMessage(
"form1:assetName",
new FacesMessage("Please check the name.",
"The name has been used in \""
+ tempAsset.getBuCode() + "\"."));
result = false;
}
String message = checkBudget(tempAsset);
if(message.length()>0){
FacesContext.getCurrentInstance().addMessage(
"form1:translationCost",
new FacesMessage(FacesMessage.SEVERITY_ERROR,
message,
message + "Please add budget first."));
result = false;
}
} catch (SQLException e) {
e.printStackTrace();
result = false;
}
return result;
}
private String checkBudget(Asset asset) throws SQLException {
if (asset.getStatus() == Asset.STATUS_DRAFT || !"GTS".equals(asset.getBuCode())) {
return "";
}
List lAssets = asset.getTargetLanguages();
BudgetPlan bp = null;
String message = "";
String language = "";
for (Iterator it = lAssets.iterator(); it.hasNext();) {
LAsset lAsset = (LAsset) it.next();
if (lAsset.getPrioritized().equals(LAsset.PRIORITIZE_YES)) {
if (assetPlan == null) {
assetPlan = ManageAssetPlanService.$.
retrieveAssetPlan(Integer.valueOf(asset.getAssetPlanIDs()).intValue());
}
LBudgetPlan tempLBudgetPlan = null;
if (bp == null) {
bp = ManageBudgetPlanService.$.retrieveBudgetPlan(assetPlan.getBudgetPlanId());
if (bp == null) {
return "";
}
Map lbpMap = bp.getLanguageBudgets();
tempLBudgetPlan = (LBudgetPlan) lbpMap.get(lAsset.getLanguageID());
}
if (tempLBudgetPlan == null) {
return ("The selected language " + lAsset.getLanguageName()
+ " isn't included in budget plan " + bp.getName() + ". ");
}
double costEstimation = lAsset.getEstCost() + lAsset.getEstProCost();
double actualCost = lAsset.getActualProCost() + lAsset.getActualTransCost();
double remaining = tempLBudgetPlan.getRemainingAmount() + actualCost - costEstimation;
if (remaining < 0) {
language += "," + tempLBudgetPlan.getLanguageName();
}
}
}
if (!StringUtils.isBlank(language)) {
message = "There is no more budget for " + language + ".";
}
return message;
}
/**
* Update Consumable Unit -- The type could be Product CU or Asset CU
*
* @return
* @throws SQLException
*/
public String updateAsset() throws Exception{
//We need to get the correct data before validation
ManageAssetService.$.getPreparedForDBOperation(asset);
if(!validateAsset(asset)){
return "";
}
ManageAssetService.$.updateAsset(asset,assetPlan);
return "updateSuccess";
}
/**
* Refine the asset plan records, only active asset plan can be associated to
* @return
* @throws SQLException
*/
private String getBUCodebyAsset(String assetIDs) throws SQLException {
assoicateTipText = "";
System.out.println("assetIDs:"+assetIDs);
List BUs = ManageAssetService.$.retrieveAssetBU(assetIDs);
if (BUs != null && BUs.size() == 1) {
associateBean.setSelectedCUIDs(assetIDs);
return (String) BUs.get(0);
} else {
assoicateTipText = "The assets selected must belong to one business unit.";
}
return null;
}
private void retrieveLinkablePlans(String bu) throws SQLException {
assoicateTipText = "";
AssetPlanSearchCriteria criteria = new AssetPlanSearchCriteria();
criteria.setBuCode(bu);
// List statusList = new ArrayList();
// statusList.add(AssetPlan.STATUS_DRAFT);
// statusList.add(AssetPlan.STATUS_PUBLISH);
// statusList.add(AssetPlan.STATUS_PRIORIRIE_REQUESTED);
// statusList.add(AssetPlan.STATUS_PRIORIRIE_RETURNED);
// statusList.add(AssetPlan.STATUS_IN_TRANSLATION);
// statusList.add(AssetPlan.STATUS_IN_VALIDATION);
// statusList.add(AssetPlan.STATUS_COMPLETE);
// criteria.setStatusList(statusList);
List plans = ManageAssetPlanService.$.retrieveAssetPlanBySC(criteria);
if (plans == null || plans.size() == 0) {
assoicateTipText = "There is no Product/Program that can be assoicate to.";
} else {
this.associateBean.setAssociatedPlans(plans);
}
// System.out.println("assoicateTipText: " + assoicateTipText);
}
public void onload_associatePlanPage(FacesContext context)
throws SQLException {
String assetIDs = getRequest().getParameter("assetIDs");
System.out.println("assetIDs:"+assetIDs);
associateBean = new AssociateCUPlanBean();
if (assetIDs != null && assetIDs.length() > 0 && !"0".equals(assetIDs)) {
AssetPlan tempAssetPlan;
Integer assetID;
List assetIDList = Arrays.asList(assetIDs.split(","));
// check whether the linked asset plan is in translation status;
for (Iterator it = assetIDList.iterator(); it.hasNext();) {
assetID = Integer.valueOf((String) it.next());
tempAssetPlan = ManageAssetPlanService.$
.retrieveAssetPlanByAssetID(assetID.intValue());
if (tempAssetPlan != null) {
if (AssetPlan.STATUS_IN_TRANSLATION
.equalsIgnoreCase(tempAssetPlan.getStatus())
|| AssetPlan.STATUS_IN_VALIDATION
.equalsIgnoreCase(tempAssetPlan.getStatus())
|| AssetPlan.STATUS_COMPLETE
.equalsIgnoreCase(tempAssetPlan.getStatus())) {
// give some notification
assoicateTipText = "The asset has been linked to Product/Program \""
+ tempAssetPlan.getName()
+ "\" which is already in \""
+ tempAssetPlan.getStatus()
+ "\" status, change the link is not allowed.";
return;
} else {
associateBean.setSelectedPlanIDs(String.valueOf(tempAssetPlan.getId()));
}
} else {
associateBean.setSelectedPlanIDs("");
}
}
String bu = getBUCodebyAsset(assetIDs);
if (bu != null)
retrieveLinkablePlans(bu);
} else {
String bu = getRequest().getParameter("bu");
retrieveLinkablePlans(bu);
}
}
/**
* Associate Assets to Plans (currently it's asset to asset plans, in the
* future, we may support cu&idplan)
*
*/
public String associateAssetToAssetPlan() throws Exception {
String result = "";
List assetIDs = Arrays.asList(associateBean.getSelectedCUIDs().split(
","));
List assetPlanIDs = Arrays.asList(associateBean.getSelectedPlanIDs()
.split(","));
int assetId = Integer.valueOf((String) assetIDs.get(0)).intValue();
int assetPlanId = Integer.valueOf((String) assetPlanIDs.get(0))
.intValue();
if (assetId > 0 && assetPlanId > 0) {
Asset asset = ManageAssetService.$.retrieveAsset(assetId);
AssetPlan ap = ManageAssetPlanService.$
.retrieveAssetPlan(assetPlanId);
try {
BaseDao.startTransaction();
ManageAssetService.$.deleteAssetToAssetPlanLinksByAsset(asset
.getId());
ManageAssetService.$.associateAssetToAssetPlan(asset, ap);
BaseDao.commitTransaction();
} finally {
BaseDao.endTransaction();
}
result = "success";
} else {
}
return result;
}
/**
* Estimate budget for Asset CU
*
* @throws SQLException
*/
public void showBudget() throws SQLException {
HttpServletRequest request = getRequest();
Asset tempAsset = ManageAssetService.$.composeCostEstimatorAssetBean(request);
if (asset != null) {
tempAsset.setTargetLanguages(asset.getTargetLanguages());
}
//Compose target languages
ManageAssetService.$.composeLAssetList(tempAsset);
//Estimate the cost
CostEstimation costEstimation = CostEstimationService.$.calculateCost(tempAsset);
asset.setEN_COST(costEstimation.getTranslationAndCDLayoutCharges());
asset.setNLV_COST(costEstimation.getStiboProductionTranslationCost());
}
public void estimateBudget() throws SQLException {
this.subRequestCount++;
showBudget();
}
/**
* calculte the estimate budget for Asset CU By Sophia
*
* @throws SQLException
*/
public void editBudgetOk() throws SQLException{
HttpServletRequest request = getRequest();
// retrieve parameters
String hidEstProCosts = request.getParameter("hidEstProCosts");
String hidEstTransCosts = request.getParameter("hidEstTransCosts");
String hidActualHandlingCosts = request.getParameter("hidActualHandlingCosts");
String hidActualTransCosts = request.getParameter("hidactualTransCosts");
String[] estProCosts = new String[0];
String[] estTransCosts = new String[0];
String[] actualHandlingCosts = new String[0];
String[] actualTransCosts = new String[0];
if (hidEstProCosts != null) {
estProCosts = hidEstProCosts.split("#");
}
if (hidEstTransCosts != null) {
estTransCosts = hidEstTransCosts.split("#");
}
if (hidActualHandlingCosts != null) {
actualHandlingCosts = hidActualHandlingCosts.split("#");
}
if (hidActualTransCosts != null) {
actualTransCosts = hidActualTransCosts.split("#");
}
BigDecimal estProTotal = new BigDecimal(0.0);
BigDecimal estTransTotal = new BigDecimal(0.0);
//Set estimateProCost, estimateTransCost, actualProCost, actualTranCost to Asset
List tarLanguages = asset.getTargetLanguages();
for(int i=0;i<tarLanguages.size();i++){
LAsset lasset = (LAsset)tarLanguages.get(i);
double estProCost = Double.parseDouble(estProCosts[i]);
double estTransCost = Double.parseDouble(estTransCosts[i]);
lasset.setEstProCost(estProCost);
lasset.setEstCost(estTransCost);
lasset.setActualProCost(Double.parseDouble(actualHandlingCosts[i]));
lasset.setActualTransCost(Double.parseDouble(actualTransCosts[i]));
estProTotal = estProTotal.add(new BigDecimal(lasset.getEstProCost()));
estTransTotal = estTransTotal.add(new BigDecimal(lasset.getEstCost()));
}
asset.setEN_COST(estTransTotal.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue());
asset.setNLV_COST(estProTotal.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue());
}
/**
* Populate the Asset bean based on the assetid
* @param assetID
*/
private void populateAsset(String assetID) throws SQLException{
//ujjal added - retireve BUs based on user login ************
Role role = SessionAccess.getSessionUserProfile().getCurrentRole();
TreeSet buSet = role.getBuSet();
List buList = new ArrayList();
for (Iterator iter = buSet.iterator(); iter.hasNext();)
{
com.ibm.g11n.e2e.ui.bean.BusinessUnit bu = (com.ibm.g11n.e2e.ui.bean.BusinessUnit) iter.next();
BusinessUnit newBU = new BusinessUnit();
newBU.setCode(bu.getBuid());
newBU.setName(bu.getBuid());
buList.add(newBU);
}
// System.out.println("buList size: " + buList.size());
if(assetID == null){
String buID = null;
if(buList.size()>0)
buID = ((BusinessUnit)buList.get(0)).getCode();
// System.out.println("buID: " + buID);
List majors = MajorService.$.retrieveMajorsByBU(buID);
asset.setAvaiMajors(E2EUIUtility.composeSelectItemList(majors));
if(majors != null && majors.size() > 0){
int majorID = asset.getMajorID();
if(majorID ==0)
majorID = ((Major)majors.get(0)).getId();
List minors = MinorService.$.retrieveMinors(majorID);
asset.setAvaiMinors(E2EUIUtility.composeSelectItemList(minors));
}
}else{
asset = ManageAssetService.$.retrieveAsset(Integer.valueOf(assetID).intValue());
if(operationType.equals(TYPE_COPY)){
asset = ManageAssetService.$.retrieveAsset(Integer.valueOf(assetID).intValue());
asset.setStatus(Asset.STATUS_DRAFT);
asset.setCreatedDate(new Date());
asset.setTargetLanguages(new ArrayList());
asset.setAssetPlanIDList(new ArrayList());
asset.setAssetPlanIDs(null);
asset.setAssetPlanNameList(new ArrayList());
asset.setAssetPlanNames(null);
}
//stores an copy of the asset into attribute "assetCopy"
// assetCopy = ManageAssetService.$.retrieveAsset(Integer.valueOf(assetID).intValue());
List majors = MajorService.$.retrieveMajorsByBU(asset.getBuCode()); //need
asset.setAvaiMajors(E2EUIUtility.composeSelectItemList(majors));
if(majors != null && majors.size() > 0){
List minors = MinorService.$.retrieveMinors(asset.getMajorID());
asset.setAvaiMinors(E2EUIUtility.composeSelectItemList(minors));
}
associateBean.setSelectedPlanIDs(asset.getAssetPlanIDs());
}
//set available BU List
asset.setAvaiBUs(buList);
}
/**
* Populate brand and minor list after user change the selected BU
*
*/
public void populateMajorList(){
this.subRequestCount++;
HttpServletRequest request = getRequest();
String buID = request.getParameter("buID");
List majors = MajorService.$.retrieveMajorsByBU(buID);
asset.setAvaiMajors(E2EUIUtility.composeSelectItemList(majors));
}
/**
*Popuate(update) minor List after user change the selected brand
*/
public void populateMinorList(){
this.subRequestCount++;
HttpServletRequest request = getRequest();
String majorID = request.getParameter("majorID");
if(majorID != null){
List minors = MinorService.$.retrieveMinors(Integer.valueOf(majorID).intValue());
asset.setAvaiMinors(E2EUIUtility.composeSelectItemList(minors));
}else{
// System.out.println("retrieve minor...");
String buID = request.getParameter("buID");
// System.out.println("bu id: " + buID);
List majors = MajorService.$.retrieveMajorsByBU(buID);
this.asset.setMajor(null); // set the selected brand to null
if(majors != null && majors.size() > 0){
// System.out.println("major id: " + ((Major)majors.get(0)).getId());
List minors = MinorService.$.retrieveMinors(((Major)majors.get(0)).getId());
// System.out.println("minor size: " + minors.size());
asset.setAvaiMinors(E2EUIUtility.composeSelectItemList(minors));
}
}
}
/**
*Estimate translation begin date based on publish date
*/
public void estimateTrDate(){
this.subRequestCount++;
String publishDateStr = getRequest().getParameter("publishDate");
// System.out.println("publish date: " + publishDateStr);
try {
Calendar publishDate = E2EUtility.getCalendar(publishDateStr);
publishDate.add(Calendar.DAY_OF_MONTH, -15);
Date translationDate = publishDate.getTime();
asset.setTranslationStartDate(translationDate);
// System.out.println("translation date: " + translationDate.toString());
} catch (ParseException e) {
e.printStackTrace();
}
}
// getter and setter method
public String getOperationType() {
return operationType;
}
public void setOperationType(String operationType) {
this.operationType = operationType;
}
public AssociateCUPlanBean getAssociateBean() {
return associateBean;
}
public void setAssociateBean(AssociateCUPlanBean associateBean) {
this.associateBean = associateBean;
}
public Asset getAsset() {
return asset;
}
public void setAsset(Asset asset) {
this.asset = asset;
}
public String getAssoicateTipText() {
return assoicateTipText;
}
public void setAssoicateTipText(String assoicateTipText) {
this.assoicateTipText = assoicateTipText;
}
public int getSubRequestCount() {
return subRequestCount;
}
public void setSubRequestCount(int subRequestCount) {
this.subRequestCount = subRequestCount;
}
// public Asset getAssetCopy() {
// return assetCopy;
// }
//
// public void setAssetCopy(Asset assetCopy) {
// this.assetCopy = assetCopy;
// }
public String getAssetPlanStatus() {
String status = AssetPlan.STATUS_DRAFT;
if(operationType.equalsIgnoreCase(TYPE_UPDATE)){
try {
status = ManageAssetPlanService.$
.selectAssetPlanStatusByAsset(asset.getId());
} catch (SQLException e) {
e.printStackTrace();
}
}
return status;
}
public void setAssetPlanStatus(String status) {
}
发表评论
-
jsf readonly 字段提交的时候是不会执行set方法的
2010-09-10 10:05 995jsf readonly= 'true ' jsf read ... -
自动换行word-break:break-all和word-wrap:break-word的区别
2010-05-20 10:40 2913word-break:break-all 单词 ... -
h:panelGrid 属性详解
2010-05-12 14:29 2005一.页面布局: <h:panelGrid >样式表 ... -
panelGrid, panelGroup
2010-05-12 14:00 1097<h:panelGrid columns="2 ...
相关推荐
- **多阶段处理请求**:Nginx通过多个阶段来处理一个请求,每个阶段可以由不同的模块处理。 - **返回响应数据**:客户端发送请求后,Nginx会生成相应的响应内容。 - **pipeline请求**:一种特殊的请求处理方式,...
srcache-nginx-module, 基于透明subrequest的任意 Nginx 位置缓存布局 电子邮件名称ngx_srcache - 基于透明subrequest的任意 Nginx 位置缓存布局:这里 MODULE 没有与 Nginx 源一起分发。 我们将看到安装说明( 参见...
`laravel-sub-request`是一个专门为Laravel设计的助手库,它提供了一种方便的方式来向应用程序发出内部API的子请求。 Laravel的子请求并不是HTTP层面的请求,而是模拟了一个新的请求环境,使得在当前请求的生命周期...
Nginx的一个强大功能是其虚拟主机配置,允许一台服务器同时处理多个域名的Web请求。教程会逐步引导如何准备站点,配置虚拟主机,并重新启动Nginx以使配置生效。日志配置也是Nginx管理中不可忽视的一部分,包括如何...
- **nginx的进程机制**:Nginx采用了一个主进程和多个工作进程的模型来处理请求,这种设计有助于提高系统的稳定性和效率。 ##### Nginx基础设施 - **内存池**:Nginx使用内存池来管理内存分配,避免频繁的系统调用...
这表示当前请求是一个顶级请求,没有父请求。 2. **模块处理与子请求创建**: 请求进入jtxy模块进行处理,jtxy模块调用`ngx_http_subrequest`创建一个子请求。在`ngx_http_subrequest`中,`count`增加1,因为它...
2. 利用Nginx的子请求(subrequest)功能创建一个验证模块。 3. 编写一个基于Lua的Nginx模块。 由于增加额外请求会导致延迟问题,子请求方案被排除。Python/Flask的解决方案可能对Nginx支持不足,因此也被淘汰。最终...
`mod_rewrite` 是 Apache HTTP 服务器的一个模块,它允许管理员基于规则来重写 URL,并且执行多种类型的 URL 转换和过滤操作。这对于实现网站的 SEO 优化、URL 重定向、内容管理等非常有用。`mod_rewrite-cheat-...
然后重点介绍如何开发HTTP模块(含HTTP过滤模块)来得到定制的Nginx,其中包括开发一个功能复杂的模块所需要了解的各种知识,如Nginx的基础数据结构、配置项的解析、记录日志的工具以及upstream、subrequest的使用...
Nginx是一个开源的HTTP和反向代理服务器,以其稳定性、功能集丰富、低资源消耗而著名。在云时代,由于端设备的多样化,服务器性能成为关键,Nginx因其高效性能在企业中逐渐替代Apache。陶辉指出,企业使用Nginx时,...
然后重点介绍如何开发HTTP模块(含HTTP过滤模块)来得到定制的Nginx,其中包括开发一个功能复杂的模块所需要了解的各种知识,如Nginx的基础数据结构、配置项的解析、记录日志的工具以及upstream、subrequest的使用...
然后重点介绍如何开发HTTP模块(含HTTP过滤模块)来得到定制的Nginx,其中包括开发一个功能复杂的模块所需要了解的各种知识,如Nginx的基础数据结构、配置项的解析、记录日志的工具以及upstream、subrequest的使用...
然后重点介绍如何开发HTTP模块(含HTTP过滤模块)来得到定制的Nginx,其中包括开发一个功能复杂的模块所需要了解的各种知识,如Nginx的基础数据结构、配置项的解析、记录日志的工具以及upstream、subrequest的使用...
然后重点介绍如何开发HTTP模块(含HTTP过滤模块)来得到定制的Nginx,其中包括开发一个功能复杂的模块所需要了解的各种知识,如Nginx的基础数据结构、配置项的解析、记录日志的工具以及upstream、subrequest的使用...