-
-
Notifications
You must be signed in to change notification settings - Fork 553
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Misc] Move some deprecated class from model-api to legacy
- Loading branch information
Showing
20 changed files
with
236 additions
and
135 deletions.
There are no files selected for viewing
This file contains 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
File renamed without changes.
File renamed without changes.
86 changes: 86 additions & 0 deletions
86
...tform-legacy-model-api/src/main/java/org/xwiki/model/script/LegacyModelScriptService.java
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
/* | ||
* See the NOTICE file distributed with this work for additional | ||
* information regarding copyright ownership. | ||
* | ||
* This 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 software 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. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public | ||
* License along with this software; if not, write to the Free | ||
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA | ||
* 02110-1301 USA, or see the FSF site: http://www.fsf.org. | ||
*/ | ||
package org.xwiki.model.script; | ||
|
||
import javax.inject.Named; | ||
import javax.inject.Singleton; | ||
|
||
import org.xwiki.component.annotation.Component; | ||
import org.xwiki.component.manager.ComponentLookupException; | ||
import org.xwiki.model.EntityType; | ||
import org.xwiki.model.reference.EntityReferenceValueProvider; | ||
|
||
/** | ||
* Legacy version of {@link ModelScriptService}, holding deprecated methods. | ||
* | ||
* @version $Id$ | ||
* @since 17.0.0RC1 | ||
*/ | ||
@Deprecated(since = "17.0.0RC1") | ||
@Component | ||
@Named("model") | ||
@Singleton | ||
public class LegacyModelScriptService extends ModelScriptService | ||
{ | ||
/** | ||
* Get the value configured for a specific entity type, like the space name or wiki name. This doesn't return a | ||
* proper entity reference, but just the string value that should be used for that type of entity. | ||
* | ||
* @param type the target entity type; from Velocity it's enough to use a string with the uppercase name of the | ||
* entity, like {@code 'SPACE'} | ||
* @param hint the hint of the value provider to use (valid hints are for example "default", "current" and | ||
* "currentmixed") | ||
* @return the configured value for the requested entity type, for example "Main" for the default space or "WebHome" | ||
* for the default space homepage | ||
* @since 4.3M1 | ||
* @deprecated since 7.2M1, use {@link #getEntityReference(EntityType, String)} | ||
*/ | ||
@Deprecated | ||
public String getEntityReferenceValue(EntityType type, String hint) | ||
{ | ||
if (type == null) { | ||
return null; | ||
} | ||
|
||
try { | ||
EntityReferenceValueProvider provider = | ||
this.componentManager.getInstance(EntityReferenceValueProvider.class, hint); | ||
return provider.getDefaultValue(type); | ||
} catch (ComponentLookupException ex) { | ||
return null; | ||
} | ||
} | ||
|
||
/** | ||
* Get the current value for a specific entity type, like the current space or wiki name. This doesn't return a | ||
* proper entity reference, but just the string value that should be used for that type of entity. | ||
* | ||
* @param type the target entity type; from Velocity it's enough to use a string with the uppercase name of the | ||
* entity, like {@code 'SPACE'} | ||
* @return the current value for the requested entity type | ||
* @since 4.3M1 | ||
* @deprecated since 7.4.1/8.0M1, use {@link #getEntityReference(EntityType)} | ||
*/ | ||
@Deprecated | ||
public String getEntityReferenceValue(EntityType type) | ||
{ | ||
return getEntityReferenceValue(type, DEFAULT_RESOLVER_HINT); | ||
} | ||
} |
This file contains 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
This file contains 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
74 changes: 74 additions & 0 deletions
74
...m-legacy-model-api/src/test/java/org/xwiki/model/script/LegacyModelScriptServiceTest.java
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
/* | ||
* See the NOTICE file distributed with this work for additional | ||
* information regarding copyright ownership. | ||
* | ||
* This 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 software 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. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public | ||
* License along with this software; if not, write to the Free | ||
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA | ||
* 02110-1301 USA, or see the FSF site: http://www.fsf.org. | ||
*/ | ||
package org.xwiki.model.script; | ||
|
||
import javax.inject.Named; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import org.mockito.Mock; | ||
import org.xwiki.component.manager.ComponentLookupException; | ||
import org.xwiki.component.manager.ComponentManager; | ||
import org.xwiki.model.EntityType; | ||
import org.xwiki.model.reference.EntityReferenceValueProvider; | ||
import org.xwiki.test.junit5.mockito.ComponentTest; | ||
import org.xwiki.test.junit5.mockito.InjectMockComponents; | ||
import org.xwiki.test.junit5.mockito.MockComponent; | ||
|
||
import static org.junit.jupiter.api.Assertions.*; | ||
import static org.mockito.Mockito.when; | ||
|
||
@ComponentTest | ||
class LegacyModelScriptServiceTest | ||
{ | ||
@InjectMockComponents | ||
private LegacyModelScriptService service; | ||
|
||
@MockComponent | ||
@Named("context") | ||
private ComponentManager componentManager; | ||
|
||
@Mock | ||
private EntityReferenceValueProvider valueProvider; | ||
|
||
@Test | ||
void getEntityReferenceValue() throws Exception | ||
{ | ||
when(this.componentManager.getInstance(EntityReferenceValueProvider.class, "current")) | ||
.thenReturn(this.valueProvider); | ||
when(this.valueProvider.getDefaultValue(EntityType.WIKI)).thenReturn("somewiki"); | ||
|
||
assertEquals("somewiki", this.service.getEntityReferenceValue(EntityType.WIKI)); | ||
} | ||
|
||
@Test | ||
void getEntityReferenceValueWithInvalidHint() throws Exception | ||
{ | ||
when(this.componentManager.getInstance(EntityReferenceValueProvider.class, "invalid")) | ||
.thenThrow(new ComponentLookupException("error")); | ||
|
||
assertNull(this.service.getEntityReferenceValue(EntityType.WIKI, "invalid")); | ||
} | ||
|
||
@Test | ||
void getEntityReferenceValueWithNullType() throws Exception | ||
{ | ||
assertNull(this.service.getEntityReferenceValue(null)); | ||
} | ||
} |
This file contains 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
File renamed without changes.
File renamed without changes.
2 changes: 2 additions & 0 deletions
2
...-platform-legacy/xwiki-platform-legacy-oldcore/src/main/resources/META-INF/components.txt
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Oops, something went wrong.