Skip to content

Commit

Permalink
la-team#164 Demo not work due Customer.java @FileReference(baseDirec…
Browse files Browse the repository at this point in the history
…tory = "/Users/max/Desktop/lightadmin-demo")
  • Loading branch information
max-dev committed Nov 11, 2014
1 parent 2dbbe10 commit 1dd2d96
Show file tree
Hide file tree
Showing 10 changed files with 105 additions and 159 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import org.lightadmin.core.config.domain.unit.processor.EmptyConfigurationUnitPostProcessor;
import org.lightadmin.core.config.domain.unit.processor.HierarchicalConfigurationPostProcessor;
import org.lightadmin.core.config.domain.unit.processor.VisitableConfigurationUnitPostProcessor;
import org.lightadmin.core.reporting.DefaultProblemReporter;
import org.lightadmin.core.reporting.ProblemReporter;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.InitializingBean;
Expand All @@ -43,11 +44,12 @@
import static com.google.common.collect.Sets.newLinkedHashSet;
import static java.lang.String.format;
import static org.apache.commons.lang3.ArrayUtils.toArray;
import static org.lightadmin.core.reporting.ProblemReporterFactory.failFastReporter;

@SuppressWarnings("unused")
public class GlobalAdministrationConfigurationFactoryBean extends AbstractFactoryBean<GlobalAdministrationConfiguration> implements InitializingBean {

private ProblemReporter problemReporter = DefaultProblemReporter.INSTANCE;

private DomainTypeAdministrationConfigurationFactory domainTypeAdministrationConfigurationFactory;

private Set<ConfigurationUnits> domainTypeConfigurationUnits;
Expand Down Expand Up @@ -91,11 +93,9 @@ public Class<?> getObjectType() {
protected GlobalAdministrationConfiguration createInstance() throws Exception {
GlobalAdministrationConfiguration globalAdministrationConfiguration = new GlobalAdministrationConfiguration();

ProblemReporter problemReporter = failFastReporter();

for (ConfigurationUnits configurationUnits : domainTypeConfigurationUnits) {
if (nonPersistentEntityType(configurationUnits.getDomainType())) {
problemReporter.error(new DomainConfigurationProblem(configurationUnits, format("Administration of non-persistent type %s is not supported.", configurationUnits.getDomainType().getSimpleName())));
problemReporter.handle(new DomainConfigurationProblem(configurationUnits, format("Administration of non-persistent type %s is not supported.", configurationUnits.getDomainType().getSimpleName())));
continue;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,24 @@ public class DomainConfigurationProblem extends Problem {

private final ConfigurationUnits configurationUnits;

private DomainConfigurationUnitType configurationUnitType;
private final DomainConfigurationUnitType configurationUnitType;

public DomainConfigurationProblem(final ConfigurationUnits configurationUnits, final String message) {
super(message);
public DomainConfigurationProblem(final ConfigurationUnits configurationUnits, DomainConfigurationUnitType configurationUnitType, final String message, ProblemLevel problemLevel) {
super(message, problemLevel);
this.configurationUnits = configurationUnits;
this.configurationUnitType = configurationUnitType;
}

public DomainConfigurationProblem(final ConfigurationUnits configurationUnits, DomainConfigurationUnitType configurationUnitType, final String message) {
this(configurationUnits, message);
this.configurationUnitType = configurationUnitType;
this(configurationUnits, configurationUnitType, message, ProblemLevel.ERROR);
}

public DomainConfigurationProblem(final ConfigurationUnits configurationUnits, final String message, ProblemLevel problemLevel) {
this(configurationUnits, null, message, problemLevel);
}

public DomainConfigurationProblem(final ConfigurationUnits configurationUnits, final String message) {
this(configurationUnits, message, ProblemLevel.ERROR);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,27 +23,27 @@
@SuppressWarnings("unused")
public class InvalidPropertyConfigurationProblem extends DomainConfigurationProblem {

private InvalidPropertyConfigurationProblem(final ConfigurationUnits configurationUnits, DomainConfigurationUnitType configurationUnitType, String message) {
super(configurationUnits, configurationUnitType, message);
private InvalidPropertyConfigurationProblem(final ConfigurationUnits configurationUnits, DomainConfigurationUnitType configurationUnitType, String message, ProblemLevel problemLevel) {
super(configurationUnits, configurationUnitType, message, problemLevel);
}

public static InvalidPropertyConfigurationProblem missingFieldProblem(final ConfigurationUnits configurationUnits, DomainConfigurationUnitType configurationUnitType, String propertyName) {
return new InvalidPropertyConfigurationProblem(configurationUnits, configurationUnitType, format("Missing property '%s' defined!", propertyName));
return new InvalidPropertyConfigurationProblem(configurationUnits, configurationUnitType, format("Missing property '%s' defined!", propertyName), ProblemLevel.ERROR);
}

public static InvalidPropertyConfigurationProblem rendererNotDefinedForFieldProblem(final ConfigurationUnits configurationUnits, DomainConfigurationUnitType configurationUnitType, String propertyName) {
return new InvalidPropertyConfigurationProblem(configurationUnits, configurationUnitType, format("Renderer not defined for custom property '%s'!", propertyName));
return new InvalidPropertyConfigurationProblem(configurationUnits, configurationUnitType, format("Renderer not defined for custom property '%s'!", propertyName), ProblemLevel.ERROR);
}

public static InvalidPropertyConfigurationProblem notSupportedTypeFieldProblem(final ConfigurationUnits configurationUnits, DomainConfigurationUnitType configurationUnitType, String propertyName) {
return new InvalidPropertyConfigurationProblem(configurationUnits, configurationUnitType, format("Persistent property '%s' has not supported type!", propertyName));
return new InvalidPropertyConfigurationProblem(configurationUnits, configurationUnitType, format("Persistent property '%s' has not supported type!", propertyName), ProblemLevel.ERROR);
}

public static InvalidPropertyConfigurationProblem missingBaseDirectoryInFileReferenceProblem(final ConfigurationUnits configurationUnits, DomainConfigurationUnitType configurationUnitType, String propertyName) {
return new InvalidPropertyConfigurationProblem(configurationUnits, configurationUnitType, format("@FileReference property '%s' has incorrect baseDirectory defined!", propertyName));
return new InvalidPropertyConfigurationProblem(configurationUnits, configurationUnitType, format("@FileReference property '%s' has incorrect baseDirectory defined!", propertyName), ProblemLevel.WARNING);
}

public static InvalidPropertyConfigurationProblem invalidPropertyValueExpressionProblem(final ConfigurationUnits configurationUnits, DomainConfigurationUnitType configurationUnitType, String propertyName) {
return new InvalidPropertyConfigurationProblem(configurationUnits, configurationUnitType, format("Property '%s' has invalid path/expression defined!", propertyName));
return new InvalidPropertyConfigurationProblem(configurationUnits, configurationUnitType, format("Property '%s' has invalid path/expression defined!", propertyName), ProblemLevel.ERROR);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,11 @@ void validateDomainType(final ConfigurationUnits configurationUnits, final Probl
final Class<?> domainType = configurationUnits.getDomainType();

if (notPersistentEntityType(domainType)) {
problemReporter.error(new DomainConfigurationProblem(configurationUnits, format("Non-persistent type %s is not supported.", domainType.getSimpleName())));
problemReporter.handle(new DomainConfigurationProblem(configurationUnits, format("Non-persistent type %s is not supported.", domainType.getSimpleName())));
}

if (!hasConstructor(domainType)) {
problemReporter.error(new DomainConfigurationProblem(configurationUnits, format("Type %s must have default constructor.", domainType.getSimpleName())));
problemReporter.handle(new DomainConfigurationProblem(configurationUnits, format("Type %s must have default constructor.", domainType.getSimpleName())));
}
}

Expand All @@ -97,7 +97,7 @@ void validateSidebars(ConfigurationUnits configurationUnits, ProblemReporter pro
for (SidebarMetadata sidebar : sidebars) {
final String jspFilePath = sidebar.getJspFilePath();
if (!resourceLoader.getResource(jspFilePath).exists()) {
problemReporter.error(new DomainConfigurationProblem(configurationUnits, SIDEBARS, "Wrong jsp file path defined for sidebar " + jspFilePath));
problemReporter.handle(new DomainConfigurationProblem(configurationUnits, SIDEBARS, "Wrong jsp file path defined for sidebar " + jspFilePath));
}
}
}
Expand All @@ -119,14 +119,14 @@ void validateScopes(final ConfigurationUnits configurationUnits, final ProblemRe
void validateSpecificationScope(final ScopeMetadata scope, final ConfigurationUnits configurationUnits, final ProblemReporter problemReporter) {
SpecificationScopeMetadata specificationScopeMetadata = (SpecificationScopeMetadata) scope;
if (specificationScopeMetadata.specification() == null) {
problemReporter.error(new DomainConfigurationProblem(configurationUnits, SCOPES, "Filtering specification not defined for scope " + scope.getName()));
problemReporter.handle(new DomainConfigurationProblem(configurationUnits, SCOPES, "Filtering specification not defined for scope " + scope.getName()));
}
}

void validatePredicateScope(final ScopeMetadata scope, final ConfigurationUnits configurationUnits, final ProblemReporter problemReporter) {
PredicateScopeMetadata predicateScopeMetadata = (PredicateScopeMetadata) scope;
if (predicateScopeMetadata.predicate() == null) {
problemReporter.error(new DomainConfigurationProblem(configurationUnits, SCOPES, "Filtering predicate not defined for scope " + scope.getName()));
problemReporter.handle(new DomainConfigurationProblem(configurationUnits, SCOPES, "Filtering predicate not defined for scope " + scope.getName()));
}
}

Expand Down Expand Up @@ -164,7 +164,7 @@ private void validateFields(Set<FieldMetadata> fields, ConfigurationUnits config
for (FieldMetadata field : fields) {
final Collection<? extends DomainConfigurationProblem> problems = fieldMetadataValidator.validateFieldMetadata(field, configurationUnits.getDomainType(), newDomainConfigurationValidationContext(configurationUnits, configurationUnitType));
if (!problems.isEmpty()) {
problemReporter.errors(problems);
problemReporter.handle(problems);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/*
* Copyright 2012-2014 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.lightadmin.core.reporting;

import com.google.common.base.Predicate;
import com.google.common.collect.Collections2;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.Collection;

import static com.google.common.collect.Lists.newArrayList;
import static org.lightadmin.core.reporting.Problem.ProblemLevel.ERROR;
import static org.lightadmin.core.reporting.Problem.ProblemLevel.WARNING;

public class DefaultProblemReporter implements ProblemReporter {

public static final ProblemReporter INSTANCE = new DefaultProblemReporter();

private final Logger logger = LoggerFactory.getLogger(getClass());

private DefaultProblemReporter() {
}

@Override
public void handle(final Problem problem) {
handle(newArrayList(problem));
}

@Override
public void handle(Collection<? extends Problem> problems) {
for (Problem warning : select(problems, WARNING)) {
logger.warn(warning.getMessage());
}

Collection<? extends Problem> errors = select(problems, ERROR);
if (!errors.isEmpty()) {
throw new ConfigurationProblemException(errors);
}
}

private Collection<? extends Problem> select(Collection<? extends Problem> problems, final Problem.ProblemLevel problemLevel) {
return Collections2.filter(problems, new Predicate<Problem>() {
@Override
public boolean apply(Problem problem) {
return problem.getProblemLevel() == problemLevel;
}
});
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -19,29 +19,29 @@

public class Problem {

private final String message;
public enum ProblemLevel {
ERROR, WARNING
}

private final Throwable rootCause;
private final String message;

public Problem(final String message) {
this(message, null);
}
private ProblemLevel problemLevel = ProblemLevel.ERROR;

public Problem(final String message, final Throwable rootCause) {
public Problem(String message, ProblemLevel problemLevel) {
this.message = message;
this.rootCause = rootCause;
this.problemLevel = problemLevel;
}

public String getMessage() {
return message;
}

public Throwable getRootCause() {
return rootCause;
public ProblemLevel getProblemLevel() {
return problemLevel;
}

@Override
public String toString() {
return new ToStringBuilder(this).append("message", message).append("rootCause", rootCause).toString();
return new ToStringBuilder(this).append("message", message).append("problemLevel", problemLevel).toString();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,7 @@

public interface ProblemReporter {

void fatal(Problem problem);
void handle(Problem problem);

void error(Problem problem);

void errors(Collection<? extends Problem> problems);

void warning(Problem problem);
void handle(Collection<? extends Problem> problems);
}

This file was deleted.

This file was deleted.

0 comments on commit 1dd2d96

Please sign in to comment.