Skip to content

[Misc] Move some deprecated class from model-api to legacy #3706

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,13 @@
<version>${commons.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.xwiki.platform</groupId>
<artifactId>xwiki-platform-model-api</artifactId>
<version>${project.version}</version>
<type>test-jar</type>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.xwiki.commons</groupId>
<artifactId>xwiki-commons-tool-test-jmock</artifactId>
Expand Down
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);
}
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
org.xwiki.model.internal.reference.DefaultEntityReferenceValueProvider
org.xwiki.model.internal.reference.DeprecatedDefaultReferenceDocumentReferenceResolver
org.xwiki.model.internal.reference.DeprecatedDefaultReferenceDocumentReferenceResolver2
org.xwiki.model.internal.reference.DeprecatedDefaultReferenceEntityReferenceResolver
Expand All @@ -19,3 +20,4 @@ org.xwiki.model.internal.reference.DeprecatedLocalReferenceEntityReferenceSerial
org.xwiki.model.internal.reference.DeprecatedLocalReferenceEntityReferenceSerializer2
org.xwiki.model.internal.reference.DeprecatedLocalStringEntityReferenceSerializer
org.xwiki.model.internal.reference.DeprecatedRelativeStringEntityReferenceResolver
500:org.xwiki.model.script.LegacyModelScriptService
Original file line number Diff line number Diff line change
Expand Up @@ -49,22 +49,24 @@ public class DefaultEntityReferenceValueProviderTest implements TestConstants
@BeforeEach
public void beforeEach()
{
when(this.configuration.getDefaultReferenceValue(EntityType.SPACE)).thenReturn(DEFAULT_SPACE);
when(this.configuration.getDefaultReferenceValue(EntityType.WIKI)).thenReturn(DEFAULT_WIKI);
when(this.configuration.getDefaultReferenceValue(EntityType.DOCUMENT)).thenReturn(DEFAULT_DOCUMENT);
when(this.configuration.getDefaultReferenceValue(EntityType.ATTACHMENT)).thenReturn(DEFAULT_ATTACHMENT);
when(this.configuration.getDefaultReferenceValue(EntityType.PAGE)).thenReturn(DEFAULT_PAGE);
when(this.configuration.getDefaultReferenceValue(EntityType.PAGE_ATTACHMENT)).thenReturn(DEFAULT_ATTACHMENT);
when(this.configuration.getDefaultReferenceValue(EntityType.SPACE)).thenReturn(TestConstants.DEFAULT_SPACE);
when(this.configuration.getDefaultReferenceValue(EntityType.WIKI)).thenReturn(TestConstants.DEFAULT_WIKI);
when(this.configuration.getDefaultReferenceValue(EntityType.DOCUMENT)).thenReturn(TestConstants.DEFAULT_DOCUMENT);
when(this.configuration.getDefaultReferenceValue(EntityType.ATTACHMENT)).thenReturn(
TestConstants.DEFAULT_ATTACHMENT);
when(this.configuration.getDefaultReferenceValue(EntityType.PAGE)).thenReturn(TestConstants.DEFAULT_PAGE);
when(this.configuration.getDefaultReferenceValue(EntityType.PAGE_ATTACHMENT)).thenReturn(
TestConstants.DEFAULT_ATTACHMENT);
}

@Test
public void testGetDefaultValue()
{
assertEquals(DEFAULT_WIKI, this.provider.getDefaultValue(EntityType.WIKI));
assertEquals(DEFAULT_SPACE, this.provider.getDefaultValue(EntityType.SPACE));
assertEquals(DEFAULT_DOCUMENT, this.provider.getDefaultValue(EntityType.DOCUMENT));
assertEquals(DEFAULT_ATTACHMENT, this.provider.getDefaultValue(EntityType.ATTACHMENT));
assertEquals(DEFAULT_PAGE, this.provider.getDefaultValue(EntityType.PAGE));
assertEquals(DEFAULT_ATTACHMENT, this.provider.getDefaultValue(EntityType.PAGE_ATTACHMENT));
assertEquals(TestConstants.DEFAULT_WIKI, this.provider.getDefaultValue(EntityType.WIKI));
assertEquals(TestConstants.DEFAULT_SPACE, this.provider.getDefaultValue(EntityType.SPACE));
assertEquals(TestConstants.DEFAULT_DOCUMENT, this.provider.getDefaultValue(EntityType.DOCUMENT));
assertEquals(TestConstants.DEFAULT_ATTACHMENT, this.provider.getDefaultValue(EntityType.ATTACHMENT));
assertEquals(TestConstants.DEFAULT_PAGE, this.provider.getDefaultValue(EntityType.PAGE));
assertEquals(TestConstants.DEFAULT_ATTACHMENT, this.provider.getDefaultValue(EntityType.PAGE_ATTACHMENT));
}
}
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));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,12 @@
</exclusion>
</exclusions>
</dependency>
<!-- Legacy oldcore needs some legacy classes from legacy model -->
<dependency>
<groupId>org.xwiki.platform</groupId>
<artifactId>xwiki-platform-legacy-model-api</artifactId>
<version>${project.version}</version>
</dependency>

<!-- Legacy oldcore needs some legacy classes from legacy rendering -->
<dependency>
Expand All @@ -78,6 +84,7 @@
<version>${rendering.version}</version>
</dependency>


<!-- Build tools -->
<!-- Needed for backward compatibility Aspects -->
<dependency>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
org.xwiki.legacy.internal.oldcore.notification.LegacyNotificationDispatcher
com.xpn.xwiki.internal.mandatory.SheetClassDocumentInitializer
com.xpn.xwiki.internal.model.reference.CurrentEntityReferenceValueProvider
com.xpn.xwiki.internal.model.reference.CurrentMixedEntityReferenceValueProvider
com.xpn.xwiki.internal.model.reference.DeprecatedCompactStringEntityReferenceSerializer
com.xpn.xwiki.internal.model.reference.DeprecatedCompactWikiStringEntityReferenceSerializer
com.xpn.xwiki.internal.model.reference.DeprecatedCurrentMixedReferenceDocumentReferenceResolver
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@
<xwiki.jacoco.instructionRatio>0.79</xwiki.jacoco.instructionRatio>
<!-- Define the old name of this module for extensions using it -->
<xwiki.extension.features>org.xwiki.platform:xwiki-platform-model</xwiki.extension.features>
<!-- revapi call skipped since there's a legacy module -->
<xwiki.revapi.skip>true</xwiki.revapi.skip>
</properties>
<dependencies>
<dependency>
Expand Down Expand Up @@ -99,6 +101,23 @@
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<executions>
<execution>
<id>test-jar</id>
<goals>
<goal>test-jar</goal>
</goals>
<configuration>
<includes>
<include>**/TestConstants.class</include>
</includes>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@
import org.xwiki.model.reference.EntityReferenceResolver;
import org.xwiki.model.reference.EntityReferenceSerializer;
import org.xwiki.model.reference.EntityReferenceTree;
import org.xwiki.model.reference.EntityReferenceValueProvider;
import org.xwiki.model.reference.ObjectPropertyReference;
import org.xwiki.model.reference.ObjectReference;
import org.xwiki.model.reference.PageAttachmentReference;
Expand All @@ -68,7 +67,7 @@ public class ModelScriptService implements ScriptService
/**
* The default hint used when resolving references.
*/
private static final String DEFAULT_RESOLVER_HINT = "current";
protected static final String DEFAULT_RESOLVER_HINT = "current";

/**
* The default hint used when serializing references.
Expand All @@ -85,7 +84,8 @@ public class ModelScriptService implements ScriptService
* Used to dynamically look up component implementations based on a given hint.
*/
@Inject
private ComponentManager componentManager;
@Named("context")
protected ComponentManager componentManager;

@Inject
private EntityReferenceSerializer<String> defaultSerializer;
Expand Down Expand Up @@ -830,51 +830,6 @@ public String serialize(EntityReference reference, String hint, Object... parame
return result;
}

/**
* 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);
}

/**
* 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 reference configured for a specific entity type, like the space reference or wiki reference. This
* doesn't return a full entity reference, but just the part that should be used for that type of entity.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ org.xwiki.model.internal.DefaultModelConfiguration
org.xwiki.model.internal.DefaultModelContext
org.xwiki.model.internal.reference.DefaultDocumentReferenceProvider
org.xwiki.model.internal.reference.DefaultEntityReferenceProvider
org.xwiki.model.internal.reference.DefaultEntityReferenceValueProvider
org.xwiki.model.internal.reference.DefaultPageReferenceProvider
org.xwiki.model.internal.reference.DefaultReferenceAttachmentReferenceResolver
org.xwiki.model.internal.reference.DefaultReferenceEntityReferenceResolver
Expand Down
Loading