Search in sources :

Example 1 with EntityNotFoundException

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

the class ImageRestController method getWebuiImage.

private WebuiImage getWebuiImage(final int imageId, final int maxWidth, final int maxHeight) {
    if (imageId <= 0) {
        throw new IllegalArgumentException("Invalid image id");
    }
    final MImage adImage = MImage.get(Env.getCtx(), imageId);
    if (adImage == null || adImage.getAD_Image_ID() <= 0) {
        throw new EntityNotFoundException("Image id not found: " + imageId);
    }
    final boolean hasAccess = userSession.getUserRolePermissions().canView(adImage.getAD_Client_ID(), adImage.getAD_Org_ID(), I_AD_Image.Table_ID, adImage.getAD_Image_ID());
    if (!hasAccess) {
        throw new EntityNotFoundException("Image id not found: " + imageId);
    }
    return WebuiImage.of(adImage, maxWidth, maxHeight);
}
Also used : MImage(org.compiere.model.MImage) EntityNotFoundException(de.metas.ui.web.exceptions.EntityNotFoundException)

Example 2 with EntityNotFoundException

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

the class SqlViewDataRepository method retrieveById.

@Override
public IViewRow retrieveById(final ViewEvaluationCtx viewEvalCtx, final ViewId viewId, final DocumentId rowId) {
    final SqlAndParams sqlAndParams = sqlViewSelect.selectById().viewEvalCtx(viewEvalCtx).viewId(viewId).rowId(rowId).build();
    PreparedStatement pstmt = null;
    ResultSet rs = null;
    try {
        final int limit = 2;
        pstmt = DB.prepareStatement(sqlAndParams.getSql(), ITrx.TRXNAME_ThreadInherited);
        pstmt.setMaxRows(limit);
        DB.setParameters(pstmt, sqlAndParams.getSqlParams());
        rs = pstmt.executeQuery();
        final List<IViewRow> documents = loadViewRows(rs, viewEvalCtx, viewId, limit);
        if (documents.isEmpty()) {
            throw new EntityNotFoundException("No document found for rowId=" + rowId);
        } else if (documents.size() > 1) {
            logger.warn("More than one document found for rowId={} in {}. Returning only the first one from: {}", rowId, this, documents);
            return documents.get(0);
        } else {
            return documents.get(0);
        }
    } catch (final SQLException | DBException e) {
        throw DBException.wrapIfNeeded(e).setSqlIfAbsent(sqlAndParams.getSql(), sqlAndParams.getSqlParams());
    } finally {
        DB.close(rs, pstmt);
    }
}
Also used : DBException(org.adempiere.exceptions.DBException) SQLException(java.sql.SQLException) SqlAndParams(de.metas.ui.web.view.descriptor.SqlAndParams) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) EntityNotFoundException(de.metas.ui.web.exceptions.EntityNotFoundException)

Example 3 with EntityNotFoundException

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

the class DocumentAttachments method deleteEntry.

public void deleteEntry(final DocumentId id) {
    final IPair<String, Integer> prefixAndId = toPrefixAndEntryId(id);
    final String idPrefix = prefixAndId.getLeft();
    final int entryId = prefixAndId.getRight();
    if (ID_PREFIX_Attachment.equals(idPrefix)) {
        attachmentsBL.deleteEntryForModel(recordRef, entryId);
        notifyRelatedDocumentTabsChanged();
    } else if (ID_PREFIX_Archive.equals(idPrefix)) {
        final I_AD_Archive archive = Services.get(IArchiveDAO.class).retrieveArchiveOrNull(Env.getCtx(), recordRef, entryId);
        if (archive == null) {
            throw new EntityNotFoundException(id.toJson());
        }
        InterfaceWrapperHelper.delete(archive);
    } else {
        throw new EntityNotFoundException(id.toJson());
    }
}
Also used : I_AD_Archive(org.compiere.model.I_AD_Archive) EntityNotFoundException(de.metas.ui.web.exceptions.EntityNotFoundException)

Example 4 with EntityNotFoundException

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

the class WindowRestController method getDocumentFieldZoomInto.

private JSONZoomInto getDocumentFieldZoomInto(final DocumentPath documentPath, final String fieldName) {
    userSession.assertLoggedIn();
    final DocumentZoomIntoInfo zoomIntoInfo = documentCollection.forDocumentReadonly(documentPath, document -> {
        final IDocumentFieldView field = document.getFieldView(fieldName);
        // Generic ZoomInto button
        if (field.getDescriptor().getWidgetType() == DocumentFieldWidgetType.ZoomIntoButton) {
            final ButtonFieldActionDescriptor buttonActionDescriptor = field.getDescriptor().getButtonActionDescriptor();
            final String zoomIntoTableIdFieldName = buttonActionDescriptor.getZoomIntoTableIdFieldName();
            final Integer adTableId = document.getFieldView(zoomIntoTableIdFieldName).getValueAs(Integer.class);
            if (adTableId == null || adTableId <= 0) {
                throw new EntityNotFoundException("Cannot fetch ZoomInto infos from a null value. No AD_Table_ID.").setParameter("documentPath", documentPath).setParameter("fieldName", fieldName).setParameter("zoomIntoTableIdFieldName", zoomIntoTableIdFieldName);
            }
            final Integer recordId = field.getValueAs(Integer.class);
            if (recordId == null) {
                throw new EntityNotFoundException("Cannot fetch ZoomInto infos from a null value. No Record_ID.").setParameter("documentPath", documentPath).setParameter("fieldName", fieldName).setParameter("zoomIntoTableIdFieldName", zoomIntoTableIdFieldName);
            }
            final String tableName = Services.get(IADTableDAO.class).retrieveTableName(adTableId);
            return DocumentZoomIntoInfo.of(tableName, recordId);
        } else // Key Field
        if (field.isKey()) {
            // Allow zooming into key column. It shall open precisely this record in a new window.
            // (see https://github.com/metasfresh/metasfresh/issues/1687 to understand the use-case)
            final String tableName = document.getEntityDescriptor().getTableName();
            final int recordId = document.getDocumentIdAsInt();
            return DocumentZoomIntoInfo.of(tableName, recordId);
        } else // Regular lookup value
        {
            return field.getZoomIntoInfo();
        }
    });
    final JSONDocumentPath jsonZoomIntoDocumentPath;
    if (zoomIntoInfo == null) {
        throw new EntityNotFoundException("ZoomInto not supported").setParameter("documentPath", documentPath).setParameter("fieldName", fieldName);
    } else if (!zoomIntoInfo.isRecordIdPresent()) {
        final WindowId windowId = documentCollection.getWindowId(zoomIntoInfo);
        jsonZoomIntoDocumentPath = JSONDocumentPath.newWindowRecord(windowId);
    } else {
        final DocumentPath zoomIntoDocumentPath = documentCollection.getDocumentPath(zoomIntoInfo);
        jsonZoomIntoDocumentPath = JSONDocumentPath.ofWindowDocumentPath(zoomIntoDocumentPath);
    }
    return JSONZoomInto.builder().documentPath(jsonZoomIntoDocumentPath).source(JSONDocumentPath.ofWindowDocumentPath(documentPath, fieldName)).build();
}
Also used : ButtonFieldActionDescriptor(de.metas.ui.web.window.descriptor.ButtonFieldActionDescriptor) DocumentZoomIntoInfo(de.metas.ui.web.window.model.lookup.DocumentZoomIntoInfo) WindowId(de.metas.ui.web.window.datatypes.WindowId) IADTableDAO(org.adempiere.ad.table.api.IADTableDAO) DocumentPath(de.metas.ui.web.window.datatypes.DocumentPath) JSONDocumentPath(de.metas.ui.web.window.datatypes.json.JSONDocumentPath) EntityNotFoundException(de.metas.ui.web.exceptions.EntityNotFoundException) IDocumentFieldView(de.metas.ui.web.window.model.IDocumentFieldView) JSONDocumentPath(de.metas.ui.web.window.datatypes.json.JSONDocumentPath)

Example 5 with EntityNotFoundException

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

the class DocumentCollection method getWindowId.

public WindowId getWindowId(@NonNull final DocumentZoomIntoInfo zoomIntoInfo) {
    if (zoomIntoInfo.getWindowId() != null) {
        return zoomIntoInfo.getWindowId();
    }
    final RecordZoomWindowFinder zoomWindowFinder;
    if (zoomIntoInfo.isRecordIdPresent()) {
        zoomWindowFinder = RecordZoomWindowFinder.newInstance(zoomIntoInfo.getTableName(), zoomIntoInfo.getRecordId());
    } else {
        zoomWindowFinder = RecordZoomWindowFinder.newInstance(zoomIntoInfo.getTableName());
    }
    final int zoomInto_adWindowId = zoomWindowFinder.findAD_Window_ID();
    if (zoomInto_adWindowId <= 0) {
        throw new EntityNotFoundException("No windowId found").setParameter("zoomIntoInfo", zoomIntoInfo);
    }
    return WindowId.of(zoomInto_adWindowId);
}
Also used : RecordZoomWindowFinder(org.adempiere.model.RecordZoomWindowFinder) 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