Skip to content

Commit

Permalink
Merge My Craft Site Review - Meeds-io/MIPs#156 (#211)
Browse files Browse the repository at this point in the history
  • Loading branch information
boubaker authored Sep 5, 2024
2 parents e9bc0e7 + db002e2 commit d36dda4
Show file tree
Hide file tree
Showing 50 changed files with 85 additions and 126 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,15 @@
@Data
public class ApplicationReferenceUpgrade {

private String modificationType = ApplicationReferenceModificationType.UPDATE.name();
private String modificationType = ApplicationReferenceModificationType.UPDATE.name();

private String oldContentId;
private String oldContentId;

private String newContentId;
private String newContentId;

private boolean upgradePages = true;

private boolean upgradePortletInstance = true;

public boolean isModification() {
return StringUtils.equalsIgnoreCase(ApplicationReferenceModificationType.UPDATE.name(), modificationType);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,28 +78,39 @@ public boolean shouldProceedToUpgrade(String newVersion, String previousVersion)

@SneakyThrows
@ContainerTransactional
public void upgradeApplications() {
public void upgradeApplications() { // NOSONAR
List<PortletInstance> portletInstances = portletInstanceService.getPortletInstances();

for (ApplicationReferenceUpgrade applicationModification : upgrades) {
String oldContentId = applicationModification.getOldContentId();
String newContentId = applicationModification.getNewContentId();
PortletInstance portletInstance = portletInstances.stream()
.filter(p -> StringUtils.equals(oldContentId, p.getContentId()))
.findFirst()
.orElse(null);

int modifiedLines = 0;
if (applicationModification.isModification()) {
modifiedLines = windowDAO.updateContentId(oldContentId, newContentId);
if (portletInstance != null) {
portletInstance.setContentId(newContentId);
portletInstanceService.updatePortletInstance(portletInstance);
if (applicationModification.isUpgradePages()) {
modifiedLines = windowDAO.updateContentId(oldContentId, newContentId);
}
if (applicationModification.isUpgradePortletInstance()) {
PortletInstance portletInstance = portletInstances.stream()
.filter(p -> StringUtils.equals(oldContentId, p.getContentId()))
.findFirst()
.orElse(null);
if (portletInstance != null) {
portletInstance.setContentId(newContentId);
portletInstanceService.updatePortletInstance(portletInstance);
}
}
} else if (applicationModification.isRemoval()) {
modifiedLines = windowDAO.deleteByContentId(oldContentId);
if (portletInstance != null) {
portletInstanceService.deletePortletInstance(portletInstance.getId());
if (applicationModification.isUpgradePages()) {
modifiedLines = windowDAO.deleteByContentId(oldContentId);
}
if (applicationModification.isUpgradePortletInstance()) {
PortletInstance portletInstance = portletInstances.stream()
.filter(p -> StringUtils.equals(oldContentId, p.getContentId()))
.findFirst()
.orElse(null);
if (portletInstance != null) {
portletInstanceService.deletePortletInstance(portletInstance.getId());
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,7 @@ private void deletePortletInstanceFromStore(long id) throws ObjectNotFoundExcept
}
try {
translationService.deleteTranslationLabels(PortletInstanceTranslationPlugin.OBJECT_TYPE, id);
} catch (ObjectNotFoundException e) {
} catch (Exception e) {
LOG.debug("Error while deleting translation labels of deleted Portlet instance", e);
}
portletInstanceStorage.deletePortletInstance(id);
Expand Down
19 changes: 0 additions & 19 deletions layout-service/src/main/resources/portlet-instances.json
Original file line number Diff line number Diff line change
Expand Up @@ -76,25 +76,6 @@
],
"system":true
},
{
"nameId":"ExternalSpacesList",
"categoryNameId":"tools",
"portletName":"ExternalSpacesList",
"names":{
"en":"layout.portletInstance.ExternalSpacesList.name"
},
"descriptions":{
"en":"layout.portletInstance.ExternalSpacesList.description"
},
"illustrationPath":"war:/../images/portlets/spacesList.webp",
"preferences":[

],
"permissions":[
"*:/platform/users"
],
"system":true
},
{
"nameId":"GettingStarted",
"categoryNameId":"tools",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@
*/
package io.meeds.layout.plugin.upgrade;

import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.Mockito.*;

import java.util.Collections;

Expand Down Expand Up @@ -73,6 +73,8 @@ public void processUpgradeWithModification() {
when(applicationModification.isModification()).thenReturn(true);
when(applicationModification.getOldContentId()).thenReturn(oldContentId);
when(applicationModification.getNewContentId()).thenReturn(newContentId);
when(applicationModification.isUpgradePages()).thenReturn(true);
when(applicationModification.isUpgradePortletInstance()).thenReturn(true);

LayoutApplicationReferenceUpgradePlugin applicationReferenceUpgradePlugin =
new LayoutApplicationReferenceUpgradePlugin(settingService,
Expand All @@ -96,6 +98,8 @@ public void processUpgradeWithRemoval() {
when(applicationModification.isRemoval()).thenReturn(true);
when(applicationModification.getOldContentId()).thenReturn(oldContentId);
when(applicationModification.getNewContentId()).thenReturn(newContentId);
when(applicationModification.isUpgradePages()).thenReturn(true);
when(applicationModification.isUpgradePortletInstance()).thenReturn(true);
when(portletInstance.getId()).thenReturn(2l);

LayoutApplicationReferenceUpgradePlugin applicationReferenceUpgradePlugin =
Expand All @@ -111,4 +115,47 @@ public void processUpgradeWithRemoval() {
verify(portletInstanceService).deletePortletInstance(2l);
}

@Test
@SneakyThrows
public void processUpgradeWithModificationIgnoreAll() {
when(initParams.getObjectParamValues(ApplicationReferenceUpgrade.class)).thenReturn(Collections.singletonList(applicationModification));
when(portletInstanceService.getPortletInstances()).thenReturn(Collections.singletonList(portletInstance));
when(applicationModification.isModification()).thenReturn(true);
when(applicationModification.getOldContentId()).thenReturn(oldContentId);
when(applicationModification.getNewContentId()).thenReturn(newContentId);

LayoutApplicationReferenceUpgradePlugin applicationReferenceUpgradePlugin =
new LayoutApplicationReferenceUpgradePlugin(settingService,
portletInstanceService,
windowDAO,
initParams);
assertTrue(applicationReferenceUpgradePlugin.shouldProceedToUpgrade(null, null));

applicationReferenceUpgradePlugin.processUpgrade(null, null);

verify(windowDAO, never()).updateContentId(oldContentId, newContentId);
verify(portletInstanceService, never()).updatePortletInstance(portletInstance);
}

@Test
@SneakyThrows
public void processUpgradeWithRemovalIgnoreAll() {
when(initParams.getObjectParamValues(ApplicationReferenceUpgrade.class)).thenReturn(Collections.singletonList(applicationModification));
when(portletInstanceService.getPortletInstances()).thenReturn(Collections.singletonList(portletInstance));
when(applicationModification.isRemoval()).thenReturn(true);
when(applicationModification.getOldContentId()).thenReturn(oldContentId);
when(applicationModification.getNewContentId()).thenReturn(newContentId);

LayoutApplicationReferenceUpgradePlugin applicationReferenceUpgradePlugin =
new LayoutApplicationReferenceUpgradePlugin(settingService,
portletInstanceService,
windowDAO,
initParams);
assertTrue(applicationReferenceUpgradePlugin.shouldProceedToUpgrade(null, null));
applicationReferenceUpgradePlugin.processUpgrade(null, null);

verify(windowDAO, never()).deleteByContentId(oldContentId);
verify(portletInstanceService, never()).deletePortletInstance(2l);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -203,8 +203,6 @@ layout.portletInstance.SpaceSettingPortlet.name=Settings
layout.portletInstance.SpaceSettingPortlet.description=Settings of the space
layout.portletInstance.Image.name=Image
layout.portletInstance.Image.description=Display an image
layout.portletInstance.ExternalSpacesList.name=Spaces list
layout.portletInstance.ExternalSpacesList.description=Gadget listing spaces of the current user
layout.portletInstance.GettingStarted.name=Getting Started
layout.portletInstance.GettingStarted.description=Gadget suggesting first steps to do
layout.portletInstance.SpaceBannerPortlet.name=Space Banner
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -203,8 +203,6 @@ layout.portletInstance.SpaceSettingPortlet.name=Settings
layout.portletInstance.SpaceSettingPortlet.description=Settings of the space
layout.portletInstance.Image.name=Image
layout.portletInstance.Image.description=Display an image
layout.portletInstance.ExternalSpacesList.name=Spaces list
layout.portletInstance.ExternalSpacesList.description=Gadget listing spaces of the current user
layout.portletInstance.GettingStarted.name=Getting Started
layout.portletInstance.GettingStarted.description=Gadget suggesting first steps to do
layout.portletInstance.SpaceBannerPortlet.name=Space Banner
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -203,8 +203,6 @@ layout.portletInstance.SpaceSettingPortlet.name=Settings
layout.portletInstance.SpaceSettingPortlet.description=Settings of the space
layout.portletInstance.Image.name=Image
layout.portletInstance.Image.description=Display an image
layout.portletInstance.ExternalSpacesList.name=Spaces list
layout.portletInstance.ExternalSpacesList.description=Gadget listing spaces of the current user
layout.portletInstance.GettingStarted.name=Getting Started
layout.portletInstance.GettingStarted.description=Gadget suggesting first steps to do
layout.portletInstance.SpaceBannerPortlet.name=Space Banner
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -203,8 +203,6 @@ layout.portletInstance.SpaceSettingPortlet.name=Settings
layout.portletInstance.SpaceSettingPortlet.description=Settings of the space
layout.portletInstance.Image.name=Image
layout.portletInstance.Image.description=Display an image
layout.portletInstance.ExternalSpacesList.name=Spaces list
layout.portletInstance.ExternalSpacesList.description=Gadget listing spaces of the current user
layout.portletInstance.GettingStarted.name=Getting Started
layout.portletInstance.GettingStarted.description=Gadget suggesting first steps to do
layout.portletInstance.SpaceBannerPortlet.name=Space Banner
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -203,8 +203,6 @@ layout.portletInstance.SpaceSettingPortlet.name=Settings
layout.portletInstance.SpaceSettingPortlet.description=Settings of the space
layout.portletInstance.Image.name=Image
layout.portletInstance.Image.description=Display an image
layout.portletInstance.ExternalSpacesList.name=Spaces list
layout.portletInstance.ExternalSpacesList.description=Gadget listing spaces of the current user
layout.portletInstance.GettingStarted.name=Getting Started
layout.portletInstance.GettingStarted.description=Gadget suggesting first steps to do
layout.portletInstance.SpaceBannerPortlet.name=Space Banner
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -203,8 +203,6 @@ layout.portletInstance.SpaceSettingPortlet.name=Settings
layout.portletInstance.SpaceSettingPortlet.description=Settings of the space
layout.portletInstance.Image.name=Image
layout.portletInstance.Image.description=Display an image
layout.portletInstance.ExternalSpacesList.name=Spaces list
layout.portletInstance.ExternalSpacesList.description=Gadget listing spaces of the current user
layout.portletInstance.GettingStarted.name=Getting Started
layout.portletInstance.GettingStarted.description=Gadget suggesting first steps to do
layout.portletInstance.SpaceBannerPortlet.name=Space Banner
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -203,8 +203,6 @@ layout.portletInstance.SpaceSettingPortlet.name=Settings
layout.portletInstance.SpaceSettingPortlet.description=Settings of the space
layout.portletInstance.Image.name=Image
layout.portletInstance.Image.description=Display an image
layout.portletInstance.ExternalSpacesList.name=Spaces list
layout.portletInstance.ExternalSpacesList.description=Gadget listing spaces of the current user
layout.portletInstance.GettingStarted.name=Getting Started
layout.portletInstance.GettingStarted.description=Gadget suggesting first steps to do
layout.portletInstance.SpaceBannerPortlet.name=Space Banner
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -203,8 +203,6 @@ layout.portletInstance.SpaceSettingPortlet.name=Einstellungen
layout.portletInstance.SpaceSettingPortlet.description=Raumeinstellungen
layout.portletInstance.Image.name=Bild
layout.portletInstance.Image.description=Bild anzeigen
layout.portletInstance.ExternalSpacesList.name=Raum-Liste
layout.portletInstance.ExternalSpacesList.description=Tool - Raumliste des aktuellen Benutzers
layout.portletInstance.GettingStarted.name=Erste Schritte
layout.portletInstance.GettingStarted.description=Tool welches erste Schritte vorschlägt
layout.portletInstance.SpaceBannerPortlet.name=Raumbanner
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -203,8 +203,6 @@ layout.portletInstance.SpaceSettingPortlet.name=Settings
layout.portletInstance.SpaceSettingPortlet.description=Settings of the space
layout.portletInstance.Image.name=Image
layout.portletInstance.Image.description=Display an image
layout.portletInstance.ExternalSpacesList.name=Spaces list
layout.portletInstance.ExternalSpacesList.description=Gadget listing spaces of the current user
layout.portletInstance.GettingStarted.name=Getting Started
layout.portletInstance.GettingStarted.description=Gadget suggesting first steps to do
layout.portletInstance.SpaceBannerPortlet.name=Space Banner
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -203,8 +203,6 @@ layout.portletInstance.SpaceSettingPortlet.name=Settings
layout.portletInstance.SpaceSettingPortlet.description=Settings of the space
layout.portletInstance.Image.name=Image
layout.portletInstance.Image.description=Display an image
layout.portletInstance.ExternalSpacesList.name=Spaces list
layout.portletInstance.ExternalSpacesList.description=Gadget listing spaces of the current user
layout.portletInstance.GettingStarted.name=Getting Started
layout.portletInstance.GettingStarted.description=Gadget suggesting first steps to do
layout.portletInstance.SpaceBannerPortlet.name=Space Banner
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -203,8 +203,6 @@ layout.portletInstance.SpaceSettingPortlet.name=Settings
layout.portletInstance.SpaceSettingPortlet.description=Settings of the space
layout.portletInstance.Image.name=Image
layout.portletInstance.Image.description=Display an image
layout.portletInstance.ExternalSpacesList.name=Spaces list
layout.portletInstance.ExternalSpacesList.description=Gadget listing spaces of the current user
layout.portletInstance.GettingStarted.name=Getting Started
layout.portletInstance.GettingStarted.description=Gadget suggesting first steps to do
layout.portletInstance.SpaceBannerPortlet.name=Space Banner
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -203,8 +203,6 @@ layout.portletInstance.SpaceSettingPortlet.name=Settings
layout.portletInstance.SpaceSettingPortlet.description=Settings of the space
layout.portletInstance.Image.name=Image
layout.portletInstance.Image.description=Display an image
layout.portletInstance.ExternalSpacesList.name=Spaces list
layout.portletInstance.ExternalSpacesList.description=Gadget listing spaces of the current user
layout.portletInstance.GettingStarted.name=Getting Started
layout.portletInstance.GettingStarted.description=Gadget suggesting first steps to do
layout.portletInstance.SpaceBannerPortlet.name=Space Banner
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -203,8 +203,6 @@ layout.portletInstance.SpaceSettingPortlet.name=Settings
layout.portletInstance.SpaceSettingPortlet.description=Settings of the space
layout.portletInstance.Image.name=Image
layout.portletInstance.Image.description=Display an image
layout.portletInstance.ExternalSpacesList.name=Spaces list
layout.portletInstance.ExternalSpacesList.description=Gadget listing spaces of the current user
layout.portletInstance.GettingStarted.name=Getting Started
layout.portletInstance.GettingStarted.description=Gadget suggesting first steps to do
layout.portletInstance.SpaceBannerPortlet.name=Space Banner
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -203,8 +203,6 @@ layout.portletInstance.SpaceSettingPortlet.name=Settings
layout.portletInstance.SpaceSettingPortlet.description=Settings of the space
layout.portletInstance.Image.name=Image
layout.portletInstance.Image.description=Display an image
layout.portletInstance.ExternalSpacesList.name=Spaces list
layout.portletInstance.ExternalSpacesList.description=Gadget listing spaces of the current user
layout.portletInstance.GettingStarted.name=Getting Started
layout.portletInstance.GettingStarted.description=Gadget suggesting first steps to do
layout.portletInstance.SpaceBannerPortlet.name=Space Banner
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -203,8 +203,6 @@ layout.portletInstance.SpaceSettingPortlet.name=Settings
layout.portletInstance.SpaceSettingPortlet.description=Settings of the space
layout.portletInstance.Image.name=Image
layout.portletInstance.Image.description=Display an image
layout.portletInstance.ExternalSpacesList.name=Spaces list
layout.portletInstance.ExternalSpacesList.description=Gadget listing spaces of the current user
layout.portletInstance.GettingStarted.name=Getting Started
layout.portletInstance.GettingStarted.description=Gadget suggesting first steps to do
layout.portletInstance.SpaceBannerPortlet.name=Space Banner
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -203,8 +203,6 @@ layout.portletInstance.SpaceSettingPortlet.name=Paramètres
layout.portletInstance.SpaceSettingPortlet.description=Paramètres de l'espace
layout.portletInstance.Image.name=Image
layout.portletInstance.Image.description=Afficher une image
layout.portletInstance.ExternalSpacesList.name=Liste des espaces
layout.portletInstance.ExternalSpacesList.description=Liste des espaces de l'utilisateur actuel
layout.portletInstance.GettingStarted.name=Premiers Pas
layout.portletInstance.GettingStarted.description=Gadget suggérant les premières étapes à faire
layout.portletInstance.SpaceBannerPortlet.name=Bannière de l'espace
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -203,8 +203,6 @@ layout.portletInstance.SpaceSettingPortlet.name=Settings
layout.portletInstance.SpaceSettingPortlet.description=Settings of the space
layout.portletInstance.Image.name=Image
layout.portletInstance.Image.description=Display an image
layout.portletInstance.ExternalSpacesList.name=Spaces list
layout.portletInstance.ExternalSpacesList.description=Gadget listing spaces of the current user
layout.portletInstance.GettingStarted.name=Getting Started
layout.portletInstance.GettingStarted.description=Gadget suggesting first steps to do
layout.portletInstance.SpaceBannerPortlet.name=Space Banner
Expand Down
Loading

0 comments on commit d36dda4

Please sign in to comment.