Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into functional-tests
Browse files Browse the repository at this point in the history
# Conflicts:
#	application-admintools-default/src/main/java/com/xwiki/admintools/internal/data/ConfigurationDataProvider.java
#	application-admintools-default/src/main/java/com/xwiki/admintools/internal/data/identifiers/CurrentServer.java
#	application-admintools-default/src/main/java/com/xwiki/admintools/internal/data/identifiers/TomcatInfo.java
#	application-admintools-default/src/test/java/com/xwiki/admintools/internal/data/ConfigurationDataProviderTest.java
#	application-admintools-default/src/test/java/com/xwiki/admintools/internal/data/identifiers/CurrentServerTest.java
  • Loading branch information
ChiuchiuSorin committed Jan 30, 2024
2 parents e0f69bd + 9390191 commit d94abf8
Show file tree
Hide file tree
Showing 31 changed files with 1,078 additions and 257 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
* @version $Id$
*/
@Role
public interface ServerIdentifier
public interface ServerInfo
{
/**
* Verify if a specific server is used. If a server path is provided in the XWiki configurations, it verifies if the
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
/*
* 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 com.xwiki.admintools;

import org.xwiki.stability.Unstable;

/**
* Stores info about the size of a wiki.
*
* @version $Id$
* @since 1.0
*/
@Unstable
public class WikiSizeResult
{
private String name;

private Long userCount;

private String attachmentsSize;

private Long attachmentsCount;

private Long documentsCount;

/**
* Null constructor to initialize a {@link WikiSizeResult} object.
*/
public WikiSizeResult()
{
}

/**
* Get the name of the wiki.
*
* @return the name of the wiki.
*/
public String getName()
{
return name;
}

/**
* Set the name of the wiki.
*
* @param name representing the name of the wiki.
*/
public void setName(String name)
{
this.name = name;
}

/**
* Get the number of users registered in the wiki.
*
* @return {@link Long} representing the number of users in the wiki.
*/
public Long getUserCount()
{
return userCount;
}

/**
* Set the number of users registered in the wiki.
*
* @param userCount the number of users in the wiki.
*/
public void setUserCount(Long userCount)
{
this.userCount = userCount;
}

/**
* Get the total size of the attachments in the wiki.
*
* @return formatted {@link String} with the size of the attachments in the wiki and corresponding size unit.
*/
public String getAttachmentsSize()
{
return attachmentsSize;
}

/**
* Set the total size of the attachments in the wiki.
*
* @param attachmentsSize the size of the attachments in the wiki and corresponding size unit.
*/
public void setAttachmentsSize(String attachmentsSize)
{
this.attachmentsSize = attachmentsSize;
}

/**
* Get the total number of the attachments in wiki.
*
* @return the total number of the attachments in wiki.
*/
public Long getAttachmentsCount()
{
return attachmentsCount;
}

/**
* Set the total number of the attachments in wiki.
*
* @param attachmentsCount the total number of the attachments in wiki.
*/
public void setAttachmentsCount(Long attachmentsCount)
{
this.attachmentsCount = attachmentsCount;
}

/**
* Get the total number of documents in wiki.
*
* @return the total number of documents in wiki.
*/
public Long getDocumentsCount()
{
return documentsCount;
}

/**
* Set the total number of documents in wiki.
*
* @param documentsCount the total number of documents in wiki.
*/
public void setDocumentsCount(Long documentsCount)
{
this.documentsCount = documentsCount;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,10 @@
import com.xwiki.admintools.DataProvider;
import com.xwiki.admintools.internal.data.identifiers.CurrentServer;
import com.xwiki.admintools.internal.files.ImportantFilesManager;
import com.xwiki.admintools.internal.wikiUsage.InstanceUsage;

/**
* Manages the data providers.
* Manages the data that needs to be used by the Admin Tools application.
*
* @version $Id$
*/
Expand All @@ -58,6 +59,9 @@ public class AdminToolsManager
@Inject
private ImportantFilesManager importantFilesManager;

@Inject
private InstanceUsage instanceUsage;

@Inject
@Named("context")
private ComponentManager contextComponentManager;
Expand Down Expand Up @@ -119,4 +123,14 @@ public String getFilesSection()
{
return this.importantFilesManager.renderTemplate();
}

/**
* Get the rendered template for viewing info about the size of the XWiki instance.
*
* @return a {@link String} representation of the rendered template.
*/
public String getInstanceSizeTemplate()
{
return instanceUsage.renderTemplate();
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,12 @@
import javax.inject.Singleton;

import org.apache.commons.lang.exception.ExceptionUtils;
import org.xwiki.activeinstalls2.internal.data.DatabasePing;
import org.xwiki.activeinstalls2.internal.data.ServletContainerPing;
import org.xwiki.component.annotation.Component;

import com.xpn.xwiki.XWiki;
import com.xpn.xwiki.XWikiContext;
import com.xwiki.admintools.ServerIdentifier;
import com.xwiki.admintools.internal.PingProvider;
import com.xwiki.admintools.ServerInfo;
import com.xwiki.admintools.internal.wikiUsage.UsageDataProvider;
import com.xwiki.admintools.internal.data.identifiers.CurrentServer;

/**
Expand Down Expand Up @@ -62,7 +60,7 @@ public class ConfigurationDataProvider extends AbstractDataProvider
private CurrentServer currentServer;

@Inject
private PingProvider pingProvider;
private UsageDataProvider usageDataProvider;

@Override
public String getIdentifier()
Expand Down Expand Up @@ -90,16 +88,16 @@ public Map<String, String> getDataAsJSON() throws Exception
{
try {
Map<String, String> systemInfo = new HashMap<>();
Map<String, String> dbMetadata = this.identifyDB();
Map<String, String> dbMetadata = this.usageDataProvider.getDatabaseMetadata();
systemInfo.put("databaseName", dbMetadata.get(METADATA_NAME));
systemInfo.put("databaseVersion", dbMetadata.get(METADATA_VERSION));
systemInfo.put("xwikiCfgPath", getCurrentServer().getXwikiCfgFolderPath());
systemInfo.put("serverPath", getCurrentServer().getServerPath());
systemInfo.put("tomcatConfPath", this.getCurrentServer().getServerCfgPath());
systemInfo.put("javaVersion", this.getJavaVersion());
ServletContainerPing currentServerMetadata = this.currentServer.getServerMetadata();
systemInfo.put("usedServerName", currentServerMetadata.getName());
systemInfo.put("usedServerVersion", currentServerMetadata.getVersion());
Map<String, String> serverMetadata = this.usageDataProvider.getServerMetadata();
systemInfo.put("usedServerName", serverMetadata.get(METADATA_NAME));
systemInfo.put("usedServerVersion", serverMetadata.get(METADATA_VERSION));
systemInfo.put("xwikiVersion", getXWikiVersion());
systemInfo.putAll(this.getOSInfo());
return systemInfo;
Expand All @@ -118,20 +116,6 @@ private String getJavaVersion()
return System.getProperty("java.version");
}

/**
* Identify the used database for XWiki by accessing the {@link DatabasePing}.
*
* @return database metadata or {@code null} in case of an error or if the used DB is not supported.
*/
private Map<String, String> identifyDB()
{
DatabasePing databasePing = pingProvider.getDatabasePing();
if (databasePing == null) {
return new HashMap<>();
}
return Map.of(METADATA_NAME, databasePing.getName(), METADATA_VERSION, databasePing.getVersion());
}

/**
* Get info about the OS that XWiki is running on.
*
Expand All @@ -147,13 +131,13 @@ private Map<String, String> getOSInfo()
return result;
}

private ServerIdentifier getCurrentServer()
private ServerInfo getCurrentServer()
{
ServerIdentifier serverIdentifier = currentServer.getCurrentServer();
if (serverIdentifier == null) {
ServerInfo serverInfo = currentServer.getCurrentServer();
if (serverInfo == null) {
throw new NullPointerException("Failed to retrieve the current used server, check your configurations.");
}
return serverIdentifier;
return serverInfo;
}

private String getXWikiVersion()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,15 @@
import javax.inject.Inject;
import javax.inject.Named;

import com.xwiki.admintools.ServerIdentifier;
import com.xwiki.admintools.ServerInfo;
import com.xwiki.admintools.configuration.AdminToolsConfiguration;

/**
* Common methods for {@link ServerIdentifier} classes.
* Common methods for {@link ServerInfo} classes.
*
* @version $Id$
*/
public abstract class AbstractServerIdentifier implements ServerIdentifier
public abstract class AbstractServerInfo implements ServerInfo
{
protected String[] serverCfgPossiblePaths;

Expand Down
Loading

0 comments on commit d94abf8

Please sign in to comment.