@Test public void testUnmarshallLifecycle() { final long currentTimeMillis = System.currentTimeMillis(); final String createdUser = "createdUser"; final String approvedUser = "approvedUser"; final String publishedUser = "publishedUser"; final String expiredUser = "expiredUser"; final String maintenanceUser = "maintenanceUser"; final Calendar createdCalendar = getCalendarForMillis(currentTimeMillis - (5L * MILLIS_IN_ONE_DAY)); final Calendar approvedCalendar = getCalendarForMillis(currentTimeMillis - (4L * MILLIS_IN_ONE_DAY)); final Calendar publishedCalendar = getCalendarForMillis(currentTimeMillis - (3L * MILLIS_IN_ONE_DAY)); final Calendar expiredCalendar = getCalendarForMillis(currentTimeMillis + MILLIS_IN_ONE_DAY); final Calendar maintenanceCalendar = getCalendarForMillis(currentTimeMillis - (2L * MILLIS_IN_ONE_DAY)); final LifecycleEntry created = new LifecycleEntry(); created.setName("CREATED"); created.setUser(createdUser); created.setValue(createdCalendar); final LifecycleEntry approved = new LifecycleEntry(); approved.setName("APPROVED"); approved.setUser(approvedUser); approved.setValue(approvedCalendar); final LifecycleEntry published = new LifecycleEntry(); published.setName("PUBLISHED"); published.setUser(publishedUser); published.setValue(publishedCalendar); final LifecycleEntry expired = new LifecycleEntry(); expired.setName("EXPIRED"); expired.setUser(expiredUser); expired.setValue(expiredCalendar); final LifecycleEntry maintenance = new LifecycleEntry(); maintenance.setName("MAINTENANCE"); maintenance.setUser(maintenanceUser); maintenance.setValue(maintenanceCalendar); final Lifecycle lifecycle1 = new Lifecycle(); lifecycle1.getEntries().add(created); final Lifecycle lifecycle2 = new Lifecycle(); lifecycle2.getEntries().add(created); lifecycle2.getEntries().add(approved); final Lifecycle lifecycle3 = new Lifecycle(); lifecycle3.getEntries().add(published); lifecycle3.getEntries().add(expired); final Lifecycle lifecycle4 = new Lifecycle(); lifecycle4.getEntries().add(created); lifecycle4.getEntries().add(approved); lifecycle4.getEntries().add(published); lifecycle4.getEntries().add(maintenance); lifecycle4.getEntries().add(expired); final Lifecycle[] lifecyclesToTest = new Lifecycle[] {lifecycle1, lifecycle2, lifecycle3, lifecycle4}; final IPortletLifecycleEntry[][] expectedPortletLifecycles = new IPortletLifecycleEntry[][] { new IPortletLifecycleEntry[] { new PortletLifecycleEntryImpl( createdUser.hashCode(), PortletLifecycleState.CREATED, createdCalendar.getTime()) }, new IPortletLifecycleEntry[] { new PortletLifecycleEntryImpl( createdUser.hashCode(), PortletLifecycleState.CREATED, createdCalendar.getTime()), new PortletLifecycleEntryImpl( approvedUser.hashCode(), PortletLifecycleState.APPROVED, approvedCalendar.getTime()) }, new IPortletLifecycleEntry[] { new PortletLifecycleEntryImpl( publishedUser.hashCode(), PortletLifecycleState.PUBLISHED, publishedCalendar.getTime()), new PortletLifecycleEntryImpl( expiredUser.hashCode(), PortletLifecycleState.EXPIRED, expiredCalendar.getTime()) }, new IPortletLifecycleEntry[] { new PortletLifecycleEntryImpl( createdUser.hashCode(), PortletLifecycleState.CREATED, createdCalendar.getTime()), new PortletLifecycleEntryImpl( approvedUser.hashCode(), PortletLifecycleState.APPROVED, approvedCalendar.getTime()), new PortletLifecycleEntryImpl( publishedUser.hashCode(), PortletLifecycleState.PUBLISHED, publishedCalendar.getTime()), new PortletLifecycleEntryImpl( maintenanceUser.hashCode(), PortletLifecycleState.MAINTENANCE, maintenanceCalendar.getTime()), new PortletLifecycleEntryImpl( expiredUser.hashCode(), PortletLifecycleState.EXPIRED, expiredCalendar.getTime()) } }; final ExternalPortletDefinitionUnmarshaller unmarshaller = new ExternalPortletDefinitionUnmarshaller(); unmarshaller.setUserIdentityStore(new MockUserIdentityStore()); final IPortletType portletType = new PortletTypeImpl("FakePortletType", "http: for (int i = 0; i < lifecyclesToTest.length; i++) { final Lifecycle lifecycle = lifecyclesToTest[i]; final IPortletDefinition pDef = new PortletDefinitionImpl( portletType, "fake-portlet", "Fake Portlet", "Fake Portlet", "FakePortletApp", "fake-portlet-def", false); unmarshaller.unmarshallLifecycle(lifecycle, pDef); final IPortletLifecycleEntry[] expectedLifecycle = expectedPortletLifecycles[i]; for (IPortletLifecycleEntry y : pDef.getLifecycle()) { System.out.println(" ## "); System.out.println(" ## y.getLifecycleState()=" + y.getLifecycleState()); } assertArrayEquals(pDef.getLifecycle().toArray(), expectedLifecycle); } }
void unmarshallLifecycle( final Lifecycle lifecycle, final IPortletDefinition portletDefinition) { portletDefinition.clearLifecycle(); if (lifecycle == null) { portletDefinition.updateLifecycleState(PortletLifecycleState.PUBLISHED, systemUser); } else if (lifecycle.getEntries().isEmpty()) { portletDefinition.updateLifecycleState(PortletLifecycleState.CREATED, systemUser); } else { Map<IPortletLifecycleEntry, IPerson> convertedEntries = new TreeMap<>(); for (LifecycleEntry entry : lifecycle.getEntries()) { final IPerson user = StringUtils.isNotBlank(entry.getUser()) ? userIdentityStore.getPerson(entry.getUser(), true) : systemUser; final PortletLifecycleState state = PortletLifecycleState.valueOf(entry.getName().toUpperCase()); final Date date = entry.getValue().equals(useCurrentDatetimeSignal) ? new Date() : entry.getValue().getTime(); convertedEntries.put( new IPortletLifecycleEntry() { @Override public int getUserId() { return user.getID(); } @Override public PortletLifecycleState getLifecycleState() { return state; } @Override public Date getDate() { return date; } @Override public int compareTo(IPortletLifecycleEntry o) { int rslt = date.compareTo(o.getDate()); if (rslt == 0) { rslt = state.getOrder() - o.getLifecycleState().getOrder(); } return rslt; } }, user); } convertedEntries.forEach( (k, v) -> { portletDefinition.updateLifecycleState( k.getLifecycleState(), v, k.getDate()); }); } }
ExternalPortletDefinitionUnmarshaller { void unmarshallLifecycle( final Lifecycle lifecycle, final IPortletDefinition portletDefinition) { portletDefinition.clearLifecycle(); if (lifecycle == null) { portletDefinition.updateLifecycleState(PortletLifecycleState.PUBLISHED, systemUser); } else if (lifecycle.getEntries().isEmpty()) { portletDefinition.updateLifecycleState(PortletLifecycleState.CREATED, systemUser); } else { Map<IPortletLifecycleEntry, IPerson> convertedEntries = new TreeMap<>(); for (LifecycleEntry entry : lifecycle.getEntries()) { final IPerson user = StringUtils.isNotBlank(entry.getUser()) ? userIdentityStore.getPerson(entry.getUser(), true) : systemUser; final PortletLifecycleState state = PortletLifecycleState.valueOf(entry.getName().toUpperCase()); final Date date = entry.getValue().equals(useCurrentDatetimeSignal) ? new Date() : entry.getValue().getTime(); convertedEntries.put( new IPortletLifecycleEntry() { @Override public int getUserId() { return user.getID(); } @Override public PortletLifecycleState getLifecycleState() { return state; } @Override public Date getDate() { return date; } @Override public int compareTo(IPortletLifecycleEntry o) { int rslt = date.compareTo(o.getDate()); if (rslt == 0) { rslt = state.getOrder() - o.getLifecycleState().getOrder(); } return rslt; } }, user); } convertedEntries.forEach( (k, v) -> { portletDefinition.updateLifecycleState( k.getLifecycleState(), v, k.getDate()); }); } } }
ExternalPortletDefinitionUnmarshaller { void unmarshallLifecycle( final Lifecycle lifecycle, final IPortletDefinition portletDefinition) { portletDefinition.clearLifecycle(); if (lifecycle == null) { portletDefinition.updateLifecycleState(PortletLifecycleState.PUBLISHED, systemUser); } else if (lifecycle.getEntries().isEmpty()) { portletDefinition.updateLifecycleState(PortletLifecycleState.CREATED, systemUser); } else { Map<IPortletLifecycleEntry, IPerson> convertedEntries = new TreeMap<>(); for (LifecycleEntry entry : lifecycle.getEntries()) { final IPerson user = StringUtils.isNotBlank(entry.getUser()) ? userIdentityStore.getPerson(entry.getUser(), true) : systemUser; final PortletLifecycleState state = PortletLifecycleState.valueOf(entry.getName().toUpperCase()); final Date date = entry.getValue().equals(useCurrentDatetimeSignal) ? new Date() : entry.getValue().getTime(); convertedEntries.put( new IPortletLifecycleEntry() { @Override public int getUserId() { return user.getID(); } @Override public PortletLifecycleState getLifecycleState() { return state; } @Override public Date getDate() { return date; } @Override public int compareTo(IPortletLifecycleEntry o) { int rslt = date.compareTo(o.getDate()); if (rslt == 0) { rslt = state.getOrder() - o.getLifecycleState().getOrder(); } return rslt; } }, user); } convertedEntries.forEach( (k, v) -> { portletDefinition.updateLifecycleState( k.getLifecycleState(), v, k.getDate()); }); } } ExternalPortletDefinitionUnmarshaller(); }
ExternalPortletDefinitionUnmarshaller { void unmarshallLifecycle( final Lifecycle lifecycle, final IPortletDefinition portletDefinition) { portletDefinition.clearLifecycle(); if (lifecycle == null) { portletDefinition.updateLifecycleState(PortletLifecycleState.PUBLISHED, systemUser); } else if (lifecycle.getEntries().isEmpty()) { portletDefinition.updateLifecycleState(PortletLifecycleState.CREATED, systemUser); } else { Map<IPortletLifecycleEntry, IPerson> convertedEntries = new TreeMap<>(); for (LifecycleEntry entry : lifecycle.getEntries()) { final IPerson user = StringUtils.isNotBlank(entry.getUser()) ? userIdentityStore.getPerson(entry.getUser(), true) : systemUser; final PortletLifecycleState state = PortletLifecycleState.valueOf(entry.getName().toUpperCase()); final Date date = entry.getValue().equals(useCurrentDatetimeSignal) ? new Date() : entry.getValue().getTime(); convertedEntries.put( new IPortletLifecycleEntry() { @Override public int getUserId() { return user.getID(); } @Override public PortletLifecycleState getLifecycleState() { return state; } @Override public Date getDate() { return date; } @Override public int compareTo(IPortletLifecycleEntry o) { int rslt = date.compareTo(o.getDate()); if (rslt == 0) { rslt = state.getOrder() - o.getLifecycleState().getOrder(); } return rslt; } }, user); } convertedEntries.forEach( (k, v) -> { portletDefinition.updateLifecycleState( k.getLifecycleState(), v, k.getDate()); }); } } ExternalPortletDefinitionUnmarshaller();  }
ExternalPortletDefinitionUnmarshaller { void unmarshallLifecycle( final Lifecycle lifecycle, final IPortletDefinition portletDefinition) { portletDefinition.clearLifecycle(); if (lifecycle == null) { portletDefinition.updateLifecycleState(PortletLifecycleState.PUBLISHED, systemUser); } else if (lifecycle.getEntries().isEmpty()) { portletDefinition.updateLifecycleState(PortletLifecycleState.CREATED, systemUser); } else { Map<IPortletLifecycleEntry, IPerson> convertedEntries = new TreeMap<>(); for (LifecycleEntry entry : lifecycle.getEntries()) { final IPerson user = StringUtils.isNotBlank(entry.getUser()) ? userIdentityStore.getPerson(entry.getUser(), true) : systemUser; final PortletLifecycleState state = PortletLifecycleState.valueOf(entry.getName().toUpperCase()); final Date date = entry.getValue().equals(useCurrentDatetimeSignal) ? new Date() : entry.getValue().getTime(); convertedEntries.put( new IPortletLifecycleEntry() { @Override public int getUserId() { return user.getID(); } @Override public PortletLifecycleState getLifecycleState() { return state; } @Override public Date getDate() { return date; } @Override public int compareTo(IPortletLifecycleEntry o) { int rslt = date.compareTo(o.getDate()); if (rslt == 0) { rslt = state.getOrder() - o.getLifecycleState().getOrder(); } return rslt; } }, user); } convertedEntries.forEach( (k, v) -> { portletDefinition.updateLifecycleState( k.getLifecycleState(), v, k.getDate()); }); } } ExternalPortletDefinitionUnmarshaller();   }