private void checkAndRemoveDuplicates(MaterialInstance materialInstance, List<Modification> newChanges, ArrayList<Modification> list) { if (!new SystemEnvironment().get(SystemEnvironment.CHECK_AND_REMOVE_DUPLICATE_MODIFICATIONS)) { return; } DetachedCriteria criteria = DetachedCriteria.forClass(Modification.class); criteria.setProjection(Projections.projectionList().add(Projections.property("revision"))); criteria.add(Restrictions.eq("materialInstance.id", materialInstance.getId())); ArrayList<String> revisions = new ArrayList<>(); for (Modification modification : newChanges) { revisions.add(modification.getRevision()); } criteria.add(Restrictions.in("revision", revisions)); List<String> matchingRevisionsFromDb = (List<String>) getHibernateTemplate().findByCriteria(criteria); if (!matchingRevisionsFromDb.isEmpty()) { for (final String revision : matchingRevisionsFromDb) { Modification modification = list.stream().filter(item -> item.getRevision().equals(revision)).findFirst().orElse(null); list.remove(modification); } } if (!newChanges.isEmpty() && list.isEmpty()) { LOGGER.debug("All modifications already exist in db [{}]", revisions); } if (!matchingRevisionsFromDb.isEmpty()) { LOGGER.info("Saving revisions for material [{}] after removing the following duplicates {}", materialInstance.toOldMaterial(null, null, null).getLongDescription(), matchingRevisionsFromDb); } }
String message = "Modification check failed for material: " + material.getLongDescription(); String errorDescription = e.getMessage() == null ? "Unknown error" : e.getMessage(); healthService.update(ServerHealthState.error(message, errorDescription, HealthStateType.general(scope)));
public boolean updateMaterial(Material material) { Date inProgressSince = inProgress.putIfAbsent(material, new Date()); if (inProgressSince == null || !material.isAutoUpdate()) { LOGGER.debug("[Material Update] Starting update of material {}", material); try { long trackingId = mduPerformanceLogger.materialSentToUpdateQueue(material); queueFor(material).post(new MaterialUpdateMessage(material, trackingId)); return true; } catch (RuntimeException e) { inProgress.remove(material); throw e; } } else { LOGGER.warn("[Material Update] Skipping update of material {} which has been in-progress since {}", material, inProgressSince); long idleTime = getProcessManager().getIdleTimeFor(material.getFingerprint()); if (idleTime > getMaterialUpdateInActiveTimeoutInMillis()) { HealthStateScope scope = HealthStateScope.forMaterialUpdate(material); serverHealthService.removeByScope(scope); serverHealthService.update(warning("Material update for " + material.getUriForDisplay() + " hung:", "Material update is currently running but has not shown any activity in the last " + idleTime / 60000 + " minute(s). This may be hung. Details - " + material.getLongDescription(), general(scope))); } return false; } }