Search in sources :

Example 11 with EntityNotFoundException

use of de.metas.ui.web.exceptions.EntityNotFoundException in project metasfresh-webui-api by metasfresh.

the class PurchaseRow method getIncludedRowById.

public PurchaseRow getIncludedRowById(@NonNull final PurchaseRowId rowId) {
    final ImmutableMap<PurchaseRowId, PurchaseRow> includedRowsByRowId = this.includedRows.stream().collect(ImmutableMap.toImmutableMap(PurchaseRow::getRowId, Function.identity()));
    final PurchaseRow row = includedRowsByRowId.get(rowId);
    if (row == null) {
        throw new EntityNotFoundException("Included row not found").appendParametersToMessage().setParameter("rowId", rowId).setParameter("this", this);
    }
    return row;
}
Also used : EntityNotFoundException(de.metas.ui.web.exceptions.EntityNotFoundException)

Example 12 with EntityNotFoundException

use of de.metas.ui.web.exceptions.EntityNotFoundException in project metasfresh-webui-api by metasfresh.

the class ASIRepository method loadReadonly.

/**
 * Retrieves {@link ASIDocument} for given ASI. The document will be readonly and not save-able.
 *
 * IMPORTANT: the retrieved document is not cached, so next time it will be retrieved again
 *
 * @param attributeSetInstanceId
 * @return ASI document
 */
public ASIDocument loadReadonly(final int attributeSetInstanceId) {
    if (attributeSetInstanceId <= 0) {
        throw new EntityNotFoundException("ASI " + attributeSetInstanceId);
    }
    final ASIEditingInfo info = ASIEditingInfo.readonlyASI(attributeSetInstanceId);
    // 
    // Get the ASI descriptor
    final ASIDescriptor asiDescriptor = descriptorsFactory.getASIDescriptor(info);
    // 
    // Create the new ASI document
    final Document asiDocData = Document.builder(asiDescriptor.getEntityDescriptor()).initializeAsNewDocument(() -> DocumentId.of(attributeSetInstanceId), VERSION_DEFAULT).build();
    // 
    // If we have a template ASI, populate the ASI document from it
    final MAttributeSetInstance templateASI = info.getM_AttributeSetInstance();
    for (final I_M_AttributeInstance fromAI : Services.get(IAttributeDAO.class).retrieveAttributeInstances(templateASI)) {
        loadASIDocumentField(asiDocData, fromAI);
    }
    // 
    // Validate, log and add the new ASI document to our index
    asiDocData.checkAndGetValidStatus();
    logger.trace("Created from ASI={}: {}", templateASI, asiDocData);
    final ASIDocument asiDoc = new ASIDocument(asiDescriptor, asiDocData);
    return asiDoc.copy(CopyMode.CheckInReadonly, NullDocumentChangesCollector.instance);
}
Also used : EntityNotFoundException(de.metas.ui.web.exceptions.EntityNotFoundException) ASIEditingInfo(org.adempiere.mm.attributes.util.ASIEditingInfo) Document(de.metas.ui.web.window.model.Document) MAttributeSetInstance(org.compiere.model.MAttributeSetInstance) I_M_AttributeInstance(org.compiere.model.I_M_AttributeInstance) IAttributeDAO(org.adempiere.mm.attributes.api.IAttributeDAO)

Example 13 with EntityNotFoundException

use of de.metas.ui.web.exceptions.EntityNotFoundException in project metasfresh-webui-api by metasfresh.

the class WEBUI_M_ReceiptSchedule_AttachPhoto method doIt.

@Override
protected String doIt() throws Exception {
    final I_M_ReceiptSchedule receiptSchedule = getRecord(I_M_ReceiptSchedule.class);
    final MImage adImage = MImage.get(getCtx(), p_AD_Image_ID);
    if (adImage == null || adImage.getAD_Image_ID() <= 0) {
        throw new EntityNotFoundException("@NotFound@ @AD_Image_ID@: " + p_AD_Image_ID);
    }
    final String name = adImage.getName();
    final byte[] data = adImage.getData();
    final BufferedImage image = ImageIO.read(new ByteArrayInputStream(data));
    Services.get(IHUReceiptScheduleBL.class).attachPhoto(receiptSchedule, name, image);
    return MSG_OK;
}
Also used : MImage(org.compiere.model.MImage) IHUReceiptScheduleBL(de.metas.handlingunits.receiptschedule.IHUReceiptScheduleBL) ByteArrayInputStream(java.io.ByteArrayInputStream) I_M_ReceiptSchedule(de.metas.handlingunits.model.I_M_ReceiptSchedule) EntityNotFoundException(de.metas.ui.web.exceptions.EntityNotFoundException) BufferedImage(java.awt.image.BufferedImage)

Example 14 with EntityNotFoundException

use of de.metas.ui.web.exceptions.EntityNotFoundException in project metasfresh-webui-api by metasfresh.

the class DocumentCollection method getDocumentPath.

/**
 * Retrieves document path for given ZoomInto info.
 *
 * @param zoomIntoInfo
 */
public DocumentPath getDocumentPath(@NonNull final DocumentZoomIntoInfo zoomIntoInfo) {
    if (!zoomIntoInfo.isRecordIdPresent()) {
        throw new IllegalArgumentException("recordId must be set in " + zoomIntoInfo);
    }
    // 
    // Find the root window ID
    final WindowId zoomIntoWindowIdEffective = getWindowId(zoomIntoInfo);
    final DocumentEntityDescriptor rootEntityDescriptor = getDocumentEntityDescriptor(zoomIntoWindowIdEffective);
    final String zoomIntoTableName = zoomIntoInfo.getTableName();
    // (i.e. root descriptor's table is matching record's table)
    if (Objects.equals(rootEntityDescriptor.getTableName(), zoomIntoTableName)) {
        final DocumentId rootDocumentId = DocumentId.of(zoomIntoInfo.getRecordId());
        return DocumentPath.rootDocumentPath(zoomIntoWindowIdEffective, rootDocumentId);
    } else // 
    // We are dealing with an included document
    {
        // Search the root descriptor for any child entity descriptor which would match record's TableName
        final List<DocumentEntityDescriptor> childEntityDescriptors = rootEntityDescriptor.getIncludedEntities().stream().filter(includedEntityDescriptor -> Objects.equals(includedEntityDescriptor.getTableName(), zoomIntoTableName)).collect(ImmutableList.toImmutableList());
        if (childEntityDescriptors.isEmpty()) {
            throw new EntityNotFoundException("Cannot find the detail tab to zoom into").setParameter("zoomIntoInfo", zoomIntoInfo).setParameter("zoomIntoWindowId", zoomIntoWindowIdEffective).setParameter("rootEntityDescriptor", rootEntityDescriptor);
        } else if (childEntityDescriptors.size() > 1) {
            logger.warn("More then one child descriptors matched our root descriptor. Picking the fist one. \nRoot descriptor: {} \nChild descriptors: {}", rootEntityDescriptor, childEntityDescriptors);
        }
        // 
        final DocumentEntityDescriptor childEntityDescriptor = childEntityDescriptors.get(0);
        // Find the root DocumentId
        final DocumentId rowId = DocumentId.of(zoomIntoInfo.getRecordId());
        final DocumentId rootDocumentId = DocumentQuery.ofRecordId(childEntityDescriptor, rowId).retrieveParentDocumentId(rootEntityDescriptor);
        // 
        return DocumentPath.includedDocumentPath(zoomIntoWindowIdEffective, rootDocumentId, childEntityDescriptor.getDetailId(), rowId);
    }
}
Also used : DocumentPermissionsHelper(de.metas.ui.web.window.controller.DocumentPermissionsHelper) DocumentZoomIntoInfo(de.metas.ui.web.window.model.lookup.DocumentZoomIntoInfo) ITrx(org.adempiere.ad.trx.api.ITrx) Env(org.compiere.util.Env) Autowired(org.springframework.beans.factory.annotation.Autowired) OutputType(de.metas.adempiere.report.jasper.OutputType) SourceDocument(de.metas.letters.model.MADBoilerPlate.SourceDocument) Evaluatee(org.compiere.util.Evaluatee) TableModelLoader(org.adempiere.ad.persistence.TableModelLoader) InterfaceWrapperHelper(org.adempiere.model.InterfaceWrapperHelper) DocumentWebsocketPublisher(de.metas.ui.web.window.events.DocumentWebsocketPublisher) CopyRecordSupport(org.adempiere.model.CopyRecordSupport) TableRecordReference(org.adempiere.util.lang.impl.TableRecordReference) RecordZoomWindowFinder(org.adempiere.model.RecordZoomWindowFinder) ImmutableSet(com.google.common.collect.ImmutableSet) WindowConstants(de.metas.ui.web.window.WindowConstants) NonNull(lombok.NonNull) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) DocumentDescriptor(de.metas.ui.web.window.descriptor.DocumentDescriptor) Set(java.util.Set) Objects(java.util.Objects) ITrxManager(org.adempiere.ad.trx.api.ITrxManager) UserSession(de.metas.ui.web.session.UserSession) Services(org.adempiere.util.Services) EntityNotFoundException(de.metas.ui.web.exceptions.EntityNotFoundException) List(java.util.List) Builder(lombok.Builder) CopyRecordFactory(org.adempiere.model.CopyRecordFactory) CacheBuilder(com.google.common.cache.CacheBuilder) DocumentType(de.metas.ui.web.window.datatypes.DocumentType) LogManager(de.metas.logging.LogManager) ProcessInfo(de.metas.process.ProcessInfo) DocumentPath(de.metas.ui.web.window.datatypes.DocumentPath) ProcessExecutionResult(de.metas.process.ProcessExecutionResult) DocumentId(de.metas.ui.web.window.datatypes.DocumentId) ILogicExpression(org.adempiere.ad.expression.api.ILogicExpression) InvalidDocumentPathException(de.metas.ui.web.window.exceptions.InvalidDocumentPathException) Function(java.util.function.Function) PlainContextAware(org.adempiere.model.PlainContextAware) DocumentNotFoundException(de.metas.ui.web.window.exceptions.DocumentNotFoundException) Value(lombok.Value) CopyMode(de.metas.ui.web.window.model.Document.CopyMode) ImmutableList(com.google.common.collect.ImmutableList) DocumentEntityDescriptor(de.metas.ui.web.window.descriptor.DocumentEntityDescriptor) Nullable(javax.annotation.Nullable) OnVariableNotFound(org.adempiere.ad.expression.api.IExpressionEvaluator.OnVariableNotFound) MADBoilerPlate(de.metas.letters.model.MADBoilerPlate) Logger(org.slf4j.Logger) Evaluatees(org.compiere.util.Evaluatees) DocumentDescriptorFactory(de.metas.ui.web.window.descriptor.factory.DocumentDescriptorFactory) LogicExpressionResult(org.adempiere.ad.expression.api.LogicExpressionResult) MoreObjects(com.google.common.base.MoreObjects) WindowId(de.metas.ui.web.window.datatypes.WindowId) IAutoCloseable(org.adempiere.util.lang.IAutoCloseable) ExecutionException(java.util.concurrent.ExecutionException) BoilerPlateContext(de.metas.letters.model.MADBoilerPlate.BoilerPlateContext) Component(org.springframework.stereotype.Component) AdempiereException(org.adempiere.exceptions.AdempiereException) Check(org.adempiere.util.Check) Preconditions(com.google.common.base.Preconditions) PO(org.compiere.model.PO) Cache(com.google.common.cache.Cache) AllArgsConstructor(lombok.AllArgsConstructor) Collections(java.util.Collections) Immutable(javax.annotation.concurrent.Immutable) WindowId(de.metas.ui.web.window.datatypes.WindowId) DocumentId(de.metas.ui.web.window.datatypes.DocumentId) DocumentEntityDescriptor(de.metas.ui.web.window.descriptor.DocumentEntityDescriptor) EntityNotFoundException(de.metas.ui.web.exceptions.EntityNotFoundException)

Example 15 with EntityNotFoundException

use of de.metas.ui.web.exceptions.EntityNotFoundException in project metasfresh-webui-api by metasfresh.

the class DocumentAttachmentsRestController method extractResponseEntryFromData.

private static ResponseEntity<byte[]> extractResponseEntryFromData(@NonNull final IDocumentAttachmentEntry entry) {
    final String entryFilename = entry.getFilename();
    final byte[] entryData = entry.getData();
    if (entryData == null || entryData.length == 0) {
        throw new EntityNotFoundException("No attachment found").setParameter("entry", entry).setParameter("reason", "data is null or empty");
    }
    final String entryContentType = entry.getContentType();
    final HttpHeaders headers = new HttpHeaders();
    headers.setContentType(MediaType.parseMediaType(entryContentType));
    headers.set(HttpHeaders.CONTENT_DISPOSITION, "inline; filename=\"" + entryFilename + "\"");
    headers.setCacheControl("must-revalidate, post-check=0, pre-check=0");
    final ResponseEntity<byte[]> response = new ResponseEntity<>(entryData, headers, HttpStatus.OK);
    return response;
}
Also used : HttpHeaders(org.springframework.http.HttpHeaders) ResponseEntity(org.springframework.http.ResponseEntity) EntityNotFoundException(de.metas.ui.web.exceptions.EntityNotFoundException)

Aggregations

EntityNotFoundException (de.metas.ui.web.exceptions.EntityNotFoundException)19 Logger (org.slf4j.Logger)4 ImmutableList (com.google.common.collect.ImmutableList)3 Level (ch.qos.logback.classic.Level)2 Preconditions (com.google.common.base.Preconditions)2 ImmutableSet (com.google.common.collect.ImmutableSet)2 IModelTranslationMap (de.metas.i18n.IModelTranslationMap)2 LogManager (de.metas.logging.LogManager)2 DocumentPath (de.metas.ui.web.window.datatypes.DocumentPath)2 DocumentType (de.metas.ui.web.window.datatypes.DocumentType)2 WindowId (de.metas.ui.web.window.datatypes.WindowId)2 DocumentEntityDescriptor (de.metas.ui.web.window.descriptor.DocumentEntityDescriptor)2 PreparedStatement (java.sql.PreparedStatement)2 ResultSet (java.sql.ResultSet)2 SQLException (java.sql.SQLException)2 LinkedHashSet (java.util.LinkedHashSet)2 List (java.util.List)2 Builder (lombok.Builder)2 NonNull (lombok.NonNull)2 ILogicExpression (org.adempiere.ad.expression.api.ILogicExpression)2