Search in sources :

Example 1 with QuickShareLinkExpiryAction

use of org.alfresco.service.cmr.quickshare.QuickShareLinkExpiryAction in project alfresco-repository by Alfresco.

the class QuickShareServiceImpl method deleteQuickShareLinkExpiryAction.

/**
 * Removes (hard deletes) the previously persisted {@link QuickShareLinkExpiryAction} and its related
 * schedule {@link ScheduledPersistedAction} from the repository.
 */
protected void deleteQuickShareLinkExpiryAction(NodeRef linkExpiryActionNodeRef) {
    TenantUtil.runAsDefaultTenant(() -> {
        QuickShareLinkExpiryAction linkExpiryAction = quickShareLinkExpiryActionPersister.loadQuickShareLinkExpiryAction(linkExpiryActionNodeRef);
        // Delete the expiry action and its related persisted schedule
        deleteQuickShareLinkExpiryActionImpl(linkExpiryAction);
        return null;
    });
}
Also used : QuickShareLinkExpiryAction(org.alfresco.service.cmr.quickshare.QuickShareLinkExpiryAction)

Example 2 with QuickShareLinkExpiryAction

use of org.alfresco.service.cmr.quickshare.QuickShareLinkExpiryAction in project alfresco-repository by Alfresco.

the class QuickShareServiceImpl method saveSharedLinkExpiryAction.

/**
 * Creates and persists the quick share link expiry action and its related schedule.
 */
protected void saveSharedLinkExpiryAction(String sharedId, Date expiryDate) {
    ParameterCheck.mandatory("expiryDate", expiryDate);
    // Validate the given expiry date
    checkExpiryDate(expiryDate);
    if (logger.isDebugEnabled()) {
        logger.debug("Creating shared link expiry action for the sharedId:" + sharedId);
    }
    final NodeRef expiryActionNodeRef = getQuickShareLinkExpiryActionNode(sharedId);
    // If an expiry action already exists for the specified shared Id, first remove it, before creating a new one.
    if (expiryActionNodeRef != null) {
        deleteQuickShareLinkExpiryAction(expiryActionNodeRef);
    }
    // Create the expiry action
    final QuickShareLinkExpiryAction expiryAction = new QuickShareLinkExpiryActionImpl(java.util.UUID.randomUUID().toString(), sharedId, "QuickShare link expiry action");
    // Create the persisted schedule
    final ScheduledPersistedAction schedule = scheduledPersistedActionService.createSchedule(expiryAction);
    // first set the scheduledAction so we can set the other information
    expiryAction.setSchedule(schedule);
    expiryAction.setScheduleStart(expiryDate);
    try {
        TenantUtil.runAsDefaultTenant((TenantRunAsWork<Void>) () -> {
            quickShareLinkExpiryActionPersister.saveQuickShareLinkExpiryAction(expiryAction);
            scheduledPersistedActionService.saveSchedule(schedule);
            return null;
        });
    } catch (Exception ex) {
        throw new QuickShareLinkExpiryActionException("Couldn't create quick share link expiry action.", ex);
    }
    if (logger.isDebugEnabled()) {
        logger.debug("Quick share link expiry action is created for sharedId[" + sharedId + "] and it's scheduled to be executed on: " + expiryDate);
    }
}
Also used : ScheduledPersistedAction(org.alfresco.service.cmr.action.scheduled.ScheduledPersistedAction) NodeRef(org.alfresco.service.cmr.repository.NodeRef) QuickShareLinkExpiryAction(org.alfresco.service.cmr.quickshare.QuickShareLinkExpiryAction) ClientAppNotFoundException(org.alfresco.repo.client.config.ClientAppNotFoundException) AccessDeniedException(org.alfresco.repo.security.permissions.AccessDeniedException) InvalidSharedIdException(org.alfresco.service.cmr.quickshare.InvalidSharedIdException) InvalidNodeRefException(org.alfresco.service.cmr.repository.InvalidNodeRefException) QuickShareDisabledException(org.alfresco.service.cmr.quickshare.QuickShareDisabledException) NoSuchPersonException(org.alfresco.service.cmr.security.NoSuchPersonException)

Example 3 with QuickShareLinkExpiryAction

use of org.alfresco.service.cmr.quickshare.QuickShareLinkExpiryAction in project alfresco-repository by Alfresco.

the class QuickShareLinkExpiryActionExecutor method executeImpl.

@Override
protected void executeImpl(Action action, NodeRef actionedUponNodeRef) {
    if (!(action instanceof QuickShareLinkExpiryAction)) {
        if (action.getActionDefinitionName().equals(QuickShareLinkExpiryActionImpl.EXECUTOR_NAME)) {
            action = new QuickShareLinkExpiryActionImpl(action);
        } else {
            return;
        }
    }
    QuickShareLinkExpiryAction quickShareLinkExpiryAction = (QuickShareLinkExpiryAction) action;
    String sharedId = quickShareLinkExpiryAction.getSharedId();
    if (LOGGER.isDebugEnabled()) {
        LOGGER.debug("Unsharing the shared id [" + sharedId + "] for the node:" + quickShareService.getTenantNodeRefFromSharedId(sharedId).getSecond());
    }
    if (StringUtils.isEmpty(sharedId)) {
        throw new QuickShareLinkExpiryActionException("Shared id is not specified.");
    }
    try {
        quickShareService.unshareContent(sharedId);
        if (LOGGER.isDebugEnabled()) {
            LOGGER.debug("Unshared the shared id:" + sharedId);
        }
    } catch (Exception ex) {
        if (ex instanceof QuickShareLinkExpiryActionException) {
            LOGGER.error("Couldn't delete the quick share expiry action [" + quickShareLinkExpiryAction.getNodeRef() + "] for the sharedId:" + sharedId);
        } else {
            LOGGER.error("Couldn't unshare the shared Id:" + sharedId);
        }
    }
}
Also used : QuickShareLinkExpiryAction(org.alfresco.service.cmr.quickshare.QuickShareLinkExpiryAction)

Example 4 with QuickShareLinkExpiryAction

use of org.alfresco.service.cmr.quickshare.QuickShareLinkExpiryAction in project alfresco-repository by Alfresco.

the class QuickShareServiceIntegrationTest method testSharedLinkExpiryScheduling.

/**
 * Test the quick share link expiry date action.
 */
@Test
public void testSharedLinkExpiryScheduling() throws Exception {
    // First record the number of available schedules
    final int numOfSchedules = listSchedules();
    // 1 day from now
    Date expiryDate = DateTime.now().plusDays(1).toDate();
    QuickShareDTO quickShareDTO = share(testNode, user1.getUsername(), expiryDate);
    assertTrue(hasQuickShareAspect(testNode));
    assertEquals(quickShareDTO.getId(), getProperty(testNode, QuickShareModel.PROP_QSHARE_SHAREDID));
    assertNotNull(quickShareDTO.getExpiresAt());
    assertEquals(expiryDate, quickShareDTO.getExpiresAt());
    // Check that the expiry action is persisted
    QuickShareLinkExpiryAction expiryAction = getExpiryActionAndAttachSchedule(quickShareDTO.getId());
    assertEquals(quickShareDTO.getId(), expiryAction.getSharedId());
    assertEquals(quickShareDTO.getExpiresAt(), expiryAction.getScheduleStart());
    assertNull("We haven't set interval count.", expiryAction.getScheduleIntervalCount());
    assertNull("We haven't set interval period.", expiryAction.getScheduleIntervalPeriod());
    // Try to share the already shared node with a different expiry date.
    // This basically will update the expiry action start time
    expiryDate = DateTime.now().plusDays(7).toDate();
    quickShareDTO = share(testNode, user1.getUsername(), expiryDate);
    assertEquals(expiryDate, quickShareDTO.getExpiresAt());
    assertEquals(expiryDate, getProperty(testNode, QuickShareModel.PROP_QSHARE_EXPIRY_DATE));
    assertTrue(hasQuickShareAspect(testNode));
    assertEquals(quickShareDTO.getId(), getProperty(testNode, QuickShareModel.PROP_QSHARE_SHAREDID));
    // Check that the expiry action is persisted
    expiryAction = getExpiryActionAndAttachSchedule(quickShareDTO.getId());
    assertEquals(quickShareDTO.getId(), expiryAction.getSharedId());
    assertEquals(quickShareDTO.getExpiresAt(), expiryAction.getScheduleStart());
    assertNull("We haven't set interval count.", expiryAction.getScheduleIntervalCount());
    assertNull("We haven't set interval period.", expiryAction.getScheduleIntervalPeriod());
    // Delete the expiry action
    deleteExpiryAction(expiryAction);
    // Check that the expiry action has been deleted
    QuickShareLinkExpiryAction deletedExpiryAction = getExpiryAction(quickShareDTO.getId());
    assertNull(deletedExpiryAction);
    assertNull(getProperty(testNode, QuickShareModel.PROP_QSHARE_EXPIRY_DATE));
    // Unshare
    unshare(quickShareDTO.getId(), user1.getUsername());
    // Share the testNode, with expiry date of 1 day from now
    expiryDate = DateTime.now().plusDays(1).toDate();
    quickShareDTO = share(testNode, user1.getUsername(), expiryDate);
    assertTrue(hasQuickShareAspect(testNode));
    expiryAction = getExpiryActionAndAttachSchedule(quickShareDTO.getId());
    assertEquals(expiryDate, expiryAction.getScheduleStart());
    assertEquals(numOfSchedules + 1, listSchedules());
    // Now update the schedule to be executed in 5 seconds.
    expiryAction.setScheduleStart(DateTime.now().plusSeconds(5).toDate());
    // Here we'll bypass the QuickShareService in order to force the new time.
    // As the QuickShareService by default will enforce the expiry date to not be less than 24 hours.
    forceSaveNewExpiryTime(expiryAction);
    // wait 10 seconds
    Thread.sleep(10000L);
    // Check that the expiry action was successful and it removed the shared link
    assertFalse(hasQuickShareAspect(testNode));
    // Also check the expiry date property is removed
    assertNull(getProperty(testNode, QuickShareModel.PROP_QSHARE_EXPIRY_DATE));
    // Check that the persisted expiry action is removed
    assertNull(getExpiryAction(quickShareDTO.getId()));
    // Check that the persisted schedule is removed as well
    assertEquals(numOfSchedules, listSchedules());
    // Share the testNode, with expiry date of 1 day from now
    expiryDate = DateTime.now().plusDays(1).toDate();
    quickShareDTO = share(testNode, user1.getUsername(), expiryDate);
    assertTrue(hasQuickShareAspect(testNode));
    expiryAction = getExpiryActionAndAttachSchedule(quickShareDTO.getId());
    assertEquals(expiryDate, expiryAction.getScheduleStart());
    // Delete the shared testNode as user1
    AuthenticationUtil.runAs(() -> {
        nodeService.deleteNode(testNode);
        return null;
    }, user1.getUsername());
    // Check that the persisted expiry action is removed, as we have deleted the source node
    assertNull(getExpiryAction(quickShareDTO.getId()));
    // Check that the persisted schedule is removed as well
    assertEquals(numOfSchedules, listSchedules());
    // Restore the testNode as user1
    AuthenticationUtil.runAs(() -> {
        final NodeRef archivedNode = nodeArchiveService.getArchivedNode(testNode);
        RestoreNodeReport restoreNodeReport = nodeArchiveService.restoreArchivedNode(archivedNode);
        assertNotNull(restoreNodeReport);
        assertTrue(restoreNodeReport.getStatus() == RestoreStatus.SUCCESS);
        testNode = restoreNodeReport.getRestoredNodeRef();
        return null;
    }, user1.getUsername());
    // Check that restoring the node hasn't brought back the shared aspect or the persisted expiry action
    assertFalse(hasQuickShareAspect(testNode));
    assertNull(getExpiryAction(quickShareDTO.getId()));
    assertEquals(numOfSchedules, listSchedules());
}
Also used : RestoreNodeReport(org.alfresco.repo.node.archive.RestoreNodeReport) NodeRef(org.alfresco.service.cmr.repository.NodeRef) QuickShareDTO(org.alfresco.service.cmr.quickshare.QuickShareDTO) QuickShareLinkExpiryAction(org.alfresco.service.cmr.quickshare.QuickShareLinkExpiryAction) Date(java.util.Date) Test(org.junit.Test)

Example 5 with QuickShareLinkExpiryAction

use of org.alfresco.service.cmr.quickshare.QuickShareLinkExpiryAction in project alfresco-remote-api by Alfresco.

the class SharedLinkApiTest method forceNewExpiryTime.

private void forceNewExpiryTime(String sharedId, Date date) {
    TenantUtil.runAsSystemTenant(() -> {
        // Load the expiry action and attach the schedule
        QuickShareLinkExpiryAction linkExpiryAction = quickShareLinkExpiryActionPersister.loadQuickShareLinkExpiryAction(QuickShareLinkExpiryActionImpl.createQName(sharedId));
        linkExpiryAction.setSchedule(scheduledPersistedActionService.getSchedule(linkExpiryAction));
        linkExpiryAction.setScheduleStart(date);
        // save the expiry action and the schedule
        transactionHelper.doInTransaction(() -> {
            quickShareLinkExpiryActionPersister.saveQuickShareLinkExpiryAction(linkExpiryAction);
            scheduledPersistedActionService.saveSchedule(linkExpiryAction.getSchedule());
            return null;
        });
        return null;
    }, TenantUtil.getCurrentDomain());
}
Also used : QuickShareLinkExpiryAction(org.alfresco.service.cmr.quickshare.QuickShareLinkExpiryAction)

Aggregations

QuickShareLinkExpiryAction (org.alfresco.service.cmr.quickshare.QuickShareLinkExpiryAction)6 ScheduledPersistedAction (org.alfresco.service.cmr.action.scheduled.ScheduledPersistedAction)2 NodeRef (org.alfresco.service.cmr.repository.NodeRef)2 Date (java.util.Date)1 ClientAppNotFoundException (org.alfresco.repo.client.config.ClientAppNotFoundException)1 RestoreNodeReport (org.alfresco.repo.node.archive.RestoreNodeReport)1 AccessDeniedException (org.alfresco.repo.security.permissions.AccessDeniedException)1 InvalidSharedIdException (org.alfresco.service.cmr.quickshare.InvalidSharedIdException)1 QuickShareDTO (org.alfresco.service.cmr.quickshare.QuickShareDTO)1 QuickShareDisabledException (org.alfresco.service.cmr.quickshare.QuickShareDisabledException)1 InvalidNodeRefException (org.alfresco.service.cmr.repository.InvalidNodeRefException)1 NoSuchPersonException (org.alfresco.service.cmr.security.NoSuchPersonException)1 Test (org.junit.Test)1