cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

SAP ECTR-CONNECTOR - Add Original in Java

Kottur
Discoverer
0 Likes
254

Need some assitance in how to add pdf file to the Document. Here is the sample java code

 

package ECTRC;
 
import com.dscsag.plm.comm.PlmRequestPartImpl;
import com.dscsag.plm.comm.attributes.PlmAttributeNames;
 
import java.util.Collection;
 
import com.dscsag.plm.comm.*;
 
public class CreateDocument {
 
public static void main(String args[]) {
CreateDocument anbc = new CreateDocument();
PlmConnectorFactory factory = new PlmConnectorFactory();
PlmConnectorConfig config = new PlmConnectorConfig("DS4");
try {
anbc.importOnDemand2(factory.getPlmConnector(config));
} catch (Exception e)
{
e.printStackTrace();
}
}
private static void importOnDemand2(PlmConnector connector)
  {
    try
    {
      String modelFileName = "c:\\Ali\\Design Spec.pdf";
     // PlmRequestPartImpl file = new PlmRequestPartImpl(modelFileName, PartType.ADDITIONAL_PART)
      
      PlmRequestPartImpl drawingPart = new PlmRequestPartImpl(modelFileName);       
      PlmMetaInfoCadImpl drawingMetaInfoCad = new PlmMetaInfoCadImpl();
      drawingPart.setMetaInfoCad(drawingMetaInfoCad);
      // model reference
      drawingMetaInfoCad.components().add(new PlmMetaInfoComponentImpl(modelFileName));
      // suggestions by attributes
      drawingMetaInfoCad.getAttributes().addAttribute(PlmAttributeNames.DOCUMENT_DESCR, "Drawing for PLM cube");
      drawingMetaInfoCad.getAttributes().addAttribute(PlmAttributeNames.DOCUMENT_TYPE, "STP"); // DType
      drawingMetaInfoCad.getAttributes().addAttribute(PlmAttributeNames.AUTHORIZATION_GROUP, "ZDEF");
      drawingMetaInfoCad.getAttributes().addAttribute(PlmAttributeNames.DOCUMENT_DTYPE, "SWSTP");
      
      
      // ----------------------------------
      // do plm call
      // ----------------------------------
      PlmCreateDocumentsRequest createRequest = new PlmCreateDocumentsRequest();
      createRequest.setShowDialogOption(ShowDialogOption.SHOW_NEVER);
//       createRequest.addRequestPart(modelPart);
      createRequest.addRequestPart(drawingPart);
      PartType abc = PartType.ADDITIONAL_PART;
      PlmRequestResult callResult = connector.createDocuments(createRequest);
      // ----------------------------------
      // handle result
      // ----------------------------------
      if (callResult.isRequestCancelled())
      {
        // TODO handle cancel by user
      }
      else if (callResult.isRequestFailed())
      {
        PlmError error = callResult.getError();
        String errorMsg = error.getMessage();
        // TODO handle call error
      }
      else
      {
        Collection<CreateDocumentEntry> createEntryies = createRequest.getCreateDocumentEntries();
        for (CreateDocumentEntry createEntry : createEntryies)
        {
          // handle create entry
          ProcessEntryState state = createEntry.getState();
          switch (state)
          {
            case STATE_ERROR :
              if (createEntry.hasMessage())
              {
                PlmError error = createEntry.getMessage();
                String errorMsg = error.getMessage();
                // TODO handle message: show to user, logging, ...
              }
              // TODO handle entry error
              break;
            case STATE_DONE :
              String partFilename = createEntry.getRequestPart().getFilename();
              String newFilename = createEntry.getNewFilename();
              PlmMetaInfoSap attributesFromSap = createEntry.getMetaInfoSap();
 
              // TODO handle created documents: update attributes, copy files, and call connector.save(...)
              break;
            case STATE_IGNORED :
              // Part ignored, maybe document already exist in SAP.
              // check message
              if (createEntry.hasMessage())
              {
                PlmError error = createEntry.getMessage();
                String errorMsg = error.getMessage();
                // TODO handle message: show to user, logging, ...
              }
              break;
            case STATE_UNKNOWN :
            default :
              // part was not processed by PLM, maybe process error
              // check request result
              // TODO ???
              break;
          }
        }
      }
    }
    catch (Throwable t)
    {
      //logger.error(t);
    System.out.println("Error"+t);
    }
  }
}

 

Accepted Solutions (0)

Answers (0)