CCM NG:
- Some cleanup
- Entities for the new database based configuration system
git-svn-id: https://svn.libreccm.org/ccm/ccm_ng@3768 8810af33-2d31-482b-a856-94f89814c4df
pull/2/head
parent
576d28a8ce
commit
e743e052ff
|
|
@ -211,8 +211,8 @@
|
|||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>3.3</version>
|
||||
<configuration>
|
||||
<source>1.7</source>
|
||||
<target>1.7</target>
|
||||
<source>1.8</source>
|
||||
<target>1.8</target>
|
||||
<optimize>true</optimize>
|
||||
<debug>true</debug>
|
||||
<encoding>${project.build.sourceEncoding}</encoding>
|
||||
|
|
@ -426,7 +426,9 @@
|
|||
<exclude>**/AbstractConfig.java</exclude>
|
||||
<exclude>**/AbstractParameter.java</exclude>
|
||||
<exclude>**/AbstractParameterContext.java</exclude>
|
||||
<exclude>**/AbstractSingleSelectionModel.java</exclude>
|
||||
<exclude>**/Assert.java</exclude>
|
||||
<exclude>**/bebop/**</exclude>
|
||||
<exclude>**/CCMApplicationContextListener.java</exclude>
|
||||
<exclude>**/CCMResourceManager.java</exclude>
|
||||
<exclude>**/Classes.java</exclude>
|
||||
|
|
@ -440,6 +442,7 @@
|
|||
<exclude>**/DateFormatter.java</exclude>
|
||||
<exclude>**/DateFormatterConfig.java</exclude>
|
||||
<exclude>**/DateTimeFormatter.java</exclude>
|
||||
<exclude>**/dispatcher/**</exclude>
|
||||
<exclude>**/DispatcherConfig.java</exclude>
|
||||
<exclude>**/Document.java</exclude>
|
||||
<exclude>**/Element.java</exclude>
|
||||
|
|
@ -451,12 +454,15 @@
|
|||
<exclude>**/FileParameter.java</exclude>
|
||||
<exclude>**/FormBuilderConfig.java</exclude>
|
||||
<exclude>**/FullDateFormatter.java</exclude>
|
||||
<exclude>**/globalization/**</exclude>
|
||||
<exclude>**/GlobalizationConfig.java</exclude>
|
||||
<exclude>**/IntegerParameter.java</exclude>
|
||||
<exclude>**/JavaPropertyReader.java</exclude>
|
||||
<exclude>**/JavaPropertyWriter.java</exclude>
|
||||
<exclude>**/kernel/**</exclude>
|
||||
<exclude>**/KernelConfig.java</exclude>
|
||||
<exclude>**/LockableImpl.java</exclude>
|
||||
<exclude>**/mail/**</exclude>
|
||||
<exclude>**/MailConfig.java</exclude>
|
||||
<exclude>**/MapParameter.java</exclude>
|
||||
<exclude>**/NotificationConfig.java</exclude>
|
||||
|
|
@ -470,20 +476,25 @@
|
|||
<exclude>**/SingletonParameter.java</exclude>
|
||||
<exclude>**/SpecificClassParameter.java</exclude>
|
||||
<exclude>**/StringParameter.java</exclude>
|
||||
<exclude>**/templating/**</exclude>
|
||||
<exclude>**/toolbox/**</exclude>
|
||||
<exclude>**/TimeFormatter.java</exclude>
|
||||
<exclude>**/ui/**</exclude>
|
||||
<exclude>**/UIConfig.java</exclude>
|
||||
<exclude>**/UncheckedWrapperException.java</exclude>
|
||||
<exclude>**/util/**</exclude>
|
||||
<exclude>**/web/**</exclude>
|
||||
<exclude>**/WorkflowConfig.java</exclude>
|
||||
<exclude>**/XML.java</exclude>
|
||||
<exclude>**/XMLConfig.java</exclude>
|
||||
</excludes>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<!--<plugin>
|
||||
<groupId>org.codehaus.mojo</groupId>
|
||||
<artifactId>javancss-maven-plugin</artifactId>
|
||||
<version>2.1</version>
|
||||
</plugin>
|
||||
</plugin>-->
|
||||
<plugin>
|
||||
<groupId>org.codehaus.mojo</groupId>
|
||||
<artifactId>jdepend-maven-plugin</artifactId>
|
||||
|
|
|
|||
|
|
@ -75,7 +75,7 @@ public abstract class AbstractAuditedEntityRepository<K, T>
|
|||
* @throws IllegalStateException If the associated entity manager is closed.
|
||||
*/
|
||||
public List<Number> retrieveRevisionNumbersOfEntity(final T entity,
|
||||
Long objectId)
|
||||
final Long objectId)
|
||||
throws IllegalArgumentException, NotAuditedException,
|
||||
IllegalStateException {
|
||||
return auditReader.getRevisions(entity.getClass(), objectId);
|
||||
|
|
|
|||
|
|
@ -20,7 +20,6 @@ package org.libreccm.auditing;
|
|||
|
||||
import org.hibernate.envers.RevisionListener;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
/**
|
||||
* {@link RevisionListener} setting the user for the {@link CcmRevision} entity.
|
||||
|
|
|
|||
|
|
@ -0,0 +1,101 @@
|
|||
/*
|
||||
* Copyright (C) 2015 LibreCCM Foundation.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||||
* MA 02110-1301 USA
|
||||
*/
|
||||
package org.libreccm.configuration;
|
||||
|
||||
import static org.libreccm.core.CoreConstants.*;
|
||||
|
||||
import org.libreccm.core.CcmObject;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Objects;
|
||||
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.Table;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
||||
* @param <T>
|
||||
*/
|
||||
@Entity
|
||||
@Table(name = "CONFIGURATION_ENTRIES", schema = DB_SCHEMA)
|
||||
public abstract class AbstractConfigurationEntry<T>
|
||||
extends CcmObject implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = -839223659103128135L;
|
||||
|
||||
@Column(name = "comment", length = 2048)
|
||||
private String comment;
|
||||
|
||||
public String getComment() {
|
||||
return comment;
|
||||
}
|
||||
|
||||
public void setComment(final String comment) {
|
||||
this.comment = comment;
|
||||
}
|
||||
|
||||
public abstract T getValue();
|
||||
|
||||
public abstract void setValue(T value);
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int hash = super.hashCode();
|
||||
hash = 47 * hash + Objects.hashCode(comment);
|
||||
return hash;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(final Object obj) {
|
||||
if (!super.equals(obj)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (obj == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!(obj instanceof AbstractConfigurationEntry)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
final AbstractConfigurationEntry<?> other
|
||||
= (AbstractConfigurationEntry) obj;
|
||||
if (!other.canEqual(this)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return Objects.equals(comment, other.getComment());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canEqual(final Object obj) {
|
||||
return obj instanceof AbstractConfigurationEntry;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString(final String data) {
|
||||
return super.toString(String.format(", comment = \"%s\"%s",
|
||||
comment,
|
||||
data));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,95 @@
|
|||
/*
|
||||
* Copyright (C) 2015 LibreCCM Foundation.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||||
* MA 02110-1301 USA
|
||||
*/
|
||||
package org.libreccm.configuration;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.math.BigDecimal;
|
||||
import java.util.Objects;
|
||||
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.Table;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
||||
*/
|
||||
@Entity
|
||||
@Table(name = "CONF_ENTRIES_BIG_DECIMAL")
|
||||
public class BigDecimalConfigurationEntry
|
||||
extends AbstractConfigurationEntry<BigDecimal> implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1869044294174385532L;
|
||||
|
||||
@Column(name = "entry_value")
|
||||
private BigDecimal value;
|
||||
|
||||
@Override
|
||||
public BigDecimal getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setValue(final BigDecimal value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int hash = super.hashCode();
|
||||
hash = 79 * hash + Objects.hashCode(value);
|
||||
return hash;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(final Object obj) {
|
||||
if (!super.equals(obj)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (obj == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!(obj instanceof BigDecimalConfigurationEntry)) {
|
||||
return false;
|
||||
}
|
||||
final BigDecimalConfigurationEntry other
|
||||
= (BigDecimalConfigurationEntry) obj;
|
||||
if (!other.canEqual(this)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return Objects.equals(value, other.getValue());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canEqual(final Object obj) {
|
||||
return obj instanceof BigDecimalConfigurationEntry;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString(final String data) {
|
||||
return super.toString(String.format(", value = %s%s",
|
||||
value,
|
||||
data));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,100 @@
|
|||
/*
|
||||
* Copyright (C) 2015 LibreCCM Foundation.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||||
* MA 02110-1301 USA
|
||||
*/
|
||||
package org.libreccm.configuration;
|
||||
|
||||
import static org.libreccm.core.CoreConstants.*;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.Table;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
||||
*/
|
||||
@Entity
|
||||
@Table(name = "CONF_ENTRIES_BOOLEAN", schema = DB_SCHEMA)
|
||||
public class BooleanConfigurationEntry
|
||||
extends AbstractConfigurationEntry<Boolean> implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = -1724350134756734938L;
|
||||
|
||||
@Column(name = "entry_value")
|
||||
private boolean value;
|
||||
|
||||
@Override
|
||||
public Boolean getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setValue(final Boolean value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public boolean isValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
public void setValue(final boolean value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int hash = super.hashCode();
|
||||
hash = 89 * hash + (this.value ? 1 : 0);
|
||||
return hash;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(final Object obj) {
|
||||
if (!(super.equals(obj))) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (obj == null) {
|
||||
return false;
|
||||
}
|
||||
if (!(obj instanceof BooleanConfigurationEntry)) {
|
||||
return false;
|
||||
}
|
||||
final BooleanConfigurationEntry other = (BooleanConfigurationEntry) obj;
|
||||
if (!other.canEqual(this)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return value == other.getValue();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canEqual(final Object obj) {
|
||||
return obj instanceof BooleanConfigurationEntry;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString(final String data) {
|
||||
return super.toString(String.format(", value = %b%s",
|
||||
value,
|
||||
data));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,93 @@
|
|||
/*
|
||||
* Copyright (C) 2015 LibreCCM Foundation.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||||
* MA 02110-1301 USA
|
||||
*/
|
||||
package org.libreccm.configuration;
|
||||
|
||||
import static org.libreccm.core.CoreConstants.*;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.Table;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
||||
*/
|
||||
@Entity
|
||||
@Table(name = "CONF_ENTRIES_DOUBLE", schema = DB_SCHEMA)
|
||||
public class DoubleConfigurationEntry
|
||||
extends AbstractConfigurationEntry<Double> implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = -6944518527865528160L;
|
||||
|
||||
@Column(name = "entry_value")
|
||||
private double value;
|
||||
|
||||
@Override
|
||||
public Double getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setValue(final Double value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int hash = super.hashCode();
|
||||
hash = 71 * hash + Double.hashCode(value);
|
||||
return hash;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(final Object obj) {
|
||||
if (!super.equals(obj)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (obj == null) {
|
||||
return false;
|
||||
}
|
||||
if (!(obj instanceof DoubleConfigurationEntry)) {
|
||||
return false;
|
||||
}
|
||||
final DoubleConfigurationEntry other = (DoubleConfigurationEntry) obj;
|
||||
if (!other.canEqual(this)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return Double.doubleToLongBits(value) == Double.doubleToLongBits(other
|
||||
.getValue());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canEqual(final Object obj) {
|
||||
return obj instanceof DoubleConfigurationEntry;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString(final String data) {
|
||||
return super.toString(String.format(", value = %f%s",
|
||||
value,
|
||||
data));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,119 @@
|
|||
/*
|
||||
* Copyright (C) 2015 LibreCCM Foundation.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||||
* MA 02110-1301 USA
|
||||
*/
|
||||
package org.libreccm.configuration;
|
||||
|
||||
import static org.libreccm.core.CoreConstants.*;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
import javax.persistence.ElementCollection;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.Table;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
||||
*/
|
||||
@Entity
|
||||
@Table(name = "CONF_ENTRIES_ENUM", schema = DB_SCHEMA)
|
||||
public class EnumConfigurationEntry
|
||||
extends AbstractConfigurationEntry<List<String>> implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 8506016944203102813L;
|
||||
|
||||
@ElementCollection
|
||||
private List<String> value;
|
||||
|
||||
@Override
|
||||
public List<String> getValue() {
|
||||
if (value == null) {
|
||||
return null;
|
||||
} else {
|
||||
return Collections.unmodifiableList(value);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setValue(final List<String> value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public void addEnumValue(final String value) {
|
||||
this.value.add(value);
|
||||
}
|
||||
|
||||
public void removeEnumValue(final String value) {
|
||||
this.value.remove(value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int hash = super.hashCode();
|
||||
hash = 89 * hash + Objects.hashCode(value);
|
||||
return hash;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(final Object obj) {
|
||||
if (!super.equals(obj)) {
|
||||
return false;
|
||||
}
|
||||
if (obj == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!(obj instanceof EnumConfigurationEntry)) {
|
||||
return false;
|
||||
}
|
||||
final EnumConfigurationEntry other = (EnumConfigurationEntry) obj;
|
||||
if (!other.canEqual(this)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return Objects.equals(value, other.getValue());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canEqual(final Object obj) {
|
||||
return obj instanceof EnumConfigurationEntry;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString(final String data) {
|
||||
final StringBuffer enumValues = new StringBuffer();
|
||||
enumValues.append("{ ");
|
||||
if (value != null) {
|
||||
value.forEach((String v) -> {
|
||||
enumValues.append('\"').append(v).append('\"');
|
||||
if (enumValues.indexOf(v) != enumValues.length() - 1) {
|
||||
enumValues.append(", ");
|
||||
}
|
||||
});
|
||||
enumValues.append(" }");
|
||||
}
|
||||
|
||||
return super.toString(String.format(", value = %s%s",
|
||||
enumValues.toString(),
|
||||
data));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,106 @@
|
|||
/*
|
||||
* Copyright (C) 2015 LibreCCM Foundation.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||||
* MA 02110-1301 USA
|
||||
*/
|
||||
package org.libreccm.configuration;
|
||||
|
||||
import static org.libreccm.core.CoreConstants.*;
|
||||
|
||||
import org.libreccm.l10n.LocalizedString;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Objects;
|
||||
|
||||
import javax.persistence.AssociationOverride;
|
||||
import javax.persistence.Embedded;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.JoinColumn;
|
||||
import javax.persistence.JoinTable;
|
||||
import javax.persistence.Table;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
||||
*/
|
||||
@Entity
|
||||
@Table(name = "CONF_ENTRIES_L10N_STRING", schema = DB_SCHEMA)
|
||||
public class LocalizedStringConfigurationEntry
|
||||
extends AbstractConfigurationEntry<LocalizedString> implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = -5854552013878000164L;
|
||||
|
||||
@Embedded
|
||||
@AssociationOverride(
|
||||
name = "values",
|
||||
joinTable = @JoinTable(name = "CONF_ENTRIES_L10N_STR_VALUES",
|
||||
schema = DB_SCHEMA,
|
||||
joinColumns = {
|
||||
@JoinColumn(name = "ENTRY_ID")}))
|
||||
private LocalizedString value;
|
||||
|
||||
@Override
|
||||
public LocalizedString getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setValue(final LocalizedString value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int hash = super.hashCode();
|
||||
hash = 53 * hash + Objects.hashCode(value);
|
||||
return hash;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(final Object obj) {
|
||||
if (!super.equals(obj)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (obj == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!(obj instanceof LocalizedStringConfigurationEntry)) {
|
||||
return false;
|
||||
}
|
||||
final LocalizedStringConfigurationEntry other
|
||||
= (LocalizedStringConfigurationEntry) obj;
|
||||
if (!other.canEqual(this)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return Objects.equals(value, other.getValue());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canEqual(final Object obj) {
|
||||
return obj instanceof LocalizedStringConfigurationEntry;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString(final String data) {
|
||||
return super.toString(String.format(", value = %s%s",
|
||||
Objects.toString(value),
|
||||
data));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,93 @@
|
|||
/*
|
||||
* Copyright (C) 2015 LibreCCM Foundation.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||||
* MA 02110-1301 USA
|
||||
*/
|
||||
package org.libreccm.configuration;
|
||||
|
||||
import static org.libreccm.core.CoreConstants.*;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.Table;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
||||
*/
|
||||
@Entity
|
||||
@Table(name = "CONF_ENTRIES_INTEGER", schema = DB_SCHEMA)
|
||||
public class LongConfigurationEntry
|
||||
extends AbstractConfigurationEntry<Long> implements Serializable{
|
||||
|
||||
private static final long serialVersionUID = 818622372461020368L;
|
||||
|
||||
@Column(name = "entry_value")
|
||||
private long value;
|
||||
|
||||
@Override
|
||||
public Long getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setValue(final Long value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int hash = super.hashCode();
|
||||
hash = 89 * hash + Long.hashCode(value);
|
||||
return hash;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(final Object obj) {
|
||||
if (!super.equals(obj)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (obj == null) {
|
||||
return false;
|
||||
}
|
||||
if (!(obj instanceof LongConfigurationEntry)) {
|
||||
return false;
|
||||
}
|
||||
final LongConfigurationEntry other
|
||||
= (LongConfigurationEntry) obj;
|
||||
if (!other.canEqual(this)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return this.value == other.getValue();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canEqual(final Object obj) {
|
||||
return obj instanceof LongConfigurationEntry;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString(final String data) {
|
||||
return super.toString(String.format(", value = %d%s",
|
||||
value,
|
||||
data));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,94 @@
|
|||
/*
|
||||
* Copyright (C) 2015 LibreCCM Foundation.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||||
* MA 02110-1301 USA
|
||||
*/
|
||||
package org.libreccm.configuration;
|
||||
|
||||
import static org.libreccm.core.CoreConstants.*;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Objects;
|
||||
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.Table;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
||||
*/
|
||||
@Entity
|
||||
@Table(name = "CONF_ENTRIES_STRING", schema = DB_SCHEMA)
|
||||
public class StringConfigurationEntry
|
||||
extends AbstractConfigurationEntry<String> implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = -8564570962027541731L;
|
||||
|
||||
@Column(name = "entry_value", length = 1024)
|
||||
private String value;
|
||||
|
||||
@Override
|
||||
public String getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setValue(final String value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int hash = super.hashCode();
|
||||
hash = 67 * hash + Objects.hashCode(value);
|
||||
return hash;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(final Object obj) {
|
||||
if (!super.equals(obj)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (obj == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!(obj instanceof StringConfigurationEntry)) {
|
||||
return false;
|
||||
}
|
||||
final StringConfigurationEntry other = (StringConfigurationEntry) obj;
|
||||
if (!other.canEqual(this)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return Objects.equals(value, other.getValue());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canEqual(final Object obj) {
|
||||
return obj instanceof StringConfigurationEntry;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString(final String data) {
|
||||
return super.toString(String.format(", value = %s%s",
|
||||
value,
|
||||
data));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -40,7 +40,6 @@ import javax.persistence.Inheritance;
|
|||
import javax.persistence.InheritanceType;
|
||||
import javax.persistence.OneToMany;
|
||||
import javax.persistence.Table;
|
||||
import javax.validation.constraints.Pattern;
|
||||
import javax.xml.bind.annotation.XmlElement;
|
||||
import javax.xml.bind.annotation.XmlElementWrapper;
|
||||
import javax.xml.bind.annotation.XmlRootElement;
|
||||
|
|
|
|||
|
|
@ -54,7 +54,7 @@ import javax.sql.DataSource;
|
|||
public class CcmIntegrator implements Integrator {
|
||||
|
||||
private static final Logger LOGGER = LogManager.getLogger(
|
||||
CcmIntegrator.class);
|
||||
CcmIntegrator.class);
|
||||
|
||||
/**
|
||||
* Service loader containing all modules. Initialised by the
|
||||
|
|
@ -80,8 +80,7 @@ public class CcmIntegrator implements Integrator {
|
|||
modules = ServiceLoader.load(CcmModule.class);
|
||||
for (final CcmModule module : modules) {
|
||||
LOGGER.info("Found module class {}...", module.getClass().getName());
|
||||
final ModuleInfo moduleInfo = new ModuleInfo();
|
||||
moduleInfo.load(module);
|
||||
final ModuleInfo moduleInfo = loadModuleInfo(module);
|
||||
LOGGER.info("Found module {}.", moduleInfo.getModuleName());
|
||||
}
|
||||
|
||||
|
|
@ -89,14 +88,14 @@ public class CcmIntegrator implements Integrator {
|
|||
try {
|
||||
//Create dependency tree for the modules
|
||||
final DependencyTreeManager treeManager
|
||||
= new DependencyTreeManager();
|
||||
= new DependencyTreeManager();
|
||||
final List<TreeNode> tree = treeManager.generateTree(modules);
|
||||
final List<TreeNode> orderedNodes = treeManager.orderModules(tree);
|
||||
|
||||
//Get DataSource and Connection from the sessionFactory of
|
||||
//Hibernate.
|
||||
final DataSource dataSource = (DataSource) sessionFactory.
|
||||
getProperties().get("javax.persistence.jtaDataSource");
|
||||
getProperties().get("javax.persistence.jtaDataSource");
|
||||
connection = dataSource.getConnection();
|
||||
|
||||
//Migrate tables and sequences which don't belong to a module
|
||||
|
|
@ -104,7 +103,7 @@ public class CcmIntegrator implements Integrator {
|
|||
final Flyway flyway = new Flyway();
|
||||
flyway.setDataSource(dataSource);
|
||||
final StringBuffer buffer = new StringBuffer(
|
||||
"db/migrations/org/libreccm/base");
|
||||
"db/migrations/org/libreccm/base");
|
||||
appendDbLocation(buffer, connection);
|
||||
flyway.setLocations(buffer.toString());
|
||||
flyway.migrate();
|
||||
|
|
@ -112,7 +111,7 @@ public class CcmIntegrator implements Integrator {
|
|||
//Migrate the modules
|
||||
for (final TreeNode node : orderedNodes) {
|
||||
migrateModule(node.getModule().getClass(), dataSource);
|
||||
|
||||
|
||||
// for (Class<?> entity : node.getModuleInfo().getModuleEntities()) {
|
||||
// configuration.addAnnotatedClass(entity);
|
||||
// }
|
||||
|
|
@ -130,12 +129,27 @@ public class CcmIntegrator implements Integrator {
|
|||
LOGGER.info("All modules integrated successfully.");
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper method for loading the module info for a module.
|
||||
*
|
||||
* @param module The module for which the module is loaded.
|
||||
*
|
||||
* @return The {@link ModuleInfo} object for the module
|
||||
*/
|
||||
private ModuleInfo loadModuleInfo(final CcmModule module) {
|
||||
final ModuleInfo moduleInfo = new ModuleInfo();
|
||||
moduleInfo.load(module);
|
||||
|
||||
return moduleInfo;
|
||||
}
|
||||
|
||||
/**
|
||||
* Private helper method to get the database schema name of a module. The
|
||||
* name is then name of the module in lower case with all hyphens replaced
|
||||
* with underscores.
|
||||
*
|
||||
* @param moduleInfo The module info object for the module
|
||||
*
|
||||
* @return The database schema name of the module.
|
||||
*/
|
||||
private String getSchemaName(final ModuleInfo moduleInfo) {
|
||||
|
|
@ -167,14 +181,16 @@ public class CcmIntegrator implements Integrator {
|
|||
* If the database is not supported an {@link IntegrationException} will be
|
||||
* thrown.
|
||||
*
|
||||
* @param buffer Buffer for the location string.
|
||||
* @param buffer Buffer for the location string.
|
||||
* @param connection The JDBC connection object.
|
||||
* @throws SQLException If an error occurs while accessing the database.
|
||||
*
|
||||
* @throws SQLException If an error occurs while accessing the
|
||||
* database.
|
||||
* @throws IntegrationException If the database is not supported yet.
|
||||
*/
|
||||
private void appendDbLocation(final StringBuffer buffer,
|
||||
final Connection connection)
|
||||
throws SQLException {
|
||||
throws SQLException {
|
||||
|
||||
switch (connection.getMetaData().getDatabaseProductName()) {
|
||||
case "H2":
|
||||
|
|
@ -185,9 +201,9 @@ public class CcmIntegrator implements Integrator {
|
|||
break;
|
||||
default:
|
||||
throw new IntegrationException(String.format(
|
||||
"Integration failed. Database \"%s\" is not supported yet.",
|
||||
connection.getMetaData().
|
||||
getDatabaseProductName()));
|
||||
"Integration failed. Database \"%s\" is not supported yet.",
|
||||
connection.getMetaData().
|
||||
getDatabaseProductName()));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -196,15 +212,17 @@ public class CcmIntegrator implements Integrator {
|
|||
*
|
||||
* @param moduleInfo The module info object of the module.
|
||||
* @param connection The database connection.
|
||||
*
|
||||
* @return The location of the database migrations for a specific module.
|
||||
*
|
||||
* @throws SQLException If an error on the JDBC site occurs.
|
||||
*/
|
||||
private String getLocation(final ModuleInfo moduleInfo,
|
||||
final Connection connection)
|
||||
throws SQLException {
|
||||
throws SQLException {
|
||||
|
||||
final StringBuffer buffer = new StringBuffer(
|
||||
"classpath:/db/migrations/");
|
||||
"classpath:/db/migrations/");
|
||||
buffer.append(moduleInfo.getModuleDataPackage());
|
||||
appendDbLocation(buffer, connection);
|
||||
|
||||
|
|
@ -214,66 +232,68 @@ public class CcmIntegrator implements Integrator {
|
|||
/**
|
||||
* Helper method for executing the migrations for a module.
|
||||
*
|
||||
* @param module The module for which the migrations are executed.
|
||||
* @param module The module for which the migrations are executed.
|
||||
* @param dataSource The JDBC data source for connecting to the database.
|
||||
*
|
||||
* @throws SQLException If an error occurs while applying the migrations.
|
||||
*/
|
||||
private void migrateModule(final Class<? extends CcmModule> module,
|
||||
final DataSource dataSource) throws SQLException {
|
||||
//Get the JDBC connection from the DataSource
|
||||
final Connection connection = dataSource.getConnection();
|
||||
try (final Connection connection = dataSource.getConnection()) {
|
||||
|
||||
//Load the module info for the module
|
||||
final ModuleInfo moduleInfo = new ModuleInfo();
|
||||
moduleInfo.load(module);
|
||||
//Load the module info for the module
|
||||
final ModuleInfo moduleInfo = new ModuleInfo();
|
||||
moduleInfo.load(module);
|
||||
|
||||
//Create a Flyway instance for the the module.
|
||||
final Flyway flyway = new Flyway();
|
||||
flyway.setDataSource(dataSource);
|
||||
//Set schema correctly for the different databases. Necessary because
|
||||
//different RDBMS handle case different.
|
||||
if ("H2".equals(connection.getMetaData().getDatabaseProductName())) {
|
||||
flyway
|
||||
//Create a Flyway instance for the the module.
|
||||
final Flyway flyway = new Flyway();
|
||||
flyway.setDataSource(dataSource);
|
||||
//Set schema correctly for the different databases. Necessary because
|
||||
//different RDBMS handle case different.
|
||||
if ("H2".equals(connection.getMetaData().getDatabaseProductName())) {
|
||||
flyway
|
||||
.setSchemas(getSchemaName(moduleInfo).toUpperCase(
|
||||
Locale.ROOT));
|
||||
} else {
|
||||
flyway.setSchemas(getSchemaName(moduleInfo));
|
||||
}
|
||||
flyway.setLocations(getLocation(moduleInfo, connection));
|
||||
Locale.ROOT));
|
||||
} else {
|
||||
flyway.setSchemas(getSchemaName(moduleInfo));
|
||||
}
|
||||
flyway.setLocations(getLocation(moduleInfo, connection));
|
||||
|
||||
//Get current migrations info
|
||||
final MigrationInfo current = flyway.info().current();
|
||||
boolean newModule;
|
||||
if (current == null) {
|
||||
LOGGER.info("No version, database schema is considered empty.");
|
||||
newModule = true;
|
||||
} else {
|
||||
LOGGER.info("Current version of schema {} in database is {}",
|
||||
//Get current migrations info
|
||||
final MigrationInfo current = flyway.info().current();
|
||||
boolean newModule;
|
||||
if (current == null) {
|
||||
LOGGER.info("No version, database schema is considered empty.");
|
||||
newModule = true;
|
||||
} else {
|
||||
LOGGER.info("Current version of schema {} in database is {}",
|
||||
getSchemaName(moduleInfo),
|
||||
current.getVersion());
|
||||
newModule = false;
|
||||
}
|
||||
|
||||
//Execute migrations. Flyway will check if there any migrations to apply.
|
||||
flyway.migrate();
|
||||
|
||||
LOGGER.info("Migrated schema {} in database to version {}",
|
||||
getSchemaName(moduleInfo),
|
||||
current.getVersion());
|
||||
newModule = false;
|
||||
}
|
||||
flyway.info().current().getVersion());
|
||||
|
||||
//Execute migrations. Flyway will check if there any migrations to apply.
|
||||
flyway.migrate();
|
||||
|
||||
LOGGER.info("Migrated schema {} in database to version {}",
|
||||
getSchemaName(moduleInfo),
|
||||
flyway.info().current().getVersion());
|
||||
|
||||
//If a new module was installed register the module in the
|
||||
//installed_modules table with the new status. The ModuleManager will
|
||||
//call the install method of them module.
|
||||
if (newModule) {
|
||||
try (Statement statement = connection.createStatement()) {
|
||||
statement.execute(String.format(
|
||||
//If a new module was installed register the module in the
|
||||
//installed_modules table with the new status. The ModuleManager will
|
||||
//call the install method of them module.
|
||||
if (newModule) {
|
||||
try (Statement statement = connection.createStatement()) {
|
||||
statement.execute(String.format(
|
||||
"INSERT INTO ccm_core.installed_modules "
|
||||
+ "(module_id, module_class_name, status) "
|
||||
+ "VALUES (%d, '%s', 'NEW')",
|
||||
+ "(module_id, module_class_name, status) "
|
||||
+ "VALUES (%d, '%s', 'NEW')",
|
||||
module.getName().hashCode(),
|
||||
module.getName()));
|
||||
} catch (SQLException ex) {
|
||||
throw new IntegrationException("Failed to integrate.", ex);
|
||||
} catch (SQLException ex) {
|
||||
throw new IntegrationException("Failed to integrate.", ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -303,22 +323,21 @@ public class CcmIntegrator implements Integrator {
|
|||
|
||||
//Get JDBC connection
|
||||
final DataSource dataSource = (DataSource) sessionFactory
|
||||
.getProperties().get("javax.persistence.jtaDataSource");
|
||||
.getProperties().get("javax.persistence.jtaDataSource");
|
||||
connection = dataSource.getConnection();
|
||||
System.out.println("checking modules...");
|
||||
LOGGER.info("Checking modules...");
|
||||
|
||||
for (final CcmModule module : modules) {
|
||||
final ModuleInfo moduleInfo = new ModuleInfo();
|
||||
moduleInfo.load(module);
|
||||
final ModuleInfo moduleInfo = loadModuleInfo(module);
|
||||
|
||||
try (Statement query = connection.createStatement();
|
||||
//Check status of each module
|
||||
ResultSet result = query.executeQuery(
|
||||
String.format("SELECT module_class_name, status "
|
||||
+ "FROM ccm_core.installed_modules "
|
||||
String.format("SELECT module_class_name, status "
|
||||
+ "FROM ccm_core.installed_modules "
|
||||
+ "WHERE module_class_name = '%s'",
|
||||
module.getClass().getName()))) {
|
||||
module.getClass().getName()))) {
|
||||
|
||||
System.out.printf("Checking status of module %s...%n",
|
||||
module.getClass().getName());
|
||||
|
|
@ -326,37 +345,16 @@ public class CcmIntegrator implements Integrator {
|
|||
//If there modules marked for uninstall remove the schema
|
||||
//of the module from the database.
|
||||
if (result.next() && ModuleStatus.UNINSTALL.toString()
|
||||
.equals(result.getString("status"))) {
|
||||
|
||||
LOGGER.info("Removing schema for module %s...",
|
||||
module.getClass().getName());
|
||||
final Flyway flyway = new Flyway();
|
||||
flyway.setDataSource(dataSource);
|
||||
flyway.setSchemas(getSchemaName(moduleInfo));
|
||||
flyway.setLocations(getLocation(moduleInfo, connection));
|
||||
LOGGER.warn("Deleting schema for module {}...",
|
||||
moduleInfo.getModuleName());
|
||||
flyway.clean();
|
||||
|
||||
//Delete the module from the installed modules table.
|
||||
try (final Statement statement = connection
|
||||
.createStatement()) {
|
||||
statement.addBatch(String.format(
|
||||
"DELETE FROM ccm_core.installed_modules "
|
||||
+ "WHERE module_class_name = '%s'",
|
||||
module.getClass().getName()));
|
||||
statement.executeBatch();
|
||||
LOGGER.info("Done.");
|
||||
} catch (SQLException ex) {
|
||||
throw new IntegrationException(
|
||||
"Failed to desintegrate", ex);
|
||||
}
|
||||
.equals(result.getString("status"))) {
|
||||
uninstallModule(connection,
|
||||
dataSource,
|
||||
module,
|
||||
moduleInfo);
|
||||
}
|
||||
|
||||
} catch (SQLException ex) {
|
||||
throw new IntegrationException("Failed to desintegrate.");
|
||||
throw new IntegrationException("Failed to desintegrate.",
|
||||
ex);
|
||||
}
|
||||
|
||||
}
|
||||
} catch (SQLException ex) {
|
||||
LOGGER.error("Desintegration failed: ", ex);
|
||||
|
|
@ -370,11 +368,41 @@ public class CcmIntegrator implements Integrator {
|
|||
next = next.getNextException();
|
||||
}
|
||||
|
||||
throw new IntegrationException("Failed to desintegrate.");
|
||||
throw new IntegrationException("Failed to desintegrate.", ex);
|
||||
|
||||
} finally {
|
||||
JdbcUtils.closeConnection(connection);
|
||||
}
|
||||
}
|
||||
|
||||
private void uninstallModule(final Connection connection,
|
||||
final DataSource dataSource,
|
||||
final CcmModule module,
|
||||
final ModuleInfo moduleInfo)
|
||||
throws SQLException {
|
||||
LOGGER.info("Removing schema for module %s...",
|
||||
module.getClass().getName());
|
||||
final Flyway flyway = new Flyway();
|
||||
flyway.setDataSource(dataSource);
|
||||
flyway.setSchemas(getSchemaName(moduleInfo));
|
||||
flyway.setLocations(getLocation(moduleInfo, connection));
|
||||
LOGGER.warn("Deleting schema for module {}...",
|
||||
moduleInfo.getModuleName());
|
||||
flyway.clean();
|
||||
|
||||
//Delete the module from the installed modules table.
|
||||
try (final Statement statement = connection
|
||||
.createStatement()) {
|
||||
statement.addBatch(String.format(
|
||||
"DELETE FROM ccm_core.installed_modules "
|
||||
+ "WHERE module_class_name = '%s'",
|
||||
module.getClass().getName()));
|
||||
statement.executeBatch();
|
||||
LOGGER.info("Done.");
|
||||
} catch (SQLException ex) {
|
||||
throw new IntegrationException(
|
||||
"Failed to desintegrate", ex);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -20,12 +20,9 @@ package org.libreccm.modules;
|
|||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.sql.Connection;
|
||||
import java.sql.SQLException;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Properties;
|
||||
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
|
|
|
|||
|
|
@ -33,7 +33,7 @@ import org.apache.logging.log4j.Logger;
|
|||
|
||||
/**
|
||||
* The {@code ModuleManager} manages the lifecycle of all modules.
|
||||
*
|
||||
*
|
||||
* Please note: While this class is public it is not part of the public API and
|
||||
* should not be called by other classes.
|
||||
*
|
||||
|
|
@ -43,7 +43,7 @@ import org.apache.logging.log4j.Logger;
|
|||
public class ModuleManager {
|
||||
|
||||
private static final Logger LOGGER = LogManager.getLogger(
|
||||
ModuleManager.class
|
||||
ModuleManager.class
|
||||
);
|
||||
|
||||
/**
|
||||
|
|
@ -65,16 +65,15 @@ public class ModuleManager {
|
|||
*/
|
||||
@PostConstruct
|
||||
public void initDependencyTree() {
|
||||
|
||||
|
||||
//Find all modules using the service loader.
|
||||
LOGGER.info("Finding modules");
|
||||
final ServiceLoader<CcmModule> modules = ServiceLoader.load(
|
||||
CcmModule.class);
|
||||
CcmModule.class);
|
||||
|
||||
LOGGER.info("Creating dependency tree these modules:");
|
||||
for (final CcmModule module : modules) {
|
||||
final ModuleInfo moduleInfo = new ModuleInfo();
|
||||
moduleInfo.load(module);
|
||||
final ModuleInfo moduleInfo = loadModuleInfo(module);
|
||||
LOGGER.info("\t{} {}",
|
||||
moduleInfo.getModuleName(),
|
||||
moduleInfo.getModuleVersion());
|
||||
|
|
@ -99,35 +98,33 @@ public class ModuleManager {
|
|||
LOGGER.info("Initalising modules...");
|
||||
//Initialise all modules in the correct order
|
||||
for (final TreeNode node : moduleNodes) {
|
||||
|
||||
|
||||
//Create an install event instance.
|
||||
final InstallEvent installEvent = new InstallEvent();
|
||||
installEvent.setEntityManager(entityManager);
|
||||
final InstallEvent installEvent = createInstallEvent(entityManager);
|
||||
|
||||
//Check if the module is a new module. If it is a new module
|
||||
//call the install method of the module and set the module status
|
||||
//to installed after the install method has run sucessfully.
|
||||
final InstalledModule installedModule = entityManager.find(
|
||||
InstalledModule.class,
|
||||
node.getModule().getClass().getName().hashCode());
|
||||
InstalledModule.class,
|
||||
node.getModule().getClass().getName().hashCode());
|
||||
if (installedModule != null
|
||||
&& installedModule.getStatus() == ModuleStatus.NEW) {
|
||||
&& installedModule.getStatus() == ModuleStatus.NEW) {
|
||||
node.getModule().install(installEvent);
|
||||
installedModule.setStatus(ModuleStatus.INSTALLED);
|
||||
entityManager.merge(installedModule);
|
||||
}
|
||||
|
||||
//Create an init event instance and call the init method.
|
||||
final InitEvent initEvent = new InitEvent();
|
||||
initEvent.setEntityManager(entityManager);
|
||||
final InitEvent initEvent = createInitEvent(entityManager);
|
||||
node.getModule().init(initEvent);
|
||||
|
||||
LOGGER.info("Data from module-info.properties for {}:",
|
||||
node.getModule().getClass().getName());
|
||||
final Properties moduleInfo = getModuleInfo(node.getModule());
|
||||
LOGGER
|
||||
.info("Module group id: {}", moduleInfo.getProperty(
|
||||
"groupId"));
|
||||
.info("Module group id: {}", moduleInfo.getProperty(
|
||||
"groupId"));
|
||||
LOGGER.info("Module artifact id: {}", moduleInfo.getProperty(
|
||||
"artifactId"));
|
||||
LOGGER.info("Module version: {}", moduleInfo.getProperty("version"));
|
||||
|
|
@ -139,19 +136,20 @@ public class ModuleManager {
|
|||
|
||||
/**
|
||||
* Helper method for retrieving the module info for a module.
|
||||
*
|
||||
*
|
||||
* @param module
|
||||
* @return
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
private Properties getModuleInfo(final CcmModule module) {
|
||||
final Properties moduleInfo = new Properties();
|
||||
|
||||
final String moduleInfoPath = String.format(
|
||||
"/module-info/%s.properties",
|
||||
module.getClass().getName());
|
||||
"/module-info/%s.properties",
|
||||
module.getClass().getName());
|
||||
LOGGER.info("Path for module info: {}", moduleInfoPath);
|
||||
try (final InputStream stream = module.getClass().getResourceAsStream(
|
||||
moduleInfoPath)) {
|
||||
moduleInfoPath)) {
|
||||
if (stream == null) {
|
||||
LOGGER.warn("No module info found.");
|
||||
} else {
|
||||
|
|
@ -167,7 +165,7 @@ public class ModuleManager {
|
|||
|
||||
/**
|
||||
* Called to shutdown all modules.
|
||||
*
|
||||
*
|
||||
*/
|
||||
@Transactional(Transactional.TxType.REQUIRED)
|
||||
public void shutdownModules() {
|
||||
|
|
@ -176,8 +174,8 @@ public class ModuleManager {
|
|||
for (final TreeNode node : moduleNodes) {
|
||||
//Create a shutdown event instance and call the shutdown method of
|
||||
//the module.
|
||||
final ShutdownEvent shutdownEvent = new ShutdownEvent();
|
||||
shutdownEvent.setEntityManager(entityManager);
|
||||
final ShutdownEvent shutdownEvent = createShutdownEvent(
|
||||
entityManager);
|
||||
node.getModule().shutdown(shutdownEvent);
|
||||
}
|
||||
|
||||
|
|
@ -189,8 +187,8 @@ public class ModuleManager {
|
|||
System.out.printf("Checking status of module %s%n",
|
||||
node.getModule().getClass().getName());
|
||||
final InstalledModule installedModule = entityManager.find(
|
||||
InstalledModule.class, node.
|
||||
getModule().getClass().getName().hashCode());
|
||||
InstalledModule.class, node.
|
||||
getModule().getClass().getName().hashCode());
|
||||
LOGGER.info("Status of module {} ({}): {}",
|
||||
node.getModuleInfo().getModuleName(),
|
||||
node.getModule().getClass().getName(),
|
||||
|
|
@ -211,10 +209,10 @@ public class ModuleManager {
|
|||
node.getModuleInfo().getModuleName());
|
||||
if (node.getDependentModules().isEmpty()) {
|
||||
System.out.
|
||||
printf("Calling uninstall method of module %s...%n",
|
||||
node.getModuleInfo().getModuleName());
|
||||
final UnInstallEvent unInstallEvent = new UnInstallEvent();
|
||||
unInstallEvent.setEntityManager(entityManager);
|
||||
printf("Calling uninstall method of module %s...%n",
|
||||
node.getModuleInfo().getModuleName());
|
||||
final UnInstallEvent unInstallEvent = createUnInstallEvent(
|
||||
entityManager);
|
||||
node.getModule().uninstall(null);
|
||||
|
||||
} else {
|
||||
|
|
@ -222,8 +220,8 @@ public class ModuleManager {
|
|||
//uninstall reset the status of the module to installed.
|
||||
//Normally this should never happen but just in case...
|
||||
System.out.printf("There are other modules depending on "
|
||||
+ "module %s. Module can't be "
|
||||
+ "uninstalled. Depending modules:%n",
|
||||
+ "module %s. Module can't be "
|
||||
+ "uninstalled. Depending modules:%n",
|
||||
node.getModuleInfo().getModuleName());
|
||||
for (final TreeNode dependent : node.getDependentModules()) {
|
||||
System.out.printf("\t%s%n",
|
||||
|
|
@ -235,10 +233,49 @@ public class ModuleManager {
|
|||
}
|
||||
} else {
|
||||
System.out.printf(
|
||||
"Module %s is *not* scheduled for uninstall.%n",
|
||||
node.getModuleInfo().getModuleName());
|
||||
"Module %s is *not* scheduled for uninstall.%n",
|
||||
node.getModuleInfo().getModuleName());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private ModuleInfo loadModuleInfo(final CcmModule module) {
|
||||
final ModuleInfo moduleInfo = new ModuleInfo();
|
||||
moduleInfo.load(module);
|
||||
|
||||
return moduleInfo;
|
||||
}
|
||||
|
||||
private InstallEvent createInstallEvent(final EntityManager entityManager) {
|
||||
final InstallEvent installEvent = new InstallEvent();
|
||||
installEvent.setEntityManager(entityManager);
|
||||
|
||||
return installEvent;
|
||||
}
|
||||
|
||||
private InitEvent createInitEvent(final EntityManager entityManager) {
|
||||
final InitEvent initEvent = new InitEvent();
|
||||
initEvent.setEntityManager(entityManager);
|
||||
|
||||
return initEvent;
|
||||
}
|
||||
|
||||
private ShutdownEvent createShutdownEvent(
|
||||
final EntityManager entityManager) {
|
||||
|
||||
final ShutdownEvent shutdownEvent = new ShutdownEvent();
|
||||
shutdownEvent.setEntityManager(entityManager);
|
||||
|
||||
return shutdownEvent;
|
||||
}
|
||||
|
||||
private UnInstallEvent createUnInstallEvent(
|
||||
final EntityManager entityManager) {
|
||||
|
||||
final UnInstallEvent unInstallEvent = new UnInstallEvent();
|
||||
unInstallEvent.setEntityManager(entityManager);
|
||||
|
||||
return unInstallEvent;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -56,7 +56,7 @@ import javax.xml.bind.annotation.XmlRootElement;
|
|||
+ "WHERE r.name = :name")
|
||||
})
|
||||
@XmlRootElement(name = "role", namespace = CORE_XML_NS)
|
||||
@SuppressWarnings({"PMD.ShortClassName"})
|
||||
@SuppressWarnings({"PMD.ShortClassName", "PMD.TooManyMethods"})
|
||||
public class Role implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = -7121296514181469687L;
|
||||
|
|
@ -156,7 +156,7 @@ public class Role implements Serializable {
|
|||
permissions.remove(permission);
|
||||
}
|
||||
|
||||
public List<TaskAssignment> assignedTasks() {
|
||||
public List<TaskAssignment> getAssignedTasks() {
|
||||
if (assignedTasks == null) {
|
||||
return null;
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -39,8 +39,9 @@ public class SystemUsersSetup {
|
|||
|
||||
private static final Logger LOGGER = LogManager.getLogger(
|
||||
SystemUsersSetup.class);
|
||||
|
||||
private static final String DEFAULT_ADMIN_PW = "$shiro1$SHA-512$500000$MFPkVikNoRrBZ8R8CxQIHA==$UvgO2K+poSRGw5co63P3ygpWsX7H9N0TgqdrZPBqdXv6Q+/OCL/qOocVbg65/Yjv5hyri6A3zhw7K8mEgpISoA==";
|
||||
|
||||
private static final String DEFAULT_ADMIN_PW
|
||||
= "$shiro1$SHA-512$500000$MFPkVikNoRrBZ8R8CxQIHA==$UvgO2K+poSRGw5co63P3ygpWsX7H9N0TgqdrZPBqdXv6Q+/OCL/qOocVbg65/Yjv5hyri6A3zhw7K8mEgpISoA==";
|
||||
|
||||
private final EntityManager entityManager;
|
||||
|
||||
|
|
@ -65,24 +66,31 @@ public class SystemUsersSetup {
|
|||
admin.setPrimaryEmailAddress(adminEmail);
|
||||
|
||||
String adminPassword = DEFAULT_ADMIN_PW;
|
||||
final InputStream inputStream = getClass().getResourceAsStream(
|
||||
"/integration.properties");
|
||||
if (inputStream == null) {
|
||||
LOGGER.warn("No integration.properties file found. Using default "
|
||||
+ "password (see documentation)");
|
||||
} else {
|
||||
final Properties properties = new Properties();
|
||||
try {
|
||||
properties.load(inputStream);
|
||||
final String password = properties.getProperty("admin.password");
|
||||
if((password != null) && !password.isEmpty()) {
|
||||
adminPassword = password;
|
||||
try (final InputStream inputStream = getClass().getResourceAsStream(
|
||||
"/integration.properties")) {
|
||||
if (inputStream == null) {
|
||||
LOGGER.warn(
|
||||
"No integration.properties file found. Using default "
|
||||
+ "password (see documentation)");
|
||||
} else {
|
||||
final Properties properties = new Properties();
|
||||
try {
|
||||
properties.load(inputStream);
|
||||
final String password = properties.getProperty(
|
||||
"admin.password");
|
||||
if (password != null && !password.isEmpty()) {
|
||||
adminPassword = password;
|
||||
}
|
||||
} catch (IOException ex) {
|
||||
LOGGER.warn("Failed to load integration.properties. "
|
||||
+ "Using default password.",
|
||||
ex);
|
||||
}
|
||||
} catch (IOException ex) {
|
||||
LOGGER.warn("Failed to load integration.properties. "
|
||||
+ "Using default password.",
|
||||
ex);
|
||||
}
|
||||
} catch (IOException ex) {
|
||||
LOGGER.warn("Exception while reading integration.properties file."
|
||||
+ "Using default password for admin account. ",
|
||||
ex);
|
||||
}
|
||||
admin.setPassword(adminPassword);
|
||||
|
||||
|
|
@ -92,7 +100,7 @@ public class SystemUsersSetup {
|
|||
final RoleMembership membership = new RoleMembership();
|
||||
membership.setRole(adminRole);
|
||||
membership.setMember(admin);
|
||||
|
||||
|
||||
final Permission adminPermission = new Permission();
|
||||
adminPermission.setGrantee(adminRole);
|
||||
adminPermission.setGrantedPrivilege("*");
|
||||
|
|
@ -105,7 +113,7 @@ public class SystemUsersSetup {
|
|||
entityManager.persist(membership);
|
||||
entityManager.persist(adminPermission);
|
||||
}
|
||||
|
||||
|
||||
private void createPublicUser() {
|
||||
final User user = new User();
|
||||
user.setName("public-user");
|
||||
|
|
|
|||
|
|
@ -20,8 +20,6 @@ package org.libreccm.workflow;
|
|||
|
||||
import static org.libreccm.core.CoreConstants.*;
|
||||
|
||||
import org.libreccm.security.Group;
|
||||
import org.libreccm.security.Role;
|
||||
import org.libreccm.security.User;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
|
@ -34,8 +32,6 @@ import java.util.Objects;
|
|||
import javax.persistence.Column;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.JoinColumn;
|
||||
import javax.persistence.JoinTable;
|
||||
import javax.persistence.ManyToMany;
|
||||
import javax.persistence.OneToMany;
|
||||
import javax.persistence.OneToOne;
|
||||
import javax.persistence.Table;
|
||||
|
|
|
|||
|
|
@ -26,7 +26,6 @@ import org.junit.runners.Parameterized;
|
|||
import org.libreccm.tests.categories.UnitTest;
|
||||
import org.libreccm.web.CcmApplication;
|
||||
|
||||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
|
|
|
|||
|
|
@ -43,8 +43,8 @@ public class ToStringTest extends ToStringVerifier {
|
|||
DomainOwnership.class});
|
||||
}
|
||||
|
||||
public ToStringTest(final Class<?> entitiesClass) {
|
||||
super(entitiesClass);
|
||||
public ToStringTest(final Class<?> entityClass) {
|
||||
super(entityClass);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,55 @@
|
|||
/*
|
||||
* Copyright (C) 2015 LibreCCM Foundation.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||||
* MA 02110-1301 USA
|
||||
*/
|
||||
package org.libreccm.configuration;
|
||||
|
||||
import org.junit.experimental.categories.Category;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.Parameterized;
|
||||
import org.libreccm.tests.categories.UnitTest;
|
||||
import org.libreccm.testutils.EqualsVerifier;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
||||
*/
|
||||
@RunWith(Parameterized.class)
|
||||
@Category(UnitTest.class)
|
||||
public class EqualsAndHashCodeTest extends EqualsVerifier {
|
||||
|
||||
@Parameterized.Parameters(name = "{0}")
|
||||
public static Collection<Class<?>> data() {
|
||||
return Arrays.asList(new Class<?>[]{
|
||||
BigDecimalConfigurationEntry.class,
|
||||
BooleanConfigurationEntry.class,
|
||||
DoubleConfigurationEntry.class,
|
||||
EnumConfigurationEntry.class,
|
||||
LocalizedStringConfigurationEntry.class,
|
||||
LongConfigurationEntry.class,
|
||||
StringConfigurationEntry.class
|
||||
});
|
||||
}
|
||||
|
||||
public EqualsAndHashCodeTest(final Class<?> entityClass) {
|
||||
super(entityClass);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,55 @@
|
|||
/*
|
||||
* Copyright (C) 2015 LibreCCM Foundation.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||||
* MA 02110-1301 USA
|
||||
*/
|
||||
package org.libreccm.configuration;
|
||||
|
||||
import org.junit.experimental.categories.Category;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.Parameterized;
|
||||
import org.libreccm.tests.categories.UnitTest;
|
||||
import org.libreccm.testutils.ToStringVerifier;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
||||
*/
|
||||
@RunWith(Parameterized.class)
|
||||
@Category(UnitTest.class)
|
||||
public class ToStringTest extends ToStringVerifier {
|
||||
|
||||
@Parameterized.Parameters(name = "{0}")
|
||||
public static Collection<Class<?>> data() {
|
||||
return Arrays.asList(new Class<?>[]{
|
||||
BigDecimalConfigurationEntry.class,
|
||||
BooleanConfigurationEntry.class,
|
||||
DoubleConfigurationEntry.class,
|
||||
EnumConfigurationEntry.class,
|
||||
LocalizedStringConfigurationEntry.class,
|
||||
LongConfigurationEntry.class,
|
||||
StringConfigurationEntry.class
|
||||
});
|
||||
}
|
||||
|
||||
public ToStringTest(final Class<?> entityClass) {
|
||||
super(entityClass);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -79,10 +79,9 @@ public class ToStringVerifier {
|
|||
InvocationTargetException {
|
||||
final Object obj;
|
||||
try {
|
||||
final Constructor<?> constructor = entityClass
|
||||
.getDeclaredConstructor();
|
||||
final Constructor<?> constructor = entityClass.asSubclass(
|
||||
entityClass).getDeclaredConstructor();
|
||||
constructor.setAccessible(true);
|
||||
|
||||
obj = constructor.newInstance();
|
||||
} catch (NoSuchMethodException ex) {
|
||||
final StringWriter stringWriter = new StringWriter();
|
||||
|
|
|
|||
Loading…
Reference in New Issue