Tutorials > Content management > Create a content-managed resource > Integrate the new resource
Create the NavCatExtendedCatalogCreateControllerCmdImpl controller command
Procedure
- In the Enterprise Explorer view, navigate to Other Projects > WebSphereCommerceServerExtensionsLogic.
- Right-click src and select New > Class.
- In the Package field, type com.ibm.commerce.tools.catalog.commands.
- In the Name field, type NavCatExtendedCatalogCreateControllerCmdImpl.
- Click the Browse button next to the Superclass field.
- In the Superclass Selection window, type NavCatCatalogCreateControllerCmdImpl in the Choose a type field.
- In the Matching types box, select NavCatCatalogCreateControllerCmdImpl.
- Click OK.
- Click the Add button next to the Interface box.
- In the Implemented Interfaces Selection window, type NavCatCatalogCreateControllerCmd in the Choose interfaces field.
- Click OK.
- Clear the check box for Inherited abstract methods.
- Click Finish.
- Add the following imports into the class:
import java.sql.Timestamp; import java.util.Calendar; import java.util.Hashtable; import java.util.Vector; import com.ibm.commerce.base.objects.ServerJDBCHelperAccessBean; import com.ibm.commerce.command.CommandFactory; import com.ibm.commerce.common.objects.StoreAccessBean; import com.ibm.commerce.ras.ECTrace; import com.ibm.commerce.ras.ECTraceIdentifiers; import com.ibm.commerce.registry.StoreRegistry; import com.ibm.commerce.server.ECConstants; import com.ibm.commerce.tools.catalog.util.CatalogToolException; import com.ibm.commerce.tools.common.ECToolsConstants; import com.ibm.commerce.user.objects.MemberAccessBean; import com.mycompany.catalog.commands.AddExtendedCatalogDescCmd;
- Add the following code into the class:
/** * The class name for this controller command. */ public static final String CLASSNAME = "com.ibm.commerce.catalog.tools.commands.NavCatExtendedCatalogCreateControllerCmdImpl"; /* * A collection of languages being managed in the accelerator. */ private Vector m_vLanguages = new Vector(); /** * Executes the command. */ public void performExecute() throws com.ibm.commerce.exception.ECException { final String METHODNAME = "performExecute"; if(ECTrace.isTraceEnabled()) { ECTrace.entry(ECTraceIdentifiers.COMPONENT_CATALOGTOOL, CLASSNAME, METHODNAME); } // Execute the original command logic. super.performExecute(); // Get the request properties from the parent controller command Hashtable xmlObject = (Hashtable) ((Hashtable) ((Vector) requestProperties .get(ECToolsConstants.EC_XMLOBJECT)).firstElement()).get("XML"); String strCatalogCode = (String) xmlObject.get("catalogCode"); java.lang.Object obj = xmlObject.get("languages"); if (obj instanceof Hashtable) { m_vLanguages.addElement(obj); } else if (obj instanceof Vector) { m_vLanguages = (Vector) obj; } // get the owner id of the catalog Long ownerId = null; try { ownerId = getOwnerId(getCommandContext().getStoreId(), getCommandContext().getUserId()); } catch (Exception ex) { StringBuffer logMessage = new StringBuffer(); logMessage.append("Could not retrieve the owner ID of the catalog for the catalog description being created."); if(ECTrace.isTraceEnabled()) { ECTrace.trace(ECTraceIdentifiers.COMPONENT_CATALOG, CLASSNAME, METHODNAME,logMessage.toString() ); } throw new ECApplicationException(ECMessage._ERR_GENERIC, CLASSNAME, METHODNAME, logMessage.toString(), responseProperties); } if (ownerId != null) { Hashtable hLanguage = null; try { // Add each language dependent description for (int i = 0; i < m_vLanguages.size(); i++) { hLanguage = (Hashtable) m_vLanguages.elementAt(i); addCatalogExtendedDescriptionObject(strCatalogCode, hLanguage); } } catch (CatalogToolException e) { StringBuffer logMessage = new StringBuffer(); logMessage.append("Could not add the extended catalog description information for catalog code {" + strCatalogCode + "}"); if(hLanguage!=null) { logMessage.append(" and language {" + hLanguage + "}."); } if(ECTrace.isTraceEnabled()) { ECTrace.trace(ECTraceIdentifiers.COMPONENT_CATALOG, CLASSNAME, METHODNAME,logMessage.toString() ); } throw new ECApplicationException(ECMessage._ERR_GENERIC, CLASSNAME, METHODNAME, logMessage.toString(), responseProperties); } } if(ECTrace.isTraceEnabled()) { ECTrace.exit(ECTraceIdentifiers.COMPONENT_CATALOGTOOL, CLASSNAME, METHODNAME); } } /** * This method returns an owner id. If the Store Id is supplied, then it * will return the owner of the store. Else if an user Id is supplied, then * it will return the organization owner that the user belongs to. * * @return java.lang.Long * @param anStoreId * java.lang.Integer * @param anUserId * java.lang.Long * @exception javax.ejb.FinderException * @exception java.rmi.RemoteException * @exception javax.ejb.CreateException * @exception javax.naming.NamingException * @exception javax.ejb.RemoveException */ public static Long getOwnerId(Integer anStoreId, Long anUserId) throws javax.ejb.FinderException, java.rmi.RemoteException, javax.ejb.CreateException, javax.naming.NamingException, javax.ejb.RemoveException { final String METHODNAME = "getOwnerId"; if(ECTrace.isTraceEnabled()) { ECTrace.entry(ECTraceIdentifiers.COMPONENT_CATALOG, CLASSNAME, METHODNAME); } if (anStoreId != null) { StoreAccessBean abStore = StoreRegistry.singleton().find(anStoreId); // add the following if statement if it is possible you are using // store 0 if (abStore == null && anStoreId.intValue() == ECConstants.EC_NO_STOREID .intValue()) { // store 0 is not in the registry abStore = new StoreAccessBean(); abStore.setInitKey_storeEntityId(anStoreId.toString()); abStore.refreshCopyHelper(); } if(ECTrace.isTraceEnabled()) { ECTrace.trace(ECTraceIdentifiers.COMPONENT_CATALOG, CLASSNAME, METHODNAME, "Owner of store found. Store ID = " + anStoreId + "."); ECTrace.exit(ECTraceIdentifiers.COMPONENT_CATALOG, CLASSNAME, METHODNAME); } return abStore.getMemberIdInEJBType(); } else if (anUserId != null) { MemberAccessBean abMember = new MemberAccessBean(); abMember.setInitKey_MemberId(anUserId.toString()); abMember.getEJBRef(); Long[] arrayMember = abMember.getAncestors(); Long anOwnerId = null; anOwnerId = arrayMember[1]; if(ECTrace.isTraceEnabled()) { ECTrace.trace(ECTraceIdentifiers.COMPONENT_CATALOG, CLASSNAME, METHODNAME, "Owner of user found. User ID = " + anStoreId + "."); ECTrace.exit(ECTraceIdentifiers.COMPONENT_CATALOG, CLASSNAME, METHODNAME); } return anOwnerId; } else { if(ECTrace.isTraceEnabled()) { ECTrace.trace(ECTraceIdentifiers.COMPONENT_CATALOG, CLASSNAME, METHODNAME, "Missing Store ID and User ID, null is returned."); } return null; } } /** * This method creates the catalog container description object * * @param lCatalogId - * the catalog Id of the catalog whose description is being * created * @param hLanguage - * the language specific hashtable containing the description * information * * @exception CatalogToolException An exception will be throw if there is a failure updating the * catalog description information. */ private void addCatalogExtendedDescriptionObject(String strCatalogCode, Hashtable hLanguage) throws CatalogToolException { final String METHODNAME = "addCatalogExtendedDescriptionObject(Long lCatalogId, Hashtable hLanguage)"; if(ECTrace.isTraceEnabled()) { ECTrace.entry(ECTraceIdentifiers.COMPONENT_CATALOGTOOL, CLASSNAME, METHODNAME, new Object[] { strCatalogCode, hLanguage }); } String frontImage = (String) hLanguage.get("frontimage"); String backImage = (String) hLanguage.get("backimage"); String topImage = (String) hLanguage.get("topimage"); String sideImage = (String) hLanguage.get("sideimage"); if((frontImage!=null && frontImage.trim().length()>0) || (backImage!=null && backImage.trim().length()>0) || (topImage!=null && topImage.trim().length()>0) || (sideImage!=null && sideImage.trim().length()>0)) { try { AddExtendedCatalogDescCmd addExtendedCatalogDescCmd = null; addExtendedCatalogDescCmd = (AddExtendedCatalogDescCmd) CommandFactory .createCommand(AddExtendedCatalogDescCmd.CLASSNAME, getStoreId()); Timestamp ts = new Timestamp(Calendar.getInstance().getTime() .getTime()); addExtendedCatalogDescCmd.setCatalogCode(strCatalogCode); addExtendedCatalogDescCmd.setLanguageId(new Integer(hLanguage.get( "languageId").toString())); if (hLanguage.containsKey("frontimage")) { addExtendedCatalogDescCmd.setFrontImg(frontImage); } if (hLanguage.containsKey("backimage")) { addExtendedCatalogDescCmd.setBackImg(backImage); } if (hLanguage.containsKey("sideimage")) { addExtendedCatalogDescCmd.setSideImg(sideImage); } if (hLanguage.containsKey("topimage")) { addExtendedCatalogDescCmd.setTopImg(topImage); } addExtendedCatalogDescCmd.setLastModified(ts); addExtendedCatalogDescCmd.setCommandContext(getCommandContext()); addExtendedCatalogDescCmd.execute(); } catch (Exception e) { throw new CatalogToolException( "msgNavCatCatalogCreateControllerCmdFailed"); } } if(ECTrace.isTraceEnabled()) { ECTrace.exit(ECTraceIdentifiers.COMPONENT_CATALOGTOOL, CLASSNAME, METHODNAME, new Object[] {}); } }
- Save and close the file.