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