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);
}
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);
}
}
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());
}
}
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();
}
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);
}
Aggregations