Created
September 24, 2020 22:59
-
-
Save ryanschuhler/ea1120742b085edc8c22c1163e0a1595 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Copyright (c) 2000-present Liferay, Inc. All rights reserved. | |
* | |
* This library is free software; you can redistribute it and/or modify it under | |
* the terms of the GNU Lesser General Public License as published by the Free | |
* Software Foundation; either version 2.1 of the License, or (at your option) | |
* any later version. | |
* | |
* This library is distributed in the hope that it will be useful, but WITHOUT | |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS | |
* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more | |
* details. | |
*/ | |
package com.liferay.osb.www.fragment.collection.contributor.components.global.internal.upgrade; | |
import com.bazaarvoice.jolt.Chainr; | |
import com.bazaarvoice.jolt.JsonUtils; | |
import com.liferay.fragment.model.FragmentEntryLink; | |
import com.liferay.fragment.service.FragmentEntryLinkLocalService; | |
import com.liferay.petra.content.ContentUtil; | |
import com.liferay.petra.string.StringPool; | |
import com.liferay.portal.kernel.upgrade.UpgradeProcess; | |
import java.util.List; | |
/** | |
* @author Allen Ziegenfus | |
*/ | |
public class BaseUpgradeFragmentConfigurationValues extends UpgradeProcess { | |
public static final String TRANSFORM_PATH_BASE = | |
"com/liferay/osb/www/fragment/collection/contributor/components/global"; | |
public BaseUpgradeFragmentConfigurationValues( | |
FragmentEntryLinkLocalService fragmentEntryLinkLocalService) { | |
_fragmentEntryLinkLocalService = fragmentEntryLinkLocalService; | |
} | |
public String transformJSON(String inputJSON) { | |
String transformJSON = ContentUtil.get( | |
BaseUpgradeFragmentConfigurationValues.class.getClassLoader(), | |
TRANSFORM_PATH_BASE + getTransformFilename()); | |
List transformList = JsonUtils.jsonToList(transformJSON); | |
Chainr chainr = Chainr.fromSpec(transformList); | |
Object input = JsonUtils.jsonToObject(inputJSON); | |
Object transformedOutput = chainr.transform(input); | |
return JsonUtils.toJsonString(transformedOutput); | |
} | |
@Override | |
protected void doUpgrade() throws Exception { | |
for (String rendererKey : getRendererKeys()) { | |
List<FragmentEntryLink> fragmentEntryLinks = | |
_fragmentEntryLinkLocalService.getFragmentEntryLinks( | |
rendererKey); | |
for (FragmentEntryLink fragmentEntryLink : fragmentEntryLinks) { | |
fragmentEntryLink.setEditableValues( | |
transformJSON(fragmentEntryLink.getEditableValues())); | |
_fragmentEntryLinkLocalService.updateFragmentEntryLink( | |
fragmentEntryLink); | |
} | |
} | |
} | |
protected String[] getRendererKeys() { | |
return new String[0]; | |
} | |
protected String getTransformFilename() { | |
return StringPool.BLANK; | |
} | |
private FragmentEntryLinkLocalService _fragmentEntryLinkLocalService; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment