Example usage for java.time Instant from

List of usage examples for java.time Instant from

Introduction

In this page you can find the example usage for java.time Instant from.

Prototype

public static Instant from(TemporalAccessor temporal) 

Source Link

Document

Obtains an instance of Instant from a temporal object.

Usage

From source file:org.codice.ddf.confluence.source.ConfluenceInputTransformerTest.java

private Date getDate(String dateTime) {
    return Date.from(Instant.from(DateTimeFormatter.ISO_OFFSET_DATE_TIME.parse(dateTime)));
}

From source file:org.cryptomator.frontend.webdav.jackrabbitservlet.FilesystemResourceFactory.java

/**
 * @return <code>true</code> if a partial response should be generated according to an If-Range precondition.
 *///from ww w . j  a va  2s  .c  o  m
private boolean isIfRangeHeaderSatisfied(FileLocator file, String ifRangeHeader) throws DavException {
    if (ifRangeHeader == null) {
        // no header set -> satisfied implicitly
        return true;
    } else {
        try {
            Instant expectedTime = Instant.from(DateTimeFormatter.RFC_1123_DATE_TIME.parse(ifRangeHeader));
            Instant actualTime = file.lastModified();
            return expectedTime.compareTo(actualTime) == 0;
        } catch (DateTimeParseException e) {
            throw new DavException(DavServletResponse.SC_BAD_REQUEST,
                    "Unsupported If-Range header: " + ifRangeHeader);
        }
    }
}

From source file:org.cryptomator.frontend.webdav.servlet.DavResourceFactoryImpl.java

/**
 * @return <code>true</code> if a partial response should be generated according to an If-Range precondition.
 */// w w w .  j a  v a  2 s.  com
private boolean isIfRangeHeaderSatisfied(BasicFileAttributes attr, String ifRangeHeader) throws DavException {
    if (ifRangeHeader == null) {
        // no header set -> satisfied implicitly
        return true;
    } else {
        try {
            Instant expectedTime = Instant.from(DateTimeFormatter.RFC_1123_DATE_TIME.parse(ifRangeHeader));
            Instant actualTime = attr.lastModifiedTime().toInstant();
            return expectedTime.compareTo(actualTime) == 0;
        } catch (DateTimeParseException e) {
            throw new DavException(DavServletResponse.SC_BAD_REQUEST,
                    "Unsupported If-Range header: " + ifRangeHeader);
        }
    }
}

From source file:org.fcrepo.integration.http.api.FedoraLdpIT.java

License:asdf

private static Optional<Instant> getDateFromModel(final Model model, final Resource subj, final Property pred)
        throws NoSuchElementException, ParseException {
    final StmtIterator stmts = model.listStatements(subj, pred, (String) null);
    return Optional.ofNullable(
            stmts.hasNext() ? Instant.from(tripleFormat.parse(stmts.nextStatement().getString())) : null);
}

From source file:org.fcrepo.integration.http.api.FedoraLdpIT.java

License:asdf

@Test
public void testBinaryLastModified() throws Exception {
    final String objid = getRandomUniqueId();
    final String objURI = serverAddress + objid;
    final String binURI = objURI + "/binary1";

    final Instant lastmod1;
    try (final CloseableHttpResponse response = execute(putDSMethod(objid, "binary1", "some test content"))) {
        assertEquals(CREATED.getStatusCode(), getStatus(response));
        lastmod1 = Instant.from(headerFormat.parse(response.getFirstHeader("Last-Modified").getValue()));
    }//w w w . ja va 2 s  . com

    sleep(1000); // wait a second to make sure last-modified value will be different

    try (final CloseableDataset dataset = getDataset(new HttpGet(binURI + "/fcr:metadata"))) {
        verifyModifiedMatchesCreated(dataset);
    }

    final HttpPatch patchBinary = new HttpPatch(binURI + "/fcr:metadata");
    patchBinary.addHeader(CONTENT_TYPE, "application/sparql-update");
    patchBinary.setEntity(new StringEntity("INSERT { <" + binURI + "> "
            + "<http://www.w3.org/TR/rdf-schema/label> \"this is a label\" } WHERE {}"));

    final Instant lastmod2;
    try (final CloseableHttpResponse response = execute(patchBinary)) {
        assertEquals(NO_CONTENT.getStatusCode(), getStatus(response));
        lastmod2 = Instant.from(headerFormat.parse(response.getFirstHeader("Last-Modified").getValue()));
        assertTrue(lastmod2.isAfter(lastmod1));
    }

    sleep(1000); // wait a second to make sure last-modified value will be different

    final Instant lastmod3;
    try (final CloseableHttpResponse response = execute(putDSMethod(objid, "binary1", "new test content"))) {
        assertEquals(NO_CONTENT.getStatusCode(), getStatus(response));
        lastmod3 = Instant.from(headerFormat.parse(response.getFirstHeader("Last-Modified").getValue()));
        assertTrue(lastmod3.isAfter(lastmod2));
    }
}

From source file:org.fcrepo.integration.http.api.FedoraLdpIT.java

License:asdf

@Test
public void testContainerLastModified() throws Exception {
    final String objid = getRandomUniqueId();
    final String objURI = serverAddress + objid;

    // create an object
    final long lastmod1;
    try (final CloseableHttpResponse response = execute(putObjMethod(objid))) {
        assertEquals(CREATED.getStatusCode(), getStatus(response));
        lastmod1 = Instant.from(headerFormat.parse(response.getFirstHeader("Last-Modified").getValue()))
                .toEpochMilli();//from   w w  w.j a va 2  s  .c  o m
    }

    sleep(1000); // wait a second to make sure last-modified value will be different

    // initial created and last-modified properties should match
    try (final CloseableDataset dataset = getDataset(getObjMethod(objid))) {
        verifyModifiedMatchesCreated(dataset);
    }

    // update the object properties (last-modified should be updated)
    final HttpPatch patchObject = new HttpPatch(objURI);
    patchObject.addHeader(CONTENT_TYPE, "application/sparql-update");
    patchObject.setEntity(new StringEntity(
            "INSERT { <> " + "<http://www.w3.org/TR/rdf-schema/label> \"this is a label\" } WHERE {}"));
    final long lastmod2;
    try (final CloseableHttpResponse response = execute(patchObject)) {
        assertEquals(NO_CONTENT.getStatusCode(), getStatus(response));
        lastmod2 = Instant.from(headerFormat.parse(response.getFirstHeader("Last-Modified").getValue()))
                .toEpochMilli();
        assertTrue(lastmod2 > lastmod1);
    }

    sleep(1000); // wait a second to make sure last-modified value will be different

    // create a direct container (last-modified should be updated)
    final long lastmod3;
    final HttpPut createContainer = new HttpPut(objURI + "/members");
    createContainer.addHeader(CONTENT_TYPE, "text/turtle");
    final String membersRDF = "<> a <http://www.w3.org/ns/ldp#DirectContainer>; "
            + "<http://www.w3.org/ns/ldp#hasMemberRelation> <http://pcdm.org/models#hasMember>; "
            + "<http://www.w3.org/ns/ldp#membershipResource> <" + objURI + "> . ";
    createContainer.setEntity(new StringEntity(membersRDF));
    try (final CloseableHttpResponse response = execute(createContainer)) {
        assertEquals(CREATED.getStatusCode(), getStatus(response));
        lastmod3 = Instant.from(headerFormat.parse(response.getFirstHeader("Last-Modified").getValue()))
                .toEpochMilli();
        assertTrue(lastmod3 > lastmod2);
    }

    sleep(1000); // wait a second to make sure last-modified value will be different

    // create child in the container
    final long lastmod4;
    assertEquals(CREATED.getStatusCode(), getStatus(new HttpPut(objURI + "/members/member1")));

    // last-modified should be updated
    try (final CloseableHttpResponse response = execute(headObjMethod(objid))) {
        assertEquals(OK.getStatusCode(), getStatus(response));
        lastmod4 = Instant.from(headerFormat.parse(response.getFirstHeader("Last-Modified").getValue()))
                .toEpochMilli();
        assertTrue(lastmod4 > lastmod3);
    }
}

From source file:org.haiku.haikudepotserver.job.controller.JobController.java

/**
 * <p>This is helper-code that can be used to check to see if the data is stale and
 * will then enqueue the job, run it and then redirect the user to the data
 * download.</p>/*from w  w w  .  j  a  v  a2  s .  c o m*/
 * @param response is the HTTP response to send the redirect to.
 * @param ifModifiedSinceHeader is the inbound header from the client.
 * @param lastModifyTimestamp is the actual last modified date for the data.
 * @param jobSpecification is the job that would be run if the data is newer than in the
 *                         inbound header.
 */

public static void handleRedirectToJobData(HttpServletResponse response, JobService jobService,
        String ifModifiedSinceHeader, Date lastModifyTimestamp, JobSpecification jobSpecification)
        throws IOException {

    if (!Strings.isNullOrEmpty(ifModifiedSinceHeader)) {
        try {
            Date requestModifyTimestamp = new Date(Instant
                    .from(DateTimeFormatter.RFC_1123_DATE_TIME.parse(ifModifiedSinceHeader)).toEpochMilli());

            if (requestModifyTimestamp.getTime() >= lastModifyTimestamp.getTime()) {
                response.setStatus(HttpStatus.NOT_MODIFIED.value());
                return;
            }
        } catch (DateTimeParseException dtpe) {
            LOGGER.warn("bad [{}] header on request; [{}] -- will ignore", HttpHeaders.IF_MODIFIED_SINCE,
                    StringUtils.abbreviate(ifModifiedSinceHeader, 128));
        }
    }

    // what happens here is that we get the report and if it is too old, delete it and try again.

    JobSnapshot jobSnapshot = getJobSnapshotStartedAfter(jobService, lastModifyTimestamp, jobSpecification);
    Set<String> jobDataGuids = jobSnapshot.getDataGuids();

    if (1 != jobDataGuids.size()) {
        throw new IllegalStateException("found [" + jobDataGuids.size()
                + "] job data guids related to the job [" + jobSnapshot.getGuid() + "] - was expecting 1");
    }

    String lastModifiedValue = DateTimeFormatter.RFC_1123_DATE_TIME
            .format(ZonedDateTime.ofInstant(lastModifyTimestamp.toInstant(), ZoneOffset.UTC));
    String destinationLocationUrl = UriComponentsBuilder.newInstance()
            .pathSegment(AuthenticationFilter.SEGMENT_SECURED).pathSegment(JobController.SEGMENT_JOBDATA)
            .pathSegment(jobDataGuids.iterator().next()).pathSegment(JobController.SEGMENT_DOWNLOAD)
            .toUriString();

    response.addHeader(HttpHeaders.LAST_MODIFIED, lastModifiedValue);
    response.sendRedirect(destinationLocationUrl);
}

From source file:org.sakaiproject.assignment.impl.AssignmentServiceImpl.java

@Override
@Transactional/*from   ww w  .ja va  2 s . c o m*/
public Map<String, String> transferCopyEntities(String fromContext, String toContext, List<String> ids,
        List<String> transferOptions) {

    Map<String, String> transversalMap = new HashMap<>();
    Collection<Assignment> assignments = getAssignmentsForContext(fromContext);

    for (Assignment oAssignment : assignments) {
        String oAssignmentId = oAssignment.getId();
        String nAssignmentId = null;

        if (ids == null || ids.isEmpty() || ids.contains(oAssignmentId)) {
            try {
                Assignment nAssignment = addAssignment(toContext);
                nAssignmentId = nAssignment.getId();

                nAssignment.setTitle(oAssignment.getTitle());
                // replace all occurrence of old context with new context inside instruction text
                if (StringUtils.isNotBlank(oAssignment.getInstructions())) {
                    nAssignment
                            .setInstructions(oAssignment.getInstructions().replaceAll(fromContext, toContext));
                }
                nAssignment.setTypeOfGrade(oAssignment.getTypeOfGrade());
                nAssignment.setTypeOfSubmission(oAssignment.getTypeOfSubmission());

                // User supplied publish option takes precedence, then property, then source.
                if (transferOptions != null && transferOptions.contains(EntityTransferrer.PUBLISH_OPTION)) {
                    nAssignment.setDraft(false);
                } else if (serverConfigurationService.getBoolean("import.importAsDraft", true)) {
                    nAssignment.setDraft(true);
                } else {
                    nAssignment.setDraft(oAssignment.getDraft());
                }

                nAssignment.setCloseDate(oAssignment.getCloseDate());
                nAssignment.setDropDeadDate(oAssignment.getDropDeadDate());
                nAssignment.setDueDate(oAssignment.getDueDate());
                nAssignment.setOpenDate(oAssignment.getOpenDate());
                nAssignment.setHideDueDate(oAssignment.getHideDueDate());

                nAssignment.setPosition(oAssignment.getPosition());
                nAssignment.setAllowAttachments(oAssignment.getAllowAttachments());
                nAssignment.setHonorPledge(oAssignment.getHonorPledge());
                nAssignment.setIndividuallyGraded(oAssignment.getIndividuallyGraded());
                nAssignment.setMaxGradePoint(oAssignment.getMaxGradePoint());
                nAssignment.setScaleFactor(oAssignment.getScaleFactor());
                nAssignment.setReleaseGrades(oAssignment.getReleaseGrades());

                // group assignment
                if (oAssignment.getTypeOfAccess() == GROUP) {
                    nAssignment.setTypeOfAccess(GROUP);
                    Site oSite = siteService.getSite(oAssignment.getContext());
                    Site nSite = siteService.getSite(nAssignment.getContext());

                    boolean siteChanged = false;
                    Collection<Group> nGroups = nSite.getGroups();
                    for (String groupId : oAssignment.getGroups()) {
                        Group oGroup = oSite.getGroup(groupId);
                        Optional<Group> existingGroup = nGroups.stream()
                                .filter(g -> StringUtils.equals(g.getTitle(), oGroup.getTitle())).findAny();
                        Group nGroup;
                        if (existingGroup.isPresent()) {
                            // found a matching group
                            nGroup = existingGroup.get();
                        } else {
                            // create group
                            nGroup = nSite.addGroup();
                            nGroup.setTitle(oGroup.getTitle());
                            nGroup.setDescription(oGroup.getDescription());
                            nGroup.getProperties().addProperty("group_prop_wsetup_created",
                                    Boolean.TRUE.toString());
                            siteChanged = true;
                        }
                        nAssignment.getGroups().add(nGroup.getReference());
                    }
                    if (siteChanged)
                        siteService.save(nSite);
                    nAssignment.setIsGroup(oAssignment.getIsGroup());
                }

                // review service
                nAssignment.setContentReview(oAssignment.getContentReview());

                // attachments
                Set<String> oAttachments = oAssignment.getAttachments();
                List<Reference> nAttachments = entityManager.newReferenceList();
                for (String oAttachment : oAttachments) {
                    Reference oReference = entityManager.newReference(oAttachment);
                    String oAttachmentId = oReference.getId();
                    // transfer attachment, replace the context string if necessary and add new attachment
                    String nReference = transferAttachment(fromContext, toContext, oAttachmentId);
                    nAssignment.getAttachments().add(nReference);
                }

                // peer review
                nAssignment.setAllowPeerAssessment(oAssignment.getAllowPeerAssessment());
                nAssignment.setPeerAssessmentAnonEval(oAssignment.getPeerAssessmentAnonEval());
                nAssignment.setPeerAssessmentInstructions(oAssignment.getPeerAssessmentInstructions());
                nAssignment.setPeerAssessmentNumberReviews(oAssignment.getPeerAssessmentNumberReviews());
                nAssignment.setPeerAssessmentStudentReview(oAssignment.getPeerAssessmentStudentReview());
                nAssignment.setPeerAssessmentPeriodDate(oAssignment.getPeerAssessmentPeriodDate());
                if (nAssignment.getPeerAssessmentPeriodDate() == null && nAssignment.getCloseDate() != null) {
                    // set the peer period time to be 10 mins after accept until date
                    Instant tenMinutesAfterCloseDate = Instant
                            .from(nAssignment.getCloseDate().plus(Duration.ofMinutes(10)));
                    nAssignment.setPeerAssessmentPeriodDate(tenMinutesAfterCloseDate);
                }

                // properties
                Map<String, String> nProperties = nAssignment.getProperties();
                nProperties.putAll(oAssignment.getProperties());
                // remove the link btw assignment and announcement item. One can announce the open date afterwards
                nProperties.remove(ResourceProperties.NEW_ASSIGNMENT_CHECK_AUTO_ANNOUNCE);
                nProperties.remove(AssignmentConstants.NEW_ASSIGNMENT_OPEN_DATE_ANNOUNCED);
                nProperties.remove(ResourceProperties.PROP_ASSIGNMENT_OPENDATE_ANNOUNCEMENT_MESSAGE_ID);

                // remove the link btw assignment and calendar item. One can add the due date to calendar afterwards
                nProperties.remove(ResourceProperties.NEW_ASSIGNMENT_CHECK_ADD_DUE_DATE);
                nProperties.remove(AssignmentConstants.NEW_ASSIGNMENT_DUE_DATE_SCHEDULED);
                nProperties.remove(ResourceProperties.PROP_ASSIGNMENT_DUEDATE_CALENDAR_EVENT_ID);

                if (!nAssignment.getDraft()) {
                    Map<String, String> oProperties = oAssignment.getProperties();

                    String fromCalendarEventId = oProperties
                            .get(ResourceProperties.PROP_ASSIGNMENT_DUEDATE_CALENDAR_EVENT_ID);

                    if (fromCalendarEventId != null) {
                        String fromCalendarId = calendarService.calendarReference(oAssignment.getContext(),
                                SiteService.MAIN_CONTAINER);
                        Calendar fromCalendar = calendarService.getCalendar(fromCalendarId);
                        CalendarEvent fromEvent = fromCalendar.getEvent(fromCalendarEventId);
                        String toCalendarId = calendarService.calendarReference(nAssignment.getContext(),
                                SiteService.MAIN_CONTAINER);
                        Calendar toCalendar = null;
                        try {
                            toCalendar = calendarService.getCalendar(toCalendarId);
                        } catch (IdUnusedException iue) {
                            calendarService.commitCalendar(calendarService.addCalendar(toCalendarId));
                            toCalendar = calendarService.getCalendar(toCalendarId);
                        }

                        String fromDisplayName = fromEvent.getDisplayName();
                        CalendarEvent toCalendarEvent = toCalendar.addEvent(fromEvent.getRange(),
                                fromEvent.getDisplayName(), fromEvent.getDescription(), fromEvent.getType(),
                                fromEvent.getLocation(), fromEvent.getAccess(), fromEvent.getGroups(),
                                fromEvent.getAttachments());
                        nProperties.put(ResourceProperties.PROP_ASSIGNMENT_DUEDATE_CALENDAR_EVENT_ID,
                                toCalendarEvent.getId());
                        nProperties.put(AssignmentConstants.NEW_ASSIGNMENT_DUE_DATE_SCHEDULED,
                                Boolean.TRUE.toString());
                        nProperties.put(ResourceProperties.NEW_ASSIGNMENT_CHECK_ADD_DUE_DATE,
                                Boolean.TRUE.toString());
                    }

                    String openDateAnnounced = StringUtils.trimToNull(
                            oProperties.get(AssignmentConstants.NEW_ASSIGNMENT_OPEN_DATE_ANNOUNCED));
                    String fromAnnouncementId = StringUtils.trimToNull(oProperties
                            .get(ResourceProperties.PROP_ASSIGNMENT_OPENDATE_ANNOUNCEMENT_MESSAGE_ID));
                    AnnouncementChannel fromChannel = getAnnouncementChannel(oAssignment.getContext());
                    if (fromChannel != null && fromAnnouncementId != null) {
                        AnnouncementMessage fromAnnouncement = fromChannel
                                .getAnnouncementMessage(fromAnnouncementId);
                        AnnouncementChannel toChannel = getAnnouncementChannel(nAssignment.getContext());
                        if (toChannel == null) {
                            // Create the announcement channel
                            String toChannelId = announcementService.channelReference(nAssignment.getContext(),
                                    siteService.MAIN_CONTAINER);
                            announcementService
                                    .commitChannel(announcementService.addAnnouncementChannel(toChannelId));
                            toChannel = getAnnouncementChannel(nAssignment.getContext());
                        }
                        AnnouncementMessage toAnnouncement = toChannel.addAnnouncementMessage(
                                fromAnnouncement.getAnnouncementHeader().getSubject(),
                                fromAnnouncement.getAnnouncementHeader().getDraft(),
                                fromAnnouncement.getAnnouncementHeader().getAttachments(),
                                fromAnnouncement.getBody());
                        nProperties.put(AssignmentConstants.NEW_ASSIGNMENT_OPEN_DATE_ANNOUNCED,
                                Boolean.TRUE.toString());
                        nProperties.put(ResourceProperties.PROP_ASSIGNMENT_OPENDATE_ANNOUNCEMENT_MESSAGE_ID,
                                toAnnouncement.getId());
                        nProperties.put(ResourceProperties.NEW_ASSIGNMENT_CHECK_AUTO_ANNOUNCE,
                                Boolean.TRUE.toString());
                    }
                }

                // gradebook-integration link
                String associatedGradebookAssignment = nProperties
                        .get(PROP_ASSIGNMENT_ASSOCIATE_GRADEBOOK_ASSIGNMENT);
                if (StringUtils.isBlank(associatedGradebookAssignment)) {
                    // if the association property is empty then set gradebook integration to not integrated
                    nProperties.put(NEW_ASSIGNMENT_ADD_TO_GRADEBOOK, GRADEBOOK_INTEGRATION_NO);
                } else {
                    // see if the old assignment's associated gradebook item is an internal gradebook entry or externally defined
                    boolean isExternalAssignmentDefined = gradebookExternalAssessmentService
                            .isExternalAssignmentDefined(oAssignment.getContext(),
                                    associatedGradebookAssignment);
                    if (isExternalAssignmentDefined) {
                        if (!nAssignment.getDraft()) {
                            String gbUid = nAssignment.getContext();
                            if (!gradebookFrameworkService.isGradebookDefined(gbUid)) {
                                gradebookFrameworkService.addGradebook(gbUid, gbUid);
                            }
                            // This assignment has been published, make sure the associated gb item is available
                            org.sakaiproject.service.gradebook.shared.Assignment gbAssignment = gradebookService
                                    .getAssignmentByNameOrId(nAssignment.getContext(),
                                            associatedGradebookAssignment);

                            if (gbAssignment == null) {
                                // The associated gb item hasn't been created here yet.
                                gbAssignment = gradebookService.getExternalAssignment(oAssignment.getContext(),
                                        associatedGradebookAssignment);

                                Optional<Long> categoryId = createCategoryForGbAssignmentIfNecessary(
                                        gbAssignment, oAssignment.getContext(), nAssignment.getContext());

                                String assignmentRef = AssignmentReferenceReckoner.reckoner()
                                        .assignment(nAssignment).reckon().getReference();

                                gradebookExternalAssessmentService.addExternalAssessment(
                                        nAssignment.getContext(), assignmentRef, null, nAssignment.getTitle(),
                                        nAssignment.getMaxGradePoint() / (double) nAssignment.getScaleFactor(),
                                        Date.from(nAssignment.getDueDate()), this.getToolTitle(), null, false,
                                        categoryId.isPresent() ? categoryId.get() : null);

                                nProperties.put(PROP_ASSIGNMENT_ASSOCIATE_GRADEBOOK_ASSIGNMENT, assignmentRef);
                            }
                        } else {
                            // if this is an external defined (came from assignment)
                            // mark the link as "add to gradebook" for the new imported assignment, since the assignment is still of draft state
                            // later when user posts the assignment, the corresponding assignment will be created in gradebook.
                            nProperties.remove(PROP_ASSIGNMENT_ASSOCIATE_GRADEBOOK_ASSIGNMENT);
                            nProperties.put(NEW_ASSIGNMENT_ADD_TO_GRADEBOOK, GRADEBOOK_INTEGRATION_ADD);
                        }
                    } else {
                        // If this is an internal gradebook item then it should be associated with the assignment
                        try {
                            org.sakaiproject.service.gradebook.shared.Assignment gbAssignment = gradebookService
                                    .getAssignmentByNameOrId(nAssignment.getContext(),
                                            associatedGradebookAssignment);

                            if (gbAssignment == null) {
                                if (!nAssignment.getDraft()) {
                                    // The target gb item doesn't exist and we're in publish mode, so copy it over.
                                    gbAssignment = gradebookService.getAssignmentByNameOrId(
                                            oAssignment.getContext(), associatedGradebookAssignment);
                                    gbAssignment.setId(null);

                                    Optional<Long> categoryId = createCategoryForGbAssignmentIfNecessary(
                                            gbAssignment, oAssignment.getContext(), nAssignment.getContext());

                                    if (categoryId.isPresent()) {
                                        gbAssignment.setCategoryId(categoryId.get());
                                    }

                                    gradebookService.addAssignment(nAssignment.getContext(), gbAssignment);
                                    nProperties.put(PROP_ASSIGNMENT_ASSOCIATE_GRADEBOOK_ASSIGNMENT,
                                            gbAssignment.getName());
                                } else {
                                    nProperties.put(PROP_ASSIGNMENT_ASSOCIATE_GRADEBOOK_ASSIGNMENT,
                                            AssignmentReferenceReckoner.reckoner().assignment(nAssignment)
                                                    .reckon().getReference());
                                    nProperties.put(NEW_ASSIGNMENT_ADD_TO_GRADEBOOK, GRADEBOOK_INTEGRATION_ADD);
                                }
                            } else {
                                // migrate to gradebook assignment id (vs title)
                                associatedGradebookAssignment = gbAssignment.getId().toString();
                                nProperties.put(NEW_ASSIGNMENT_ADD_TO_GRADEBOOK,
                                        GRADEBOOK_INTEGRATION_ASSOCIATE);
                                nProperties.put(PROP_ASSIGNMENT_ASSOCIATE_GRADEBOOK_ASSIGNMENT,
                                        associatedGradebookAssignment);
                            }
                        } catch (AssessmentNotFoundException anfe) {
                            log.info(
                                    "While importing assignment {} the associated gradebook item {} was missing, "
                                            + "switching assignment linkage to added by assignments",
                                    nAssignmentId, associatedGradebookAssignment);
                        }
                    }
                }

                updateAssignment(nAssignment);

                transversalMap.put("assignment/" + oAssignmentId, "assignment/" + nAssignmentId);
                log.info("Old assignment id: {} - new assignment id: {}", oAssignmentId, nAssignmentId);

                try {
                    if (taggingManager.isTaggable()) {
                        for (TaggingProvider provider : taggingManager.getProviders()) {
                            provider.transferCopyTags(assignmentActivityProducer.getActivity(oAssignment),
                                    assignmentActivityProducer.getActivity(nAssignment));
                        }
                    }
                } catch (PermissionException pe) {
                    log.error("{} oAssignmentId={} nAssignmentId={}", pe.toString(), oAssignmentId,
                            nAssignmentId);
                }

                // Import supplementary items if they are present in the assignment to be imported
                // Model Answer
                AssignmentModelAnswerItem oModelAnswerItem = assignmentSupplementItemService
                        .getModelAnswer(oAssignmentId);
                if (oModelAnswerItem != null) {
                    AssignmentModelAnswerItem nModelAnswerItem = assignmentSupplementItemService
                            .newModelAnswer();
                    assignmentSupplementItemService.saveModelAnswer(nModelAnswerItem);
                    nModelAnswerItem.setAssignmentId(nAssignmentId);
                    nModelAnswerItem.setText(oModelAnswerItem.getText());
                    nModelAnswerItem.setShowTo(oModelAnswerItem.getShowTo());
                    Set<AssignmentSupplementItemAttachment> oModelAnswerItemAttachments = oModelAnswerItem
                            .getAttachmentSet();
                    Set<AssignmentSupplementItemAttachment> nModelAnswerItemAttachments = new HashSet<>();
                    for (AssignmentSupplementItemAttachment oAttachment : oModelAnswerItemAttachments) {
                        AssignmentSupplementItemAttachment nAttachment = assignmentSupplementItemService
                                .newAttachment();
                        // New attachment creation
                        String nAttachmentId = transferAttachment(fromContext, toContext,
                                removeReferencePrefix(oAttachment.getAttachmentId()));
                        if (StringUtils.isNotEmpty(nAttachmentId)) {
                            nAttachment.setAssignmentSupplementItemWithAttachment(nModelAnswerItem);
                            nAttachment.setAttachmentId(nAttachmentId);
                            assignmentSupplementItemService.saveAttachment(nAttachment);
                            nModelAnswerItemAttachments.add(nAttachment);
                        }
                    }
                    nModelAnswerItem.setAttachmentSet(nModelAnswerItemAttachments);
                    assignmentSupplementItemService.saveModelAnswer(nModelAnswerItem);
                }

                // Private Note
                AssignmentNoteItem oNoteItem = assignmentSupplementItemService.getNoteItem(oAssignmentId);
                if (oNoteItem != null) {
                    AssignmentNoteItem nNoteItem = assignmentSupplementItemService.newNoteItem();
                    //assignmentSupplementItemService.saveNoteItem(nNoteItem);
                    nNoteItem.setAssignmentId(nAssignment.getId());
                    nNoteItem.setNote(oNoteItem.getNote());
                    nNoteItem.setShareWith(oNoteItem.getShareWith());
                    nNoteItem.setCreatorId(userDirectoryService.getCurrentUser().getId());
                    assignmentSupplementItemService.saveNoteItem(nNoteItem);
                }

                // All Purpose
                AssignmentAllPurposeItem oAllPurposeItem = assignmentSupplementItemService
                        .getAllPurposeItem(oAssignmentId);
                if (oAllPurposeItem != null) {
                    AssignmentAllPurposeItem nAllPurposeItem = assignmentSupplementItemService
                            .newAllPurposeItem();
                    assignmentSupplementItemService.saveAllPurposeItem(nAllPurposeItem);
                    nAllPurposeItem.setAssignmentId(nAssignment.getId());
                    nAllPurposeItem.setTitle(oAllPurposeItem.getTitle());
                    nAllPurposeItem.setText(oAllPurposeItem.getText());
                    nAllPurposeItem.setHide(oAllPurposeItem.getHide());
                    nAllPurposeItem.setReleaseDate(null);
                    nAllPurposeItem.setRetractDate(null);
                    Set<AssignmentSupplementItemAttachment> oAllPurposeItemAttachments = oAllPurposeItem
                            .getAttachmentSet();
                    Set<AssignmentSupplementItemAttachment> nAllPurposeItemAttachments = new HashSet<>();
                    for (AssignmentSupplementItemAttachment oAttachment : oAllPurposeItemAttachments) {
                        AssignmentSupplementItemAttachment nAttachment = assignmentSupplementItemService
                                .newAttachment();
                        // New attachment creation
                        String nAttachId = transferAttachment(fromContext, toContext,
                                removeReferencePrefix(oAttachment.getAttachmentId()));
                        if (StringUtils.isNotEmpty(nAttachId)) {
                            nAttachment.setAssignmentSupplementItemWithAttachment(nAllPurposeItem);
                            nAttachment.setAttachmentId(nAttachId);
                            assignmentSupplementItemService.saveAttachment(nAttachment);
                            nAllPurposeItemAttachments.add(nAttachment);
                        }
                    }
                    nAllPurposeItem.setAttachmentSet(nAllPurposeItemAttachments);
                    assignmentSupplementItemService.cleanAllPurposeItemAccess(nAllPurposeItem);
                    Set<AssignmentAllPurposeItemAccess> accessSet = new HashSet<>();
                    AssignmentAllPurposeItemAccess access = assignmentSupplementItemService
                            .newAllPurposeItemAccess();
                    access.setAccess(userDirectoryService.getCurrentUser().getId());
                    access.setAssignmentAllPurposeItem(nAllPurposeItem);
                    assignmentSupplementItemService.saveAllPurposeItemAccess(access);
                    accessSet.add(access);
                    nAllPurposeItem.setAccessSet(accessSet);
                    assignmentSupplementItemService.saveAllPurposeItem(nAllPurposeItem);
                }
            } catch (Exception e) {
                log.error("{} oAssignmentId={} nAssignmentId={}", e.toString(), oAssignmentId, nAssignmentId);
            }
        }
    }
    return transversalMap;
}