/** * Constructs a new {@link IndexedAIP} cloning the one given by argument. * * @param other * the {@link IndexedAIP} to be cloned. */ public IndexedAIP(IndexedAIP other) { this(other.getId(), other.getState(), other.getType(), other.getLevel(), other.getTitle(), other.getDateInitial(), other.getDateFinal(), other.getDescription(), other.getParentID(), other.getAncestors(), other.getPermissions(), other.getNumberOfSubmissionFiles(), other.getNumberOfDocumentationFiles(), other.getNumberOfSchemaFiles(), other.getHasRepresentations(), other.getGhost()); }
public static String createOutcomeTextForAIP(IndexedAIP item, String actionMessage) { SimpleDateFormat format = new SimpleDateFormat(RodaConstants.SIMPLE_DATE_FORMATTER); StringBuilder outcomeText = new StringBuilder("Archival Information Package [id: ").append(item.getId()); if (StringUtils.isNotBlank(item.getTitle())) { outcomeText.append("; title: ").append(item.getTitle()); } if (StringUtils.isNotBlank(item.getLevel())) { outcomeText.append("; level: ").append(item.getLevel()); } if (item.getDateInitial() != null) { outcomeText.append("; initial date: ").append(format.format(item.getDateInitial())); } if (item.getDateFinal() != null) { outcomeText.append("; end date: ").append(format.format(item.getDateFinal())); } outcomeText.append("] ").append(actionMessage); return outcomeText.toString(); } }
public List<IndexedAIP> retrieveAncestors(IndexedAIP aip, User user, List<String> fieldsToReturn) throws GenericException { List<IndexedAIP> ancestors = new ArrayList<>(); IndexedAIP parent; IndexedAIP actual = aip; while (actual != null && actual.getParentID() != null) { try { parent = getParent(actual, user, fieldsToReturn); } catch (NotFoundException | AuthorizationDeniedException e) { parent = null; LOGGER.warn("Ancestor not found: {}", actual.getParentID()); } if (parent != null && ancestors.contains(parent)) { LOGGER.warn("Found a cyclic ancestor relationship: {} and {}", aip.getId(), parent.getId()); break; } ancestors.add(parent); actual = parent; } return ancestors; }
if (indexedAIP.getTitle() != null) { node = node.put("title", indexedAIP.getTitle()); if (indexedAIP.getId() != null) { node = node.put("id", indexedAIP.getId()); if (indexedAIP.getParentID() != null) { node = node.put("parentId", indexedAIP.getParentID()); if (indexedAIP.getLevel() != null) { node = node.put("descriptionlevel", indexedAIP.getLevel()); AIP modelAIP = model.retrieveAIP(indexedAIP.getId());
LOGGER.debug("Reindexing aip {} descendant {}", aip.getId(), item.getId()); List<String> ancestors = SolrUtils.getAncestors(item.getParentID(), model); SolrUtils.update(index, IndexedAIP.class, aip.getId(), Collections.singletonMap(RodaConstants.AIP_ANCESTORS, ancestors), (ModelObserver) this).addTo(ret); if (item.getHasRepresentations()) { AIP aipModel = model.retrieveAIP(item.getId()); updateRepresentationAndFileAncestors(aipModel, ancestors).addTo(ret);
@JsonIgnore @Override public String getUUID() { return getId(); }
public static void checkAIPPermissions(User user, IndexedAIP aip, PermissionType permissionType) throws AuthorizationDeniedException { if (isAdministrator(user)) { return; } Set<String> users = aip.getPermissions().getUsers().get(permissionType); Set<String> groups = aip.getPermissions().getGroups().get(permissionType); LOGGER.debug("Checking if user '{}' has permissions to {} object {} (object read permissions: {} & {})", user.getId(), permissionType, aip.getId(), users, groups); if (!users.contains(user.getId()) && iterativeDisjoint(groups, user.getGroups())) { throw new AuthorizationDeniedException( "The user '" + user.getId() + "' does not have permissions to " + permissionType); } }
List<String> temp = new ArrayList<>(); if (aip.getIngestSIPIds() != null && !aip.getIngestSIPIds().isEmpty()) { String firstIngestSIPId = aip.getIngestSIPIds().get(0); if (sipIdToGhost.containsKey(firstIngestSIPId)) { temp = sipIdToGhost.get(firstIngestSIPId); temp.add(aip.getId()); sipIdToGhost.put(firstIngestSIPId, temp); } else { if (aipIdToGhost.containsKey(aip.getId())) { temp = aipIdToGhost.get(aip.getId()); temp.add(aip.getId()); aipIdToGhost.put(aip.getId(), temp); IndexedAIP newParentIAIP = result.getResults().get(0); for (String id : entry.getValue()) { moveChildrenAIPsAndDelete(index, model, id, newParentIAIP.getId(), computedSearchScope, updatedBy);
public IndexedAIP getParent(IndexedAIP aip, User user, List<String> fieldsToReturn) throws NotFoundException, GenericException, AuthorizationDeniedException { return SolrUtils.retrieve(getSolrClient(), IndexedAIP.class, aip.getParentID(), user, fieldsToReturn); }
/** * @deprecated use DownloadUtils instead. */ @Deprecated public static List<ZipEntryInfo> zipIndexedAIP(List<IndexedAIP> aips) throws RequestNotValidException, NotFoundException, GenericException, AuthorizationDeniedException { List<ZipEntryInfo> zipEntries = new ArrayList<>(); ModelService model = RodaCoreFactory.getModelService(); for (IndexedAIP aip : aips) { AIP fullAIP = model.retrieveAIP(aip.getId()); zipEntries.addAll(aipToZipEntry(fullAIP)); } return zipEntries; }
private static <T extends IsIndexed> void checkAIPObjectPermissions(User user, T obj, Function<T, String> toAIP, PermissionType permissionType) throws AuthorizationDeniedException { if (isAdministrator(user)) { return; } String aipId = toAIP.apply(obj); IndexedAIP aip; try { aip = RodaCoreFactory.getIndexService().retrieve(IndexedAIP.class, aipId, RodaConstants.AIP_PERMISSIONS_FIELDS_TO_RETURN); } catch (NotFoundException | GenericException e) { throw new AuthorizationDeniedException("Could not check permissions of object " + obj, e); } Set<String> users = aip.getPermissions().getUsers().get(permissionType); Set<String> groups = aip.getPermissions().getGroups().get(permissionType); LOGGER.debug("Checking if user '{}' has permissions to {} object {} (object read permissions: {} & {})", user.getId(), permissionType, aip.getId(), users, groups); if (!users.contains(user.getId()) && iterativeDisjoint(groups, user.getGroups())) { throw new AuthorizationDeniedException( "The user '" + user.getId() + "' does not have permissions to " + permissionType); } }
private static Optional<String> getAncestorById(String ancestor, Optional<String> computedSearchScope, IndexService index, String aipField) { if (ancestor.equalsIgnoreCase(computedSearchScope.orElse(null))) { return computedSearchScope; } Optional<String> ancestorBySIPId = Optional.empty(); Filter ancestorFilter = new Filter(new SimpleFilterParameter(aipField, ancestor)); if (computedSearchScope.isPresent()) { try { IndexedAIP computedParent = index.retrieve(IndexedAIP.class, computedSearchScope.get(), Arrays.asList(RodaConstants.INDEX_UUID, RodaConstants.AIP_ANCESTORS)); ancestorFilter.add(new SimpleFilterParameter(RodaConstants.AIP_ANCESTORS, computedParent.getId())); } catch (NotFoundException | GenericException e) { // Do nothing } } try { // TODO 2016-11-24 sleroux: add user permission IndexResult<IndexedAIP> result = index.find(IndexedAIP.class, ancestorFilter, Sorter.NONE, new Sublist(0, 1), Arrays.asList(RodaConstants.INDEX_UUID)); if (result.getTotalCount() >= 1) { IndexedAIP indexedAIP = result.getResults().get(0); ancestorBySIPId = Optional.ofNullable(indexedAIP.getId()); } } catch (GenericException | RequestNotValidException e) { // Do nothing LOGGER.error("Error getting ancestor", e); } return ancestorBySIPId; }
@Override public void run(IndexedAIP item) throws GenericException, RequestNotValidException, AuthorizationDeniedException { PluginState state = PluginState.SUCCESS; try { model.deleteAIP(item.getId()); } catch (NotFoundException e) { state = PluginState.FAILURE; reportItem.addPluginDetails("Could not delete AIP: " + e.getMessage()); } String outcomeText; if (state.equals(PluginState.SUCCESS)) { outcomeText = PluginHelper.createOutcomeTextForAIP(item, "has been manually deleted"); } else { outcomeText = PluginHelper.createOutcomeTextForAIP(item, "has not been manually deleted"); } List<LinkingIdentifier> sources = new ArrayList<>(); sources .add(PluginHelper.getLinkingIdentifier(item.getId(), RodaConstants.PRESERVATION_LINKING_OBJECT_SOURCE)); model.createEvent(item.getId(), null, null, null, PreservationEventType.DELETION, EVENT_DESCRIPTION, sources, null, state, outcomeText, details, job.getUsername(), true); } }, e -> {
private static void moveChildrenAIPsAndDelete(IndexService index, ModelService model, String aipId, String newParentId, Optional<String> searchScope, String updatedBy) throws GenericException, AuthorizationDeniedException, RequestNotValidException { Filter parentFilter = new Filter(new SimpleFilterParameter(RodaConstants.AIP_PARENT_ID, aipId)); searchScope.ifPresent(id -> parentFilter.add(new SimpleFilterParameter(RodaConstants.AIP_ANCESTORS, id))); try (IterableIndexResult<IndexedAIP> result = index.findAll(IndexedAIP.class, parentFilter, false, Arrays.asList(RodaConstants.INDEX_UUID, RodaConstants.AIP_ID))) { for (IndexedAIP aip : result) { try { model.moveAIP(aip.getId(), newParentId, updatedBy); } catch (NotFoundException e) { LOGGER.debug("Can't move child. It wasn't found.", e); } } } catch (IOException e) { LOGGER.error("Error getting children AIPs when moving and deleting them", e); } try { model.deleteAIP(aipId); } catch (NotFoundException e) { LOGGER.debug("Can't delete ghost or move node. It wasn't found.", e); } }
public static AIP earkSIPToAIPUpdate(SIP sip, IndexedAIP indexedAIP, ModelService model, String username, Optional<String> searchScope, String ingestJobId, Report reportItem, Plugin<?> plugin) throws RequestNotValidException, NotFoundException, GenericException, AlreadyExistsException, AuthorizationDeniedException, ValidationException, LockingException { boolean notify = false; AIP aip; PluginHelper.acquireObjectLock(indexedAIP, plugin); // process IP information processIPInformation(model, sip, indexedAIP.getId(), notify, true); // process IPRepresentation information for (IPRepresentation representation : sip.getRepresentations()) { processIPRepresentationInformation(model, representation, indexedAIP.getId(), notify, true, username, reportItem); } aip = model.retrieveAIP(indexedAIP.getId()); aip.setGhost(false); if (searchScope.isPresent()) { aip.setParentId(searchScope.get()); } aip.addIngestUpdateJobId(ingestJobId); for (String id : sip.getIds()) { if (!aip.getIngestSIPIds().contains(id)) { aip.getIngestSIPIds().add(id); } } return model.updateAIP(aip, username); }
String error = ""; try { LOGGER.debug("Removing unwanted AIP {}", indexedAIP.getId()); model.deleteAIP(indexedAIP.getId()); } catch (RequestNotValidException | NotFoundException | GenericException | AuthorizationDeniedException e) { error = e.getMessage(); Report reportItem = PluginHelper.initPluginReportItem(this, indexedAIP.getId(), AIP.class, AIPState.INGEST_PROCESSING); if (StringUtils.isNotBlank(error)) { reportItem.setPluginState(PluginState.FAILURE) .setPluginDetails("Removal of AIP " + indexedAIP.getId() + " did not end successfully: " + error); jobPluginInfo.incrementObjectsProcessedWithFailure(); } else { reportItem.setPluginState(PluginState.SUCCESS) .setPluginDetails("Removal of AIP " + indexedAIP.getId() + " ended successfully"); jobPluginInfo.incrementObjectsProcessedWithSuccess();
private static void updateParent(IndexService index, ModelService model, String aipId, String newParentId, Optional<String> searchScope, String updatedBy) throws GenericException, AuthorizationDeniedException, RequestNotValidException { Filter parentFilter = new Filter(new SimpleFilterParameter(RodaConstants.AIP_PARENT_ID, aipId)); searchScope.ifPresent(id -> parentFilter.add(new SimpleFilterParameter(RodaConstants.AIP_ANCESTORS, id))); index.execute(IndexedAIP.class, parentFilter, Arrays.asList(RodaConstants.INDEX_UUID), child -> { try { AIP aip = model.retrieveAIP(child.getId()); aip.setParentId(newParentId); model.updateAIP(aip, updatedBy); } catch (NotFoundException e) { LOGGER.debug("Can't move child. It wasn't found.", e); } }, e -> LOGGER.debug("Can't move child.", e)); try { model.deleteAIP(aipId); } catch (NotFoundException e) { LOGGER.debug("Can't delete ghost or move node. It wasn't found.", e); } }
model.updateAIPPermissions(child.getId(), permissions, job.getUsername());