Search in sources :

Example 1 with PlainDocumentLocation

use of de.metas.document.model.impl.PlainDocumentLocation in project metasfresh-webui-api by metasfresh.

the class LetterRestController method createNewLetter.

@PostMapping
@ApiOperation("Creates a new letter")
public JSONLetter createNewLetter(@RequestBody final JSONLetterRequest request) {
    userSession.assertLoggedIn();
    final DocumentPath contextDocumentPath = JSONDocumentPath.toDocumentPathOrNull(request.getDocumentPath());
    // 
    // Extract context BPartner, Location and Contact
    final BoilerPlateContext context = documentCollection.createBoilerPlateContext(contextDocumentPath);
    final int bpartnerId = context.getC_BPartner_ID(-1);
    final int bpartnerLocationId = context.getC_BPartner_Location_ID(-1);
    final int contactId = context.getAD_User_ID(-1);
    // 
    // Build BPartnerAddress
    final PlainDocumentLocation documentLocation = new PlainDocumentLocation(Env.getCtx(), bpartnerId, bpartnerLocationId, contactId, ITrx.TRXNAME_None);
    Services.get(IDocumentLocationBL.class).setBPartnerAddress(documentLocation);
    final String bpartnerAddress = documentLocation.getBPartnerAddress();
    final WebuiLetter letter = lettersRepo.createNewLetter(WebuiLetter.builder().contextDocumentPath(contextDocumentPath).ownerUserId(userSession.getAD_User_ID()).adOrgId(context.getAD_Org_ID(userSession.getAD_Org_ID())).bpartnerId(bpartnerId).bpartnerLocationId(bpartnerLocationId).bpartnerAddress(bpartnerAddress).bpartnerContactId(contactId));
    return JSONLetter.of(letter);
}
Also used : DocumentPath(de.metas.ui.web.window.datatypes.DocumentPath) JSONDocumentPath(de.metas.ui.web.window.datatypes.json.JSONDocumentPath) BoilerPlateContext(de.metas.letters.model.MADBoilerPlate.BoilerPlateContext) PlainDocumentLocation(de.metas.document.model.impl.PlainDocumentLocation) IDocumentLocationBL(de.metas.document.IDocumentLocationBL) PostMapping(org.springframework.web.bind.annotation.PostMapping) ApiOperation(io.swagger.annotations.ApiOperation)

Aggregations

IDocumentLocationBL (de.metas.document.IDocumentLocationBL)1 PlainDocumentLocation (de.metas.document.model.impl.PlainDocumentLocation)1 BoilerPlateContext (de.metas.letters.model.MADBoilerPlate.BoilerPlateContext)1 DocumentPath (de.metas.ui.web.window.datatypes.DocumentPath)1 JSONDocumentPath (de.metas.ui.web.window.datatypes.json.JSONDocumentPath)1 ApiOperation (io.swagger.annotations.ApiOperation)1 PostMapping (org.springframework.web.bind.annotation.PostMapping)1