Skip to content

Commit f2a2a68

Browse files
committed
Take into account some feedbacks of SonarCloud about cyclic dependencies
1 parent 363b142 commit f2a2a68

File tree

10 files changed

+127
-180
lines changed

10 files changed

+127
-180
lines changed

core-library/src/main/java/org/silverpeas/core/admin/component/model/WAComponent.java

Lines changed: 3 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -24,22 +24,10 @@
2424
package org.silverpeas.core.admin.component.model;
2525

2626
import org.silverpeas.core.admin.component.WAComponentRegistry;
27-
import org.silverpeas.core.admin.service.AdminException;
28-
import org.silverpeas.core.admin.service.ComponentInstManager;
29-
import org.silverpeas.kernel.SilverpeasRuntimeException;
30-
31-
import javax.xml.bind.annotation.XmlAccessType;
32-
import javax.xml.bind.annotation.XmlAccessorType;
33-
import javax.xml.bind.annotation.XmlElement;
34-
import javax.xml.bind.annotation.XmlElementWrapper;
35-
import javax.xml.bind.annotation.XmlType;
27+
28+
import javax.xml.bind.annotation.*;
3629
import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
37-
import java.util.ArrayList;
38-
import java.util.Collection;
39-
import java.util.HashMap;
40-
import java.util.List;
41-
import java.util.Map;
42-
import java.util.Optional;
30+
import java.util.*;
4331

4432
import static org.silverpeas.core.i18n.I18NHelper.checkLanguage;
4533

@@ -388,18 +376,4 @@ public boolean isTopicTracker() {
388376
return getBehaviors() != null &&
389377
getBehaviors().getBehavior().contains(ComponentBehavior.TOPIC_TRACKER);
390378
}
391-
392-
/**
393-
* Gets all the identifiers of the instances of this WA component.
394-
* @return a list of component instance identifiers. An empty list if there is no yet instances
395-
* of this WA component.
396-
* @throws SilverpeasRuntimeException if an error occurs while getting the existing instances.
397-
*/
398-
public List<String> getAllInstanceIds() {
399-
try {
400-
return List.of(ComponentInstManager.get().getAllCompoIdsByComponentName(name));
401-
} catch (AdminException e) {
402-
throw new SilverpeasRuntimeException(e);
403-
}
404-
}
405379
}

core-library/src/main/java/org/silverpeas/core/admin/persistence/ComponentInstanceTable.java

Lines changed: 5 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -27,16 +27,10 @@
2727
import org.silverpeas.core.annotation.Repository;
2828
import org.silverpeas.core.persistence.jdbc.DBUtil;
2929

30-
import java.sql.Connection;
31-
import java.sql.PreparedStatement;
32-
import java.sql.ResultSet;
33-
import java.sql.SQLException;
34-
import java.sql.Types;
30+
import java.sql.*;
3531
import java.util.Date;
3632
import java.util.List;
3733

38-
import static org.silverpeas.core.SilverpeasExceptionMessages.unknown;
39-
4034
/**
4135
* A ComponentInstanceTable object manages the ST_ComponentInstance table.
4236
*/
@@ -113,22 +107,6 @@ public ComponentInstanceRow getComponentInstance(int id) throws SQLException {
113107
return getUniqueRow(SELECT_INSTANCE_BY_ID, id);
114108
}
115109

116-
/**
117-
* Returns the ComponentInstance of a given user role.
118-
* @param userRoleId id of user role
119-
* @return the ComponentInstance of a given user role.
120-
* @throws SQLException on error
121-
*/
122-
public ComponentInstanceRow getComponentInstanceOfUserRole(int userRoleId)
123-
throws SQLException {
124-
return getUniqueRow(SELECT_USERROLE_INSTANCE, userRoleId);
125-
}
126-
127-
private static final String SELECT_USERROLE_INSTANCE =
128-
SELECT + Table.aliasColumns("i", INSTANCE_COLUMNS) +
129-
" from ST_ComponentInstance i, ST_UserRole us" +
130-
" where i.id = us.instanceId and us.id = ?";
131-
132110
/**
133111
* Returns all the instances in a given space
134112
* @param spaceId the space id
@@ -138,7 +116,7 @@ public ComponentInstanceRow getComponentInstanceOfUserRole(int userRoleId)
138116
public ComponentInstanceRow[] getAllComponentInstancesInSpace(int spaceId)
139117
throws SQLException {
140118
List<ComponentInstanceRow> rows = getRows(SELECT_ALL_SPACE_INSTANCES, spaceId);
141-
return rows.toArray(new ComponentInstanceRow[rows.size()]);
119+
return rows.toArray(new ComponentInstanceRow[0]);
142120
}
143121

144122
private static final String SELECT_ALL_SPACE_INSTANCES = SELECT + INSTANCE_COLUMNS +
@@ -167,7 +145,7 @@ public String[] getAllComponentInstanceIdsInSpace(int spaceId) throws SQLExcepti
167145
*/
168146
public ComponentInstanceRow[] getRemovedComponents() throws SQLException {
169147
List<ComponentInstanceRow> rows = getRows(SELECT_REMOVED_COMPONENTS);
170-
return rows.toArray(new ComponentInstanceRow[rows.size()]);
148+
return rows.toArray(new ComponentInstanceRow[0]);
171149
}
172150

173151
private static final String SELECT_REMOVED_COMPONENTS =
@@ -186,7 +164,7 @@ public ComponentInstanceRow[] getAllMatchingComponentInstances(
186164
String[] values =
187165
new String[]{sampleInstance.componentName, sampleInstance.name, sampleInstance.description};
188166
List<ComponentInstanceRow> rows = getMatchingRows(INSTANCE_COLUMNS, columns, values);
189-
return rows.toArray(new ComponentInstanceRow[rows.size()]);
167+
return rows.toArray(new ComponentInstanceRow[0]);
190168
}
191169

192170
/**
@@ -196,10 +174,6 @@ public ComponentInstanceRow[] getAllMatchingComponentInstances(
196174
*/
197175
public void createComponentInstance(ComponentInstanceRow instance)
198176
throws SQLException {
199-
SpaceRow space = OrganizationSchema.get().space().getSpace(instance.spaceId);
200-
if (space == null) {
201-
throw new SQLException(unknown("space", String.valueOf(instance.spaceId)));
202-
}
203177
insertRow(INSERT_INSTANCE, instance);
204178
}
205179

@@ -268,7 +242,7 @@ public void updateComponentInheritance(int componentId, boolean inheritanceBlock
268242
/**
269243
* Updates in the database an instance row.
270244
* @param instance the row with the fields of the component instance
271-
* @throws SQLException
245+
* @throws SQLException if the update fails.
272246
*/
273247
public void updateComponentInstance(ComponentInstanceRow instance)
274248
throws SQLException {
@@ -306,7 +280,6 @@ public boolean isComponentIntoBasket(int spaceId, String name) throws SQLExcepti
306280
* @param id the component id
307281
* @param tempLabel the temporary label
308282
* @param userId the user id that deletes the space
309-
* @throws AdminPersistenceException on error
310283
*/
311284
public void sendComponentToBasket(int id, String tempLabel, String userId)
312285
throws SQLException {

core-library/src/main/java/org/silverpeas/core/admin/persistence/UserRoleRow.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,10 @@ public String getObjectType() {
132132
return objectType;
133133
}
134134

135+
public boolean isInstanceIdNotDefined() {
136+
return instanceId == NO_VALUE;
137+
}
138+
135139
public boolean isObjectTypeDefined() {
136140
return StringUtil.isDefined(objectType);
137141
}

0 commit comments

Comments
 (0)