index int64 0 0 | repo_id stringlengths 9 205 | file_path stringlengths 31 246 | content stringlengths 1 12.2M | __index_level_0__ int64 0 10k |
|---|---|---|---|---|
0 | Create_ds/commons-ognl/src/main/java/org/apache/commons/ognl/internal | Create_ds/commons-ognl/src/main/java/org/apache/commons/ognl/internal/entry/DeclaredMethodCacheEntry.java | package org.apache.commons.ognl.internal.entry;
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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.
*/
/*
*/
public class DeclaredMethodCacheEntry
extends MethodCacheEntry
{
MethodType type;
public enum MethodType
{
STATIC, NON_STATIC
}
public DeclaredMethodCacheEntry( Class<?> targetClass )
{
super( targetClass );
}
public DeclaredMethodCacheEntry( Class<?> targetClass, MethodType type )
{
super( targetClass );
this.type = type;
}
@Override
public boolean equals(Object o) {
if (this == o)
{
return true;
}
if (!(o instanceof DeclaredMethodCacheEntry))
{
return false;
}
if (!super.equals(o))
{
return false;
}
DeclaredMethodCacheEntry that = (DeclaredMethodCacheEntry) o;
return type == that.type;
}
@Override
public int hashCode()
{
int result = super.hashCode();
result = 31 * result + ( type != null ? type.hashCode() : 0 );
return result;
}
}
| 4,700 |
0 | Create_ds/commons-ognl/src/main/java/org/apache/commons/ognl/internal | Create_ds/commons-ognl/src/main/java/org/apache/commons/ognl/internal/entry/GenericMethodParameterTypeFactory.java | package org.apache.commons.ognl.internal.entry;
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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.
*/
/*
*/
import org.apache.commons.ognl.internal.CacheException;
import java.lang.reflect.Array;
import java.lang.reflect.GenericArrayType;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
import java.lang.reflect.TypeVariable;
public class GenericMethodParameterTypeFactory
implements CacheEntryFactory<GenericMethodParameterTypeCacheEntry, Class<?>[]>
{
public Class<?>[] create( GenericMethodParameterTypeCacheEntry entry )
throws CacheException
{
Class<?>[] types;
ParameterizedType param = (ParameterizedType) entry.type.getGenericSuperclass();
Type[] genTypes = entry.method.getGenericParameterTypes();
TypeVariable<?>[] declaredTypes = entry.method.getDeclaringClass().getTypeParameters();
types = new Class[genTypes.length];
for ( int i = 0; i < genTypes.length; i++ )
{
TypeVariable<?> paramType = null;
if (genTypes[i] instanceof TypeVariable)
{
paramType = (TypeVariable<?>) genTypes[i];
}
else if (genTypes[i] instanceof GenericArrayType)
{
paramType = (TypeVariable<?>) ( (GenericArrayType) genTypes[i] ).getGenericComponentType();
}
else if (genTypes[i] instanceof ParameterizedType)
{
types[i] = (Class<?>) ( (ParameterizedType) genTypes[i] ).getRawType();
continue;
}
else if (genTypes[i] instanceof Class)
{
types[i] = (Class<?>) genTypes[i];
continue;
}
Class<?> resolved = resolveType( param, paramType, declaredTypes );
if ( resolved != null )
{
if (genTypes[i] instanceof GenericArrayType)
{
resolved = Array.newInstance( resolved, 0 ).getClass();
}
types[i] = resolved;
continue;
}
types[i] = entry.method.getParameterTypes()[i];
}
return types;
}
private Class<?> resolveType( ParameterizedType param, TypeVariable<?> var, TypeVariable<?>[] declaredTypes )
{
if ( param.getActualTypeArguments().length < 1 )
{
return null;
}
for ( int i = 0; i < declaredTypes.length; i++ )
{
if ( !(param.getActualTypeArguments()[i] instanceof TypeVariable)
&& declaredTypes[i].getName().equals( var.getName() ) )
{
return (Class<?>) param.getActualTypeArguments()[i];
}
}
return null;
}
}
| 4,701 |
0 | Create_ds/commons-ognl/src/main/java/org/apache/commons/ognl/internal | Create_ds/commons-ognl/src/main/java/org/apache/commons/ognl/internal/entry/MethodAccessCacheEntryFactory.java | package org.apache.commons.ognl.internal.entry;
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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.
*/
/*
*/
import org.apache.commons.ognl.internal.CacheException;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
public class MethodAccessCacheEntryFactory
implements CacheEntryFactory<Method, MethodAccessEntryValue>
{
public static final MethodAccessEntryValue INACCESSIBLE_NON_PUBLIC_METHOD =
new MethodAccessEntryValue( false, true );
public static final MethodAccessEntryValue ACCESSIBLE_NON_PUBLIC_METHOD = new MethodAccessEntryValue( true, true );
public static final MethodAccessEntryValue PUBLIC_METHOD = new MethodAccessEntryValue( true );
public MethodAccessEntryValue create( Method method )
throws CacheException
{
final boolean notPublic = !Modifier.isPublic( method.getModifiers() ) || !Modifier.isPublic(
method.getDeclaringClass().getModifiers() );
if ( !notPublic ) {
return PUBLIC_METHOD;
}
if ( !method.isAccessible() )
{
return INACCESSIBLE_NON_PUBLIC_METHOD;
}
return ACCESSIBLE_NON_PUBLIC_METHOD;
}
}
| 4,702 |
0 | Create_ds/commons-ognl/src/main/java/org/apache/commons/ognl/internal | Create_ds/commons-ognl/src/main/java/org/apache/commons/ognl/internal/entry/CacheEntry.java | package org.apache.commons.ognl.internal.entry;
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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.
*/
/*
*/
public interface CacheEntry
{
}
| 4,703 |
0 | Create_ds/commons-ognl/src/main/java/org/apache/commons/ognl/internal | Create_ds/commons-ognl/src/main/java/org/apache/commons/ognl/internal/entry/GenericMethodParameterTypeCacheEntry.java | package org.apache.commons.ognl.internal.entry;
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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.
*/
/*
*/
import java.lang.reflect.Method;
public class GenericMethodParameterTypeCacheEntry
implements CacheEntry
{
final Method method;
final Class<?> type;
public GenericMethodParameterTypeCacheEntry( Method method, Class<?> type )
{
this.method = method;
this.type = type;
}
@Override
public boolean equals( Object o )
{
if ( this == o )
{
return true;
}
if ( !( o instanceof GenericMethodParameterTypeCacheEntry ) )
{
return false;
}
GenericMethodParameterTypeCacheEntry that = (GenericMethodParameterTypeCacheEntry) o;
return method.equals( that.method ) && type.equals( that.type );
}
@Override
public int hashCode()
{
int result = method.hashCode();
result = 31 * result + type.hashCode();
return result;
}
}
| 4,704 |
0 | Create_ds/commons-ognl/src/main/java/org/apache/commons/ognl/internal | Create_ds/commons-ognl/src/main/java/org/apache/commons/ognl/internal/entry/FieldCacheEntryFactory.java | package org.apache.commons.ognl.internal.entry;
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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.
*/
/*
* $Id: FiedlCacheEntryFactory.java 1194954 2011-10-29 18:00:27Z mcucchiara $
*/
import org.apache.commons.ognl.internal.CacheException;
import java.lang.reflect.Field;
import java.util.HashMap;
import java.util.Map;
public class FieldCacheEntryFactory
implements ClassCacheEntryFactory<Map<String, Field>>
{
public Map<String, Field> create( Class<?> key )
throws CacheException
{
Field[] declaredFields = key.getDeclaredFields();
Map<String, Field> result = new HashMap<String, Field>( declaredFields.length );
for ( Field field : declaredFields )
{
result.put( field.getName(), field );
}
return result;
}
}
| 4,705 |
0 | Create_ds/commons-ognl/src/main/java/org/apache/commons/ognl/internal | Create_ds/commons-ognl/src/main/java/org/apache/commons/ognl/internal/entry/CacheEntryFactory.java | package org.apache.commons.ognl.internal.entry;
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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.
*/
/*
*/
import org.apache.commons.ognl.internal.CacheException;
public interface CacheEntryFactory<K, V>
{
V create( K key )
throws CacheException;
}
| 4,706 |
0 | Create_ds/commons-ognl/src/main/java/org/apache/commons/ognl/internal | Create_ds/commons-ognl/src/main/java/org/apache/commons/ognl/internal/entry/PermissionCacheEntryFactory.java | package org.apache.commons.ognl.internal.entry;
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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.
*/
/*
*/
import org.apache.commons.ognl.OgnlInvokePermission;
import org.apache.commons.ognl.internal.CacheException;
import java.security.Permission;
public class PermissionCacheEntryFactory
implements CacheEntryFactory<PermissionCacheEntry, Permission>
{
public Permission create( PermissionCacheEntry key )
throws CacheException
{
return new OgnlInvokePermission(
"invoke." + key.method.getDeclaringClass().getName() + "." + key.method.getName() );
}
}
| 4,707 |
0 | Create_ds/commons-ognl/src/main/java/org/apache/commons/ognl/internal | Create_ds/commons-ognl/src/main/java/org/apache/commons/ognl/internal/entry/MethodPermCacheEntryFactory.java | package org.apache.commons.ognl.internal.entry;
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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.
*/
/*
*/
import org.apache.commons.ognl.OgnlRuntime;
import org.apache.commons.ognl.internal.CacheException;
import java.lang.reflect.Method;
public class MethodPermCacheEntryFactory
implements CacheEntryFactory<Method, Boolean>
{
private SecurityManager securityManager;
public MethodPermCacheEntryFactory( SecurityManager securityManager )
{
this.securityManager = securityManager;
}
public Boolean create( Method key )
throws CacheException
{
try
{
securityManager.checkPermission( OgnlRuntime.getPermission( key ) );
return true;
}
catch ( SecurityException ex )
{
return false;
}
}
public void setSecurityManager( SecurityManager securityManager )
{
this.securityManager = securityManager;
}
}
| 4,708 |
0 | Create_ds/commons-ognl/src/main/java/org/apache/commons/ognl/internal | Create_ds/commons-ognl/src/main/java/org/apache/commons/ognl/internal/entry/MethodAccessEntryValue.java | package org.apache.commons.ognl.internal.entry;
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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.
*/
/*
*/
public class MethodAccessEntryValue
{
private final boolean isAccessible;
private boolean notPublic;
public MethodAccessEntryValue( boolean accessible )
{
this.isAccessible = accessible;
}
public MethodAccessEntryValue( boolean accessible, boolean notPublic )
{
isAccessible = accessible;
this.notPublic = notPublic;
}
public boolean isAccessible()
{
return isAccessible;
}
public boolean isNotPublic()
{
return notPublic;
}
}
| 4,709 |
0 | Create_ds/commons-ognl/src/main/java/org/apache/commons/ognl/internal | Create_ds/commons-ognl/src/main/java/org/apache/commons/ognl/internal/entry/DeclaredMethodCacheEntryFactory.java | package org.apache.commons.ognl.internal.entry;
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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.
*/
/*
*/
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
/**
* User: mcucchiara
* Date: 13/10/11
* Time: 13.00
*/
public class DeclaredMethodCacheEntryFactory
extends MethodCacheEntryFactory<DeclaredMethodCacheEntry>
{
@Override
protected boolean shouldCache( DeclaredMethodCacheEntry key, Method method )
{
if ( key.type == null )
{
return true;
}
boolean isStatic = Modifier.isStatic( method.getModifiers() );
if ( key.type == DeclaredMethodCacheEntry.MethodType.STATIC )
{
return isStatic;
}
return !isStatic;
}
}
| 4,710 |
0 | Create_ds/commons-ognl/src/main/java/org/apache/commons/ognl/internal | Create_ds/commons-ognl/src/main/java/org/apache/commons/ognl/internal/entry/MethodCacheEntry.java | package org.apache.commons.ognl.internal.entry;
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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.
*/
/*
*/
public class MethodCacheEntry
implements CacheEntry
{
public final Class<?> targetClass;
public MethodCacheEntry( Class<?> targetClass )
{
this.targetClass = targetClass;
}
@Override
public boolean equals( Object o )
{
if ( this == o )
{
return true;
}
if ( !( o instanceof MethodCacheEntry ) )
{
return false;
}
MethodCacheEntry that = (MethodCacheEntry) o;
return targetClass.equals( that.targetClass );
}
@Override
public int hashCode()
{
return targetClass.hashCode();
}
}
| 4,711 |
0 | Create_ds/commons-ognl/src/main/java/org/apache/commons/ognl/internal | Create_ds/commons-ognl/src/main/java/org/apache/commons/ognl/internal/entry/PermissionCacheEntry.java | package org.apache.commons.ognl.internal.entry;
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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.
*/
/*
*/
import java.lang.reflect.Method;
public class PermissionCacheEntry
implements CacheEntry
{
public final Method method;
public PermissionCacheEntry( Method method )
{
this.method = method;
}
@Override
public boolean equals( Object o )
{
if ( this == o )
{
return true;
}
if ( !( o instanceof PermissionCacheEntry ) )
{
return false;
}
PermissionCacheEntry that = (PermissionCacheEntry) o;
return !( method != null ? !method.equals( that.method ) : that.method != null );
}
@Override
public int hashCode()
{
return method != null ? method.hashCode() : 0;
}
}
| 4,712 |
0 | Create_ds/commons-ognl/src/main/java/org/apache/commons/ognl/internal | Create_ds/commons-ognl/src/main/java/org/apache/commons/ognl/internal/entry/ParametrizedCacheEntryFactory.java | /*
*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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.apache.commons.ognl.internal.entry;
import java.util.Map;
public interface ParametrizedCacheEntryFactory
{
void setParameterValues( Map<String, String> parameters );
}
| 4,713 |
0 | Create_ds/commons-ognl/src/main/java/org/apache/commons/ognl | Create_ds/commons-ognl/src/main/java/org/apache/commons/ognl/enhance/LocalReference.java | /*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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.apache.commons.ognl.enhance;
/**
* Container class for {@link OgnlExpressionCompiler} generated local method block references.
*/
public interface LocalReference
{
/**
* The name of the assigned variable reference.
*
* @return The name of the reference as it will be when compiled.
*/
String getName();
/**
* The expression that sets the value, ie the part after <code><class type> refName = <expression></code>.
*
* @return The setting expression.
*/
String getExpression();
/**
* The type of reference.
*
* @return The type.
*/
Class<?> getType();
}
| 4,714 |
0 | Create_ds/commons-ognl/src/main/java/org/apache/commons/ognl | Create_ds/commons-ognl/src/main/java/org/apache/commons/ognl/enhance/OrderedReturn.java | /*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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.apache.commons.ognl.enhance;
/**
* Marks an ognl expression {@link org.apache.commons.ognl.Node} as needing to have the return portion of a getter
* method happen in a specific
* part of the generated expression vs just having the whole expression returned in one chunk.
*/
public interface OrderedReturn
{
/**
* Gets the core expression to execute first before any return foo logic is started.
*
* @return The core standalone expression that shouldn't be pre-pended with a return keyword.
*/
String getCoreExpression();
/**
* Gets the last expression to be pre-pended with a return <expression> block.
*
* @return The expression representing the return portion of a statement;
*/
String getLastExpression();
}
| 4,715 |
0 | Create_ds/commons-ognl/src/main/java/org/apache/commons/ognl | Create_ds/commons-ognl/src/main/java/org/apache/commons/ognl/enhance/EnhancedClassLoader.java | /*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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.apache.commons.ognl.enhance;
public class EnhancedClassLoader
extends ClassLoader
{
/*
* =================================================================== Constructors
* ===================================================================
*/
public EnhancedClassLoader( ClassLoader parentClassLoader )
{
super( parentClassLoader );
}
/*
* =================================================================== Overridden methods
* ===================================================================
*/
public Class<?> defineClass( String enhancedClassName, byte[] byteCode )
{
return defineClass( enhancedClassName, byteCode, 0, byteCode.length );
}
}
| 4,716 |
0 | Create_ds/commons-ognl/src/main/java/org/apache/commons/ognl | Create_ds/commons-ognl/src/main/java/org/apache/commons/ognl/enhance/UnsupportedCompilationException.java | /*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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.apache.commons.ognl.enhance;
/**
* Thrown during bytecode enhancement conversions of ognl expressions to indicate that a certain expression isn't
* currently supported as a pure java bytecode enhanced version.
* <p>
* If this exception is thrown it is expected that ognl will fall back to default ognl evaluation of the expression.
* </p>
*/
public class UnsupportedCompilationException
extends RuntimeException
{
/**
*
*/
private static final long serialVersionUID = 4961625077128174947L;
public UnsupportedCompilationException( String message )
{
super( message );
}
public UnsupportedCompilationException( String message, Throwable cause )
{
super( message, cause );
}
}
| 4,717 |
0 | Create_ds/commons-ognl/src/main/java/org/apache/commons/ognl | Create_ds/commons-ognl/src/main/java/org/apache/commons/ognl/enhance/ExpressionCompiler.java | /*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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.apache.commons.ognl.enhance;
import javassist.CannotCompileException;
import javassist.ClassPool;
import javassist.CtClass;
import javassist.CtField;
import javassist.CtMethod;
import javassist.CtNewConstructor;
import javassist.CtNewMethod;
import javassist.LoaderClassPath;
import javassist.NotFoundException;
import org.apache.commons.ognl.ASTAnd;
import org.apache.commons.ognl.ASTChain;
import org.apache.commons.ognl.ASTConst;
import org.apache.commons.ognl.ASTCtor;
import org.apache.commons.ognl.ASTList;
import org.apache.commons.ognl.ASTMethod;
import org.apache.commons.ognl.ASTOr;
import org.apache.commons.ognl.ASTProperty;
import org.apache.commons.ognl.ASTRootVarRef;
import org.apache.commons.ognl.ASTStaticField;
import org.apache.commons.ognl.ASTStaticMethod;
import org.apache.commons.ognl.ASTThisVarRef;
import org.apache.commons.ognl.ASTVarRef;
import org.apache.commons.ognl.ClassResolver;
import org.apache.commons.ognl.ExpressionNode;
import org.apache.commons.ognl.Node;
import org.apache.commons.ognl.OgnlContext;
import org.apache.commons.ognl.OgnlRuntime;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.util.Collection;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import static java.lang.String.format;
/**
* Responsible for managing/providing functionality related to compiling generated java source expressions via bytecode
* enhancements for a given ognl expression.
*/
public class ExpressionCompiler
implements OgnlExpressionCompiler
{
/**
* Key used to store any java source string casting statements in the {@link OgnlContext} during class compilation.
*/
public static final String PRE_CAST = "_preCast";
/**
* {@link ClassLoader} instances.
*/
protected Map<ClassResolver, EnhancedClassLoader> loaders = new HashMap<ClassResolver, EnhancedClassLoader>();
/**
* Javassist class definition poool.
*/
protected ClassPool pool;
protected int classCounter;
/**
* Used by {@link #castExpression(org.apache.commons.ognl.OgnlContext, org.apache.commons.ognl.Node, String)} to
* store the cast java source string in to the current {@link org.apache.commons.ognl.OgnlContext}. This will either
* add to the existing string present if it already exists or create a new instance and store it using the static
* key of {@link #PRE_CAST}.
*
* @param context The current execution context.
* @param cast The java source string to store in to the context.
*/
public static void addCastString( OgnlContext context, String cast )
{
String value = (String) context.get( PRE_CAST );
if ( value != null )
{
value = cast + value;
}
else
{
value = cast;
}
context.put( PRE_CAST, value );
}
/**
* Returns the appropriate casting expression (minus parens) for the specified class type.
* <p/>
* For instance, if given an {@link Integer} object the string <code>"java.lang.Integer"</code> would be returned.
* For an array of primitive ints <code>"int[]"</code> and so on..
* </p>
*
* @param type The class to cast a string expression for.
* @return The converted raw string version of the class name.
*/
public static String getCastString( Class<?> type )
{
if ( type == null )
{
return null;
}
return type.isArray() ? type.getComponentType().getName() + "[]" : type.getName();
}
/**
* Convenience method called by many different property/method resolving AST types to get a root expression
* resolving string for the given node. The callers are mostly ignorant and rely on this method to properly
* determine if the expression should be cast at all and take the appropriate actions if it should.
*
* @param expression The node to check and generate a root expression to if necessary.
* @param root The root object for this execution.
* @param context The current execution context.
* @return Either an empty string or a root path java source string compatible with javassist compilations from the
* root object up to the specified {@link Node}.
*/
public static String getRootExpression( Node expression, Object root, OgnlContext context )
{
String rootExpr = "";
if ( !shouldCast( expression ) )
{
return rootExpr;
}
if ( ( !(expression instanceof ASTList) && !(expression instanceof ASTVarRef)
&& !(expression instanceof ASTStaticMethod) && !(expression instanceof ASTStaticField)
&& !(expression instanceof ASTConst) && !(expression instanceof ExpressionNode)
&& !(expression instanceof ASTCtor) && !(expression instanceof ASTStaticMethod)
&& root != null ) || ( root != null && expression instanceof ASTRootVarRef) )
{
Class<?> castClass = OgnlRuntime.getCompiler( context ).getRootExpressionClass( expression, context );
if ( castClass.isArray() || expression instanceof ASTRootVarRef || expression instanceof ASTThisVarRef)
{
rootExpr = "((" + getCastString( castClass ) + ")$2)";
if ( expression instanceof ASTProperty && !( (ASTProperty) expression ).isIndexedAccess() )
{
rootExpr += ".";
}
}
else if ( ( expression instanceof ASTProperty && ( (ASTProperty) expression ).isIndexedAccess() )
|| expression instanceof ASTChain)
{
rootExpr = "((" + getCastString( castClass ) + ")$2)";
}
else
{
rootExpr = "((" + getCastString( castClass ) + ")$2).";
}
}
return rootExpr;
}
/**
* Used by {@link #getRootExpression(org.apache.commons.ognl.Node, Object, org.apache.commons.ognl.OgnlContext)} to
* determine if the expression needs to be cast at all.
*
* @param expression The node to check against.
* @return Yes if the node type should be cast - false otherwise.
*/
public static boolean shouldCast( Node expression )
{
if (expression instanceof ASTChain)
{
Node child = expression.jjtGetChild( 0 );
if ( child instanceof ASTConst || child instanceof ASTStaticMethod
|| child instanceof ASTStaticField || ( child instanceof ASTVarRef
&& !(child instanceof ASTRootVarRef)) )
{
return false;
}
}
return !(expression instanceof ASTConst);
}
/**
* {@inheritDoc}
*/
public String castExpression( OgnlContext context, Node expression, String body )
{
//TODO: ok - so this looks really f-ed up ...and it is ..eh if you can do it better I'm all for it :)
if ( context.getCurrentAccessor() == null || context.getPreviousType() == null
|| context.getCurrentAccessor().isAssignableFrom( context.getPreviousType() ) || (
context.getCurrentType() != null && context.getCurrentObject() != null
&& context.getCurrentType().isAssignableFrom( context.getCurrentObject().getClass() )
&& context.getCurrentAccessor().isAssignableFrom( context.getPreviousType() ) ) || body == null
|| body.trim().length() < 1 || ( context.getCurrentType() != null && context.getCurrentType().isArray() && (
context.getPreviousType() == null || context.getPreviousType() != Object.class ) )
|| expression instanceof ASTOr || expression instanceof ASTAnd
|| expression instanceof ASTRootVarRef || context.getCurrentAccessor() == Class.class || (
context.get( ExpressionCompiler.PRE_CAST ) != null && ( (String) context.get(
ExpressionCompiler.PRE_CAST ) ).startsWith( "new" ) ) || expression instanceof ASTStaticField
|| expression instanceof ASTStaticMethod || ( expression instanceof OrderedReturn
&& ( (OrderedReturn) expression ).getLastExpression() != null ) )
{
return body;
}
/*
* System.out.println("castExpression() with expression " + expression + " expr class: " + expression.getClass()
* + " currentType is: " + context.getCurrentType() + " previousType: " + context.getPreviousType() +
* "\n current Accessor: " + context.getCurrentAccessor() + " previous Accessor: " +
* context.getPreviousAccessor() + " current object " + context.getCurrentObject());
*/
ExpressionCompiler.addCastString( context,
"((" + ExpressionCompiler.getCastString( context.getCurrentAccessor() )
+ ")" );
return ")" + body;
}
/**
* {@inheritDoc}
*/
public String getClassName( Class<?> clazz )
{
if ( "java.util.AbstractList$Itr".equals( clazz.getName() ) )
{
return Iterator.class.getName();
}
if ( Modifier.isPublic( clazz.getModifiers() ) && clazz.isInterface() )
{
return clazz.getName();
}
Class<?>[] interfaces = clazz.getInterfaces();
for ( Class<?> intface : interfaces )
{
if ( intface.getName().indexOf( "util.List" ) > 0 )
{
return intface.getName();
}
if ( intface.getName().indexOf( "Iterator" ) > 0 )
{
return intface.getName();
}
}
if ( clazz.getSuperclass() != null && clazz.getSuperclass().getInterfaces().length > 0 )
{
return getClassName( clazz.getSuperclass() );
}
return clazz.getName();
}
/**
* {@inheritDoc}
*/
public Class<?> getSuperOrInterfaceClass( Method m, Class<?> clazz )
{
if ( clazz.getInterfaces() != null && clazz.getInterfaces().length > 0 )
{
Class<?>[] intfs = clazz.getInterfaces();
Class<?> intClass;
for ( Class<?> intf : intfs )
{
intClass = getSuperOrInterfaceClass( m, intf );
if ( intClass != null )
{
return intClass;
}
if ( Modifier.isPublic( intf.getModifiers() ) && containsMethod( m, intf ) )
{
return intf;
}
}
}
if ( clazz.getSuperclass() != null )
{
Class<?> superClass = getSuperOrInterfaceClass( m, clazz.getSuperclass() );
if ( superClass != null )
{
return superClass;
}
}
if ( Modifier.isPublic( clazz.getModifiers() ) && containsMethod( m, clazz ) )
{
return clazz;
}
return null;
}
/**
* Helper utility method used by compiler to help resolve class->method mappings during method calls to
* {@link OgnlExpressionCompiler#getSuperOrInterfaceClass(java.lang.reflect.Method, Class)}.
*
* @param m The method to check for existance of.
* @param clazz The class to check for the existance of a matching method definition to the method passed in.
* @return True if the class contains the specified method, false otherwise.
*/
public boolean containsMethod( Method m, Class<?> clazz )
{
Method[] methods = clazz.getMethods();
if ( methods == null )
{
return false;
}
for ( Method method : methods )
{
if ( method.getName().equals( m.getName() ) && method.getReturnType() == m.getReturnType() )
{
Class<?>[] parms = m.getParameterTypes();
if ( parms == null )
{
continue;
}
Class<?>[] mparms = method.getParameterTypes();
if ( mparms == null || mparms.length != parms.length )
{
continue;
}
boolean parmsMatch = true;
for ( int p = 0; p < parms.length; p++ )
{
if ( parms[p] != mparms[p] )
{
parmsMatch = false;
break;
}
}
if ( !parmsMatch )
{
continue;
}
Class<?>[] exceptions = m.getExceptionTypes();
if ( exceptions == null )
{
continue;
}
Class<?>[] mexceptions = method.getExceptionTypes();
if ( mexceptions == null || mexceptions.length != exceptions.length )
{
continue;
}
boolean exceptionsMatch = true;
for ( int e = 0; e < exceptions.length; e++ )
{
if ( exceptions[e] != mexceptions[e] )
{
exceptionsMatch = false;
break;
}
}
if ( !exceptionsMatch )
{
continue;
}
return true;
}
}
return false;
}
/**
* {@inheritDoc}
*/
public Class<?> getInterfaceClass( Class<?> clazz )
{
if ( "java.util.AbstractList$Itr".equals( clazz.getName() ) )
{
return Iterator.class;
}
if ( Modifier.isPublic( clazz.getModifiers() ) && clazz.isInterface() || clazz.isPrimitive() )
{
return clazz;
}
Class<?>[] intf = clazz.getInterfaces();
for ( Class<?> anIntf : intf )
{
if ( List.class.isAssignableFrom( anIntf ) )
{
return List.class;
}
if ( Iterator.class.isAssignableFrom( anIntf ) )
{
return Iterator.class;
}
if ( Map.class.isAssignableFrom( anIntf ) )
{
return Map.class;
}
if ( Set.class.isAssignableFrom( anIntf ) )
{
return Set.class;
}
if ( Collection.class.isAssignableFrom( anIntf ) )
{
return Collection.class;
}
}
if ( clazz.getSuperclass() != null && clazz.getSuperclass().getInterfaces().length > 0 )
{
return getInterfaceClass( clazz.getSuperclass() );
}
return clazz;
}
/**
* {@inheritDoc}
*/
public Class<?> getRootExpressionClass( Node rootNode, OgnlContext context )
{
if ( context.getRoot() == null )
{
return null;
}
Class<?> ret = context.getRoot().getClass();
if ( context.getFirstAccessor() != null && context.getFirstAccessor().isInstance( context.getRoot() ) )
{
ret = context.getFirstAccessor();
}
return ret;
}
/**
* {@inheritDoc}
*/
public void compileExpression( OgnlContext context, Node expression, Object root )
throws Exception
{
// System.out.println("Compiling expr class " + expression.getClass().getName() + " and root " + root);
if ( expression.getAccessor() != null )
{
return;
}
String getBody, setBody;
EnhancedClassLoader loader = getClassLoader( context );
ClassPool classPool = getClassPool( context, loader );
CtClass newClass = classPool.makeClass(
expression.getClass().getName() + expression.hashCode() + classCounter++ + "Accessor" );
newClass.addInterface( getCtClass( ExpressionAccessor.class ) );
CtClass ognlClass = getCtClass( OgnlContext.class );
CtClass objClass = getCtClass( Object.class );
CtMethod valueGetter = new CtMethod( objClass, "get", new CtClass[] { ognlClass, objClass }, newClass );
CtMethod valueSetter =
new CtMethod( CtClass.voidType, "set", new CtClass[] { ognlClass, objClass, objClass }, newClass );
CtField nodeMember = null; // will only be set if uncompilable exception is thrown
CtClass nodeClass = getCtClass( Node.class );
CtMethod setExpression = null;
try
{
getBody = generateGetter( context, newClass, objClass, classPool, valueGetter, expression, root );
}
catch ( UnsupportedCompilationException uc )
{
nodeMember = new CtField( nodeClass, "_node", newClass );
newClass.addField( nodeMember );
getBody = generateOgnlGetter( newClass, valueGetter, nodeMember );
setExpression = CtNewMethod.setter( "setExpression", nodeMember );
newClass.addMethod( setExpression );
}
try
{
setBody = generateSetter( context, newClass, objClass, classPool, valueSetter, expression, root );
}
catch ( UnsupportedCompilationException uc )
{
if ( nodeMember == null )
{
nodeMember = new CtField( nodeClass, "_node", newClass );
newClass.addField( nodeMember );
}
setBody = generateOgnlSetter( newClass, valueSetter, nodeMember );
if ( setExpression == null )
{
setExpression = CtNewMethod.setter( "setExpression", nodeMember );
newClass.addMethod( setExpression );
}
}
try
{
newClass.addConstructor( CtNewConstructor.defaultConstructor( newClass ) );
Class<?> clazz = classPool.toClass( newClass );
newClass.detach();
expression.setAccessor( (ExpressionAccessor) clazz.newInstance() );
// need to set expression on node if the field was just defined.
if ( nodeMember != null )
{
expression.getAccessor().setExpression( expression );
}
}
catch ( Throwable t )
{
throw new IllegalStateException( "Error compiling expression on object " + root + " with expression node "
+ expression + " getter body: " + getBody + " setter body: " + setBody, t );
}
}
protected String generateGetter( OgnlContext context, CtClass newClass, CtClass objClass, ClassPool classPool,
CtMethod valueGetter, Node expression, Object root )
throws Exception
{
String pre = "";
String post = "";
String body;
context.setRoot( root );
// the ExpressionAccessor API has to reference the generic Object class for get/set operations, so this sets up
// that known
// type beforehand
context.remove( PRE_CAST );
// Recursively generate the java source code representation of the top level expression
String getterCode = expression.toGetSourceString( context, root );
if ( getterCode == null || getterCode.trim().isEmpty()
&& !ASTVarRef.class.isAssignableFrom( expression.getClass() ) )
{
getterCode = "null";
}
String castExpression = (String) context.get( PRE_CAST );
if ( context.getCurrentType() == null || context.getCurrentType().isPrimitive()
|| Character.class.isAssignableFrom( context.getCurrentType() )
|| Object.class == context.getCurrentType() )
{
pre = pre + " ($w) (";
post = post + ")";
}
String rootExpr = !"null".equals( getterCode ) ? getRootExpression( expression, root, context ) : "";
String noRoot = (String) context.remove( "_noRoot" );
if ( noRoot != null )
{
rootExpr = "";
}
createLocalReferences( context, classPool, newClass, objClass, valueGetter.getParameterTypes() );
if ( expression instanceof OrderedReturn
&& ( (OrderedReturn) expression ).getLastExpression() != null )
{
body = "{ " + ( expression instanceof ASTMethod || expression instanceof ASTChain
? rootExpr
: "" ) + ( castExpression != null ? castExpression : "" )
+ ( (OrderedReturn) expression ).getCoreExpression() + " return " + pre
+ ( (OrderedReturn) expression ).getLastExpression() + post + ";}";
}
else
{
body =
"{ return " + pre + ( castExpression != null ? castExpression : "" ) + rootExpr + getterCode + post
+ ";}";
}
body = body.replaceAll( "\\.\\.", "." );
// System.out.println("Getter Body: ===================================\n" + body);
valueGetter.setBody( body );
newClass.addMethod( valueGetter );
return body;
}
/**
* {@inheritDoc}
*/
public String createLocalReference( OgnlContext context, String expression, Class<?> type )
{
String referenceName = "ref" + context.incrementLocalReferenceCounter();
context.addLocalReference( referenceName, new LocalReferenceImpl( referenceName, expression, type ) );
String castString = "";
if ( !type.isPrimitive() )
{
castString = "(" + ExpressionCompiler.getCastString( type ) + ") ";
}
return castString + referenceName + "($$)";
}
void createLocalReferences( OgnlContext context, ClassPool classPool, CtClass clazz, CtClass unused,
CtClass[] params )
throws NotFoundException, CannotCompileException
{
Map<String, LocalReference> referenceMap = context.getLocalReferences();
if ( referenceMap == null || referenceMap.isEmpty() )
{
return;
}
Iterator<LocalReference> it = referenceMap.values().iterator();
while( it.hasNext() )
{
LocalReference ref = it.next();
String widener = ref.getType().isPrimitive() ? " " : " ($w) ";
String body = format( "{ return %s %s; }", widener, ref.getExpression() ).replaceAll( "\\.\\.", "." );
// System.out.println("adding method " + ref.getName() + " with body:\n" + body + " and return type: " +
// ref.getType());
CtMethod method =
new CtMethod( classPool.get( getCastString( ref.getType() ) ), ref.getName(), params, clazz );
method.setBody( body );
clazz.addMethod( method );
it.remove();
}
}
protected String generateSetter( OgnlContext context, CtClass newClass, CtClass objClass, ClassPool classPool,
CtMethod valueSetter, Node expression, Object root )
throws Exception
{
if ( expression instanceof ExpressionNode || expression instanceof ASTConst)
{
throw new UnsupportedCompilationException( "Can't compile expression/constant setters." );
}
context.setRoot( root );
context.remove( PRE_CAST );
String body;
String setterCode = expression.toSetSourceString( context, root );
String castExpression = (String) context.get( PRE_CAST );
if ( setterCode == null || setterCode.trim().length() < 1 )
{
throw new UnsupportedCompilationException( "Can't compile null setter body." );
}
if ( root == null )
{
throw new UnsupportedCompilationException( "Can't compile setters with a null root object." );
}
String pre = getRootExpression( expression, root, context );
String noRoot = (String) context.remove( "_noRoot" );
if ( noRoot != null )
{
pre = "";
}
createLocalReferences( context, classPool, newClass, objClass, valueSetter.getParameterTypes() );
body = "{" + ( castExpression != null ? castExpression : "" ) + pre + setterCode + ";}";
body = body.replaceAll( "\\.\\.", "." );
// System.out.println("Setter Body: ===================================\n" + body);
valueSetter.setBody( body );
newClass.addMethod( valueSetter );
return body;
}
/**
* Fail safe getter creation when normal compilation fails.
*
* @param clazz The javassist class the new method should be attached to.
* @param valueGetter The method definition the generated code will be contained within.
* @param node The root expression node.
* @return The generated source string for this method, the method will still be added via the javassist API either
* way so this is really a convenience for exception reporting / debugging.
* @throws Exception If a javassist error occurs.
*/
protected String generateOgnlGetter( CtClass clazz, CtMethod valueGetter, CtField node )
throws Exception
{
String body = "return " + node.getName() + ".getValue($1, $2);";
valueGetter.setBody( body );
clazz.addMethod( valueGetter );
return body;
}
/**
* Fail safe setter creation when normal compilation fails.
*
* @param clazz The javassist class the new method should be attached to.
* @param valueSetter The method definition the generated code will be contained within.
* @param node The root expression node.
* @return The generated source string for this method, the method will still be added via the javassist API either
* way so this is really a convenience for exception reporting / debugging.
* @throws Exception If a javassist error occurs.
*/
protected String generateOgnlSetter( CtClass clazz, CtMethod valueSetter, CtField node )
throws Exception
{
String body = node.getName() + ".setValue($1, $2, $3);";
valueSetter.setBody( body );
clazz.addMethod( valueSetter );
return body;
}
/**
* Creates a {@link ClassLoader} instance compatible with the javassist classloader and normal OGNL class resolving
* semantics.
*
* @param context The current execution context.
* @return The created {@link ClassLoader} instance.
*/
protected EnhancedClassLoader getClassLoader( OgnlContext context )
{
EnhancedClassLoader ret = loaders.get( context.getClassResolver() );
if ( ret != null )
{
return ret;
}
ClassLoader classLoader = new ContextClassLoader( OgnlContext.class.getClassLoader(), context );
ret = new EnhancedClassLoader( classLoader );
loaders.put( context.getClassResolver(), ret );
return ret;
}
/**
* Loads a new class definition via javassist for the specified class.
*
* @param searchClass The class to load.
* @return The javassist class equivalent.
* @throws javassist.NotFoundException When the class definition can't be found.
*/
protected CtClass getCtClass( Class<?> searchClass )
throws NotFoundException
{
return pool.get( searchClass.getName() );
}
/**
* Gets either a new or existing {@link ClassPool} for use in compiling javassist classes. A new class path object
* is inserted in to the returned {@link ClassPool} using the passed in <code>loader</code> instance if a new pool
* needs to be created.
*
* @param context The current execution context.
* @param loader The {@link ClassLoader} instance to use - as returned by
* {@link #getClassLoader(org.apache.commons.ognl.OgnlContext)}.
* @return The existing or new {@link ClassPool} instance.
*/
protected ClassPool getClassPool( OgnlContext context, EnhancedClassLoader loader )
{
if ( pool != null )
{
return pool;
}
pool = ClassPool.getDefault();
pool.insertClassPath( new LoaderClassPath( loader.getParent() ) );
return pool;
}
}
| 4,718 |
0 | Create_ds/commons-ognl/src/main/java/org/apache/commons/ognl | Create_ds/commons-ognl/src/main/java/org/apache/commons/ognl/enhance/OgnlExpressionCompiler.java | /*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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.apache.commons.ognl.enhance;
import org.apache.commons.ognl.Node;
import org.apache.commons.ognl.OgnlContext;
import java.lang.reflect.Method;
/**
* Core interface implemented by expression compiler instances.
*/
public interface OgnlExpressionCompiler
{
/** Static constant used in conjunction with {@link OgnlContext} to store temporary references. */
String ROOT_TYPE = "-ognl-root-type";
/**
* The core method executed to compile a specific expression. It is expected that this expression always return a
* {@link Node} with a non null {@link org.apache.commons.ognl.Node#getAccessor()} instance - unless an exception is
* thrown by the method or the statement wasn't compilable in this instance because of missing/null objects in the
* expression. These instances may in some cases continue to call this compilation method until the expression is
* resolvable.
*
* @param context The context of execution.
* @param expression The pre-parsed root expression node to compile.
* @param root The root object for the expression - may be null in many instances so some implementations may exit
* @throws Exception If an error occurs compiling the expression and no strategy has been implemented to handle
* incremental expression compilation for incomplete expression members.
*/
void compileExpression( OgnlContext context, Node expression, Object root )
throws Exception;
/**
* Gets a javassist safe class string for the given class instance. This is especially useful for handling array vs.
* normal class casting strings.
*
* @param clazz The class to get a string equivalent javassist compatible string reference for.
* @return The string equivalent of the class.
*/
String getClassName( Class<?> clazz );
/**
* Used in places where the preferred {@link #getSuperOrInterfaceClass(java.lang.reflect.Method, Class)} isn't
* possible because the method isn't known for a class. Attempts to upcast the given class to the next available
* non-private accessible class so that compiled expressions can reference the interface class of an instance so as
* not to be compiled in to overly specific statements.
*
* @param clazz The class to attempt to find a compatible interface for.
* @return The same class if no higher level interface could be matched against or the interface equivalent class.
*/
Class<?> getInterfaceClass( Class<?> clazz );
/**
* For the given {@link Method} and class finds the highest level interface class this combination can be cast to.
*
* @param m The method the class must implement.
* @param clazz The current class being worked with.
* @return The highest level interface / class that the referenced {@link Method} is declared in.
*/
Class<?> getSuperOrInterfaceClass( Method m, Class<?> clazz );
/**
* For a given root object type returns the base class type to be used in root referenced expressions. This helps in
* some instances where the root objects themselves are compiled javassist instances that need more generic class
* equivalents to cast to.
*
* @param rootNode The root expression node.
* @param context The current execution context.
* @return The root expression class type to cast to for this node.
*/
Class<?> getRootExpressionClass( Node rootNode, OgnlContext context );
/**
* Used primarily by AST types like {@link org.apache.commons.ognl.ASTChain} where <code>foo.bar.id</code> type
* references may need to be cast multiple times in order to properly resolve the members in a compiled statement.
* <p>
* This method should be using the various {@link org.apache.commons.ognl.OgnlContext#getCurrentType()} /
* {@link org.apache.commons.ognl.OgnlContext#getCurrentAccessor()} methods to inspect the type stack and properly
* cast to the right classes - but only when necessary.
* </p>
*
* @param context The current execution context.
* @param expression The node being checked for casting.
* @param body The java source string generated by the given node.
* @return The body string parameter plus any additional casting syntax needed to make the expression resolvable.
*/
String castExpression( OgnlContext context, Node expression, String body );
/**
* Method is used for expressions where multiple inner parameter method calls in generated java source strings cause
* javassit failures. It is hacky and cumbersome to have to generate expressions this way but it's the only current
* known way to make javassist happy.
* <p>
* Takes an expression block generated by a node and creates a new method on the base object being compiled so that
* sufficiently complicated sub expression blocks can be broken out in to distinct methods to be referenced by the
* core accessor / setter methods in the base compiled root object.
* </p>
*
* @param context The current execution context.
* @param expression The java source expression to dump in to a seperate method reference.
* @param type The return type that should be specified for the new method.
* @return The method name that will be used to reference the sub expression in place of the actual sub expression
* itself.
*/
String createLocalReference( OgnlContext context, String expression, Class<?> type );
}
| 4,719 |
0 | Create_ds/commons-ognl/src/main/java/org/apache/commons/ognl | Create_ds/commons-ognl/src/main/java/org/apache/commons/ognl/enhance/ExpressionAccessor.java | /*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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.apache.commons.ognl.enhance;
import org.apache.commons.ognl.Node;
import org.apache.commons.ognl.OgnlContext;
/**
* Provides pure java expression paths to get/set values from an ognl expression. This is achieved by taking an existing
* {@link Node} parsed expression and using bytecode enhancements to do the same work using pure java vs the ognl
* interpreter.
*/
public interface ExpressionAccessor
{
/**
* Gets the value represented by this expression path, if any.
*
* @param context The standard ognl context used for variable substitution/etc.
* @param target The root object this expression is meant for.
* @return The evaluated value, if any.
*/
Object get( OgnlContext context, Object target );
/**
* Sets the value represented by this expression path, if possible.
*
* @param context The standard ognl context used for variable substitution/etc.
* @param target The root object this expression is meant for.
* @param value The new value to set if this expression references a settable property.
*/
void set( OgnlContext context, Object target, Object value );
/**
* Used to set the original root expression node on instances where the compiled version has to fall back to
* interpreted syntax because of compilation failures.
*
* @param expression The root expression node used to generate this accessor.
*/
void setExpression( Node expression );
}
| 4,720 |
0 | Create_ds/commons-ognl/src/main/java/org/apache/commons/ognl | Create_ds/commons-ognl/src/main/java/org/apache/commons/ognl/enhance/LocalReferenceImpl.java | /*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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.apache.commons.ognl.enhance;
/**
* Implementation of {@link LocalReference}.
*/
public class LocalReferenceImpl
implements LocalReference
{
private final String name;
private final Class<?> type;
private final String expression;
public LocalReferenceImpl( String name, String expression, Class<?> type )
{
this.name = name;
this.type = type;
this.expression = expression;
}
/**
* {@inheritDoc}
*/
public String getName()
{
return name;
}
/**
* {@inheritDoc}
*/
public String getExpression()
{
return expression;
}
/**
* {@inheritDoc}
*/
public Class<?> getType()
{
return type;
}
/**
* {@inheritDoc}
*/
@Override
public boolean equals( Object o )
{
if ( this == o )
{
return true;
}
if ( o == null || getClass() != o.getClass() )
{
return false;
}
LocalReferenceImpl that = (LocalReferenceImpl) o;
if ( expression != null ? !expression.equals( that.expression ) : that.expression != null )
{
return false;
}
if ( name != null ? !name.equals( that.name ) : that.name != null )
{
return false;
}
if ( type != null ? !type.equals( that.type ) : that.type != null )
{
return false;
}
return true;
}
/**
* {@inheritDoc}
*/
@Override
public int hashCode()
{
int result;
result = ( name != null ? name.hashCode() : 0 );
result = 31 * result + ( type != null ? type.hashCode() : 0 );
result = 31 * result + ( expression != null ? expression.hashCode() : 0 );
return result;
}
/**
* {@inheritDoc}
*/
@Override
public String toString()
{
return "LocalReferenceImpl[" + "_name='" + name + '\'' + '\n' + ", _type=" + type + '\n' + ", _expression='"
+ expression + '\'' + '\n' + ']';
}
}
| 4,721 |
0 | Create_ds/commons-ognl/src/main/java/org/apache/commons/ognl | Create_ds/commons-ognl/src/main/java/org/apache/commons/ognl/enhance/ContextClassLoader.java | /*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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.apache.commons.ognl.enhance;
import org.apache.commons.ognl.OgnlContext;
public class ContextClassLoader
extends ClassLoader
{
private final OgnlContext context;
/*
* =================================================================== Constructors
* ===================================================================
*/
public ContextClassLoader( ClassLoader parentClassLoader, OgnlContext context )
{
super( parentClassLoader );
this.context = context;
}
/*
* =================================================================== Overridden methods
* ===================================================================
*/
/**
* {@inheritDoc}
*/
@Override
protected Class<?> findClass( String name )
throws ClassNotFoundException
{
if ( ( context != null ) && ( context.getClassResolver() != null ) )
{
return context.getClassResolver().classForName( name, context );
}
return super.findClass( name );
}
}
| 4,722 |
0 | Create_ds/commons-ognl/src/main/java/org/apache/commons/ognl | Create_ds/commons-ognl/src/main/java/org/apache/commons/ognl/enhance/package-info.java | /*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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.apache.commons.ognl.enhance;
/*
* Enhanced basic Java components.
*/
| 4,723 |
0 | Create_ds/fineract-cn-accounting/importer/src/main/java/org/apache/fineract/cn/accounting | Create_ds/fineract-cn-accounting/importer/src/main/java/org/apache/fineract/cn/accounting/importer/AccountImporter.java | /*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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.apache.fineract.cn.accounting.importer;
import org.apache.fineract.cn.accounting.api.v1.client.AccountAlreadyExistsException;
import org.apache.fineract.cn.accounting.api.v1.client.LedgerManager;
import org.apache.fineract.cn.accounting.api.v1.domain.Account;
import org.apache.fineract.cn.accounting.api.v1.domain.Ledger;
import org.apache.commons.csv.CSVFormat;
import org.apache.commons.csv.CSVParser;
import org.apache.commons.csv.CSVRecord;
import org.slf4j.Logger;
import java.io.IOException;
import java.net.URL;
import java.nio.charset.StandardCharsets;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Objects;
import java.util.Set;
import java.util.stream.Collectors;
import java.util.stream.StreamSupport;
/**
* @author Myrle Krantz
*/
@SuppressWarnings("unused")
public class AccountImporter {
private static final String TYPE_COLUMN = "type";
private static final String IDENTIFIER_COLUMN = "identifier";
private static final String NAME_COLUMN = "name";
private static final String PARENT_IDENTIFIER_COLUMN = "parentIdentifier";
private static final String HOLDERS_COLUMN = "holders";
private static final String AUTHORITIES_COLUMN = "authorities";
private static final String BALANCE_COLUMN = "balance";
private final LedgerManager ledgerManager;
private final Logger logger;
public AccountImporter(final LedgerManager ledgerManager, final Logger logger) {
this.ledgerManager = ledgerManager;
this.logger = logger;
}
public void importCSV(final URL toImport) throws IOException {
final CSVParser parser = CSVParser.parse(toImport, StandardCharsets.UTF_8, CSVFormat.RFC4180.withHeader());
final List<RecordFromLineNumber<Account>> ledgerList = StreamSupport.stream(parser.spliterator(), false)
.map(this::toAccount)
.collect(Collectors.toList()); //File should fully parse, correctly, before we begin creating ledgers/accounts.
ledgerList.forEach(this::createAccount);
}
private void createAccount(final RecordFromLineNumber<Account> toCreate) {
try {
ledgerManager.createAccount(toCreate.getRecord());
}
catch (final AccountAlreadyExistsException ignored) {
final Account account = ledgerManager.findAccount(toCreate.getRecord().getIdentifier());
if ((!Objects.equals(account.getBalance(), toCreate.getRecord().getBalance())) ||
(!Objects.equals(account.getIdentifier(), toCreate.getRecord().getIdentifier())) ||
(!Objects.equals(account.getHolders(), toCreate.getRecord().getHolders())) ||
(!Objects.equals(account.getLedger(), toCreate.getRecord().getLedger())) ||
(!Objects.equals(account.getName(), toCreate.getRecord().getName())) ||
(!Objects.equals(account.getSignatureAuthorities(), toCreate.getRecord().getSignatureAuthorities())) ||
(!Objects.equals(account.getType(), toCreate.getRecord().getType())))
{
logger.error("Creation of account {} failed, because an account with the same identifier but different properties already exists {}", toCreate.getRecord(), account);
}
}
}
private RecordFromLineNumber<Account> toAccount(final CSVRecord csvRecord) {
try {
final String ledgerIdentifier = csvRecord.get(PARENT_IDENTIFIER_COLUMN);
String type;
try {
type = csvRecord.get(TYPE_COLUMN);
}
catch (final IllegalArgumentException e) {
final Ledger ledger = ledgerManager.findLedger(ledgerIdentifier);
type = ledger.getType();
}
final String identifier = csvRecord.get(IDENTIFIER_COLUMN);
String name;
try {
name = csvRecord.get(NAME_COLUMN);
}
catch (final IllegalArgumentException e) {
name = identifier;
}
Set<String> holders;
try {
holders = new HashSet<>(Arrays.asList(csvRecord.get(HOLDERS_COLUMN).split("/")));
}
catch (final IllegalArgumentException e) {
holders = Collections.emptySet();
}
Set<String> authorities;
try {
authorities = new HashSet<>(Arrays.asList(csvRecord.get(AUTHORITIES_COLUMN).split("/")));
}
catch (final IllegalArgumentException e) {
authorities = Collections.emptySet();
}
Double balance;
try {
balance = Double.valueOf(csvRecord.get(BALANCE_COLUMN));
}
catch (final IllegalArgumentException e) {
balance = 0.0;
}
final Account account = new Account();
account.setType(type);
account.setIdentifier(identifier);
account.setName(name);
account.setHolders(holders);
account.setSignatureAuthorities(authorities);
account.setLedger(ledgerIdentifier);
account.setBalance(balance);
return new RecordFromLineNumber<>(csvRecord.getRecordNumber(), account);
}
catch (final NumberFormatException e) {
logger.warn("Number parsing failed on record {}", csvRecord.getRecordNumber());
throw e;
}
catch (final IllegalArgumentException e) {
logger.warn("Parsing failed on record {}", csvRecord.getRecordNumber());
throw e;
}
}
}
| 4,724 |
0 | Create_ds/fineract-cn-accounting/importer/src/main/java/org/apache/fineract/cn/accounting | Create_ds/fineract-cn-accounting/importer/src/main/java/org/apache/fineract/cn/accounting/importer/RecordFromLineNumber.java | /*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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.apache.fineract.cn.accounting.importer;
/**
* @author Myrle Krantz
*/
class RecordFromLineNumber<T> {
private final long recordNumber;
private final T record;
RecordFromLineNumber(final long recordNumber, final T record) {
this.recordNumber = recordNumber;
this.record = record;
}
long getRecordNumber() {
return recordNumber;
}
T getRecord() {
return record;
}
} | 4,725 |
0 | Create_ds/fineract-cn-accounting/importer/src/main/java/org/apache/fineract/cn/accounting | Create_ds/fineract-cn-accounting/importer/src/main/java/org/apache/fineract/cn/accounting/importer/LedgerImporter.java | /*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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.apache.fineract.cn.accounting.importer;
import org.apache.fineract.cn.accounting.api.v1.client.LedgerAlreadyExistsException;
import org.apache.fineract.cn.accounting.api.v1.client.LedgerManager;
import org.apache.fineract.cn.accounting.api.v1.domain.Ledger;
import org.apache.commons.csv.CSVFormat;
import org.apache.commons.csv.CSVParser;
import org.apache.commons.csv.CSVRecord;
import org.slf4j.Logger;
import java.io.IOException;
import java.net.URL;
import java.nio.charset.StandardCharsets;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;
import java.util.stream.StreamSupport;
/**
* @author Myrle Krantz
*/
@SuppressWarnings("unused")
public class LedgerImporter {
private static final String IDENTIFIER_COLUMN = "identifier";
private static final String PARENT_IDENTIFIER_COLUMN = "parentIdentifier";
private static final String TYPE_COLUMN = "type";
private static final String NAME_COLUMN = "name";
private static final String SHOW_ACCOUNTS_IN_CHART_COLUMN = "show";
private static final String DESCRIPTION_COLUMN = "description";
private final LedgerManager ledgerManager;
private final Logger logger;
public LedgerImporter(final LedgerManager ledgerManager, final Logger logger) {
this.ledgerManager = ledgerManager;
this.logger = logger;
}
public void importCSV(final URL toImport) throws IOException {
final CSVParser parser = CSVParser.parse(toImport, StandardCharsets.UTF_8, CSVFormat.RFC4180.withHeader());
final List<RecordFromLineNumber<Ledger>> ledgerList = StreamSupport.stream(parser.spliterator(), false)
.map(this::toLedger)
.collect(Collectors.toList()); //File should fully parse, correctly, before we begin creating ledgers/accounts.
ledgerList.forEach(this::createLedger);
}
private void createLedger(final RecordFromLineNumber<Ledger> toCreate) {
try {
final Ledger ledger = toCreate.getRecord();
if (ledger.getParentLedgerIdentifier() == null) {
ledgerManager.createLedger(toCreate.getRecord());
} else {
ledgerManager.addSubLedger(ledger.getParentLedgerIdentifier(), ledger);
}
try {
Thread.sleep(1000l);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
catch (final LedgerAlreadyExistsException ignored) {
final Ledger ledger = ledgerManager.findLedger(toCreate.getRecord().getIdentifier());
if ((!Objects.equals(ledger.getIdentifier(), toCreate.getRecord().getIdentifier())) ||
(!Objects.equals(ledger.getName(), toCreate.getRecord().getName())) ||
(!Objects.equals(ledger.getType(), toCreate.getRecord().getType())) ||
(!Objects.equals(ledger.getDescription(), toCreate.getRecord().getDescription())) ||
(!Objects.equals(ledger.getParentLedgerIdentifier(), toCreate.getRecord().getParentLedgerIdentifier())) ||
(!Objects.equals(ledger.getShowAccountsInChart(), toCreate.getRecord().getShowAccountsInChart())))
{
logger.error("Creation of ledger {} failed, because a ledger with the same identifier but different properties already exists {}", toCreate.getRecord(), ledger);
}
}
}
private RecordFromLineNumber<Ledger> toLedger(final CSVRecord csvRecord) {
try {
final String identifier = csvRecord.get(IDENTIFIER_COLUMN);
final String parentLedger = csvRecord.get(PARENT_IDENTIFIER_COLUMN);
final String type = csvRecord.get(TYPE_COLUMN);
String name;
try {
name = csvRecord.get(NAME_COLUMN);
}
catch (final IllegalArgumentException e) {
name = identifier;
}
final boolean show = Boolean.valueOf(csvRecord.get(SHOW_ACCOUNTS_IN_CHART_COLUMN));
final String description = csvRecord.get(DESCRIPTION_COLUMN);
final Ledger ledger = new Ledger();
ledger.setIdentifier(identifier);
ledger.setType(type);
ledger.setName(name);
ledger.setShowAccountsInChart(show);
ledger.setDescription(description);
if (parentLedger != null && !parentLedger.isEmpty())
ledger.setParentLedgerIdentifier(parentLedger);
return new RecordFromLineNumber<>(csvRecord.getRecordNumber(), ledger);
}
catch (final IllegalArgumentException e) {
logger.warn("Parsing failed on record {}", csvRecord.getRecordNumber());
throw e;
}
}
}
| 4,726 |
0 | Create_ds/fineract-cn-accounting/component-test/src/main/java/org/apache/fineract/cn | Create_ds/fineract-cn-accounting/component-test/src/main/java/org/apache/fineract/cn/accounting/TestAccount.java | /*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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.apache.fineract.cn.accounting;
import org.apache.fineract.cn.accounting.api.v1.EventConstants;
import org.apache.fineract.cn.accounting.api.v1.client.AccountAlreadyExistsException;
import org.apache.fineract.cn.accounting.api.v1.client.AccountNotFoundException;
import org.apache.fineract.cn.accounting.api.v1.client.AccountReferenceException;
import org.apache.fineract.cn.accounting.api.v1.domain.Account;
import org.apache.fineract.cn.accounting.api.v1.domain.AccountCommand;
import org.apache.fineract.cn.accounting.api.v1.domain.AccountEntry;
import org.apache.fineract.cn.accounting.api.v1.domain.AccountPage;
import org.apache.fineract.cn.accounting.api.v1.domain.AccountType;
import org.apache.fineract.cn.accounting.api.v1.domain.JournalEntry;
import org.apache.fineract.cn.accounting.api.v1.domain.Ledger;
import org.apache.fineract.cn.accounting.util.AccountGenerator;
import org.apache.fineract.cn.accounting.util.JournalEntryGenerator;
import org.apache.fineract.cn.accounting.util.LedgerGenerator;
import java.time.Clock;
import java.time.LocalDate;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Optional;
import java.util.Set;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import org.apache.commons.lang3.RandomStringUtils;
import org.apache.fineract.cn.lang.DateRange;
import org.junit.Assert;
import org.junit.Test;
public class TestAccount extends AbstractAccountingTest {
@Test
public void shouldCreateAccount() throws Exception {
final Ledger ledger = LedgerGenerator.createRandomLedger();
this.testSubject.createLedger(ledger);
this.eventRecorder.wait(EventConstants.POST_LEDGER, ledger.getIdentifier());
final Account account = AccountGenerator.createRandomAccount(ledger.getIdentifier());
this.testSubject.createAccount(account);
this.eventRecorder.wait(EventConstants.POST_ACCOUNT, account.getIdentifier());
final Account savedAccount = this.testSubject.findAccount(account.getIdentifier());
Assert.assertNotNull(savedAccount);
}
@Test
public void shouldNotCreateAccountAlreadyExists() throws Exception {
final Ledger ledger = LedgerGenerator.createRandomLedger();
this.testSubject.createLedger(ledger);
this.eventRecorder.wait(EventConstants.POST_LEDGER, ledger.getIdentifier());
final Account account = AccountGenerator.createRandomAccount(ledger.getIdentifier());
this.testSubject.createAccount(account);
this.eventRecorder.wait(EventConstants.POST_ACCOUNT, account.getIdentifier());
try {
this.testSubject.createAccount(account);
Assert.fail();
} catch (final AccountAlreadyExistsException ignored) {
}
}
@Test
public void shouldNotCreatedAccountUnknownReferenceAccount() throws Exception {
final Ledger ledger = LedgerGenerator.createRandomLedger();
this.testSubject.createLedger(ledger);
this.eventRecorder.wait(EventConstants.POST_LEDGER, ledger.getIdentifier());
final Account account = AccountGenerator.createRandomAccount(ledger.getIdentifier());
account.setReferenceAccount(RandomStringUtils.randomAlphanumeric(8));
try {
this.testSubject.createAccount(account);
Assert.fail();
} catch (final IllegalArgumentException ex) {
Assert.assertTrue(ex.getMessage().contains(account.getReferenceAccount()));
}
}
@Test
public void shouldNotCreateAccountUnknownLedger() throws Exception {
final Account account = AccountGenerator.createRandomAccount(RandomStringUtils.randomAlphanumeric(8));
try {
this.testSubject.createAccount(account);
Assert.fail();
} catch (final IllegalArgumentException ex) {
Assert.assertTrue(ex.getMessage().contains(account.getLedger()));
}
}
@Test
public void shouldNotCreatedAccountTypeMismatch() throws Exception {
final Ledger ledger = LedgerGenerator.createRandomLedger();
this.testSubject.createLedger(ledger);
this.eventRecorder.wait(EventConstants.POST_LEDGER, ledger.getIdentifier());
final Account account = AccountGenerator.createRandomAccount(ledger.getIdentifier());
account.setType(AccountType.LIABILITY.name());
try {
this.testSubject.createAccount(account);
Assert.fail();
} catch (final IllegalArgumentException ex) {
Assert.assertTrue(ex.getMessage().contains(account.getType()));
}
}
@Test
public void shouldFindAccount() throws Exception {
final Ledger ledger = LedgerGenerator.createRandomLedger();
this.testSubject.createLedger(ledger);
this.eventRecorder.wait(EventConstants.POST_LEDGER, ledger.getIdentifier());
final Account referenceAccount = AccountGenerator.createRandomAccount(ledger.getIdentifier());
this.testSubject.createAccount(referenceAccount);
this.eventRecorder.wait(EventConstants.POST_ACCOUNT, referenceAccount.getIdentifier());
final Account account = AccountGenerator.createRandomAccount(ledger.getIdentifier());
account.setReferenceAccount(referenceAccount.getIdentifier());
this.testSubject.createAccount(account);
this.eventRecorder.wait(EventConstants.POST_ACCOUNT, account.getIdentifier());
final Account savedAccount = this.testSubject.findAccount(account.getIdentifier());
Assert.assertNotNull(savedAccount);
Assert.assertEquals(account.getIdentifier(), savedAccount.getIdentifier());
Assert.assertEquals(account.getName(), savedAccount.getName());
Assert.assertEquals(account.getType(), savedAccount.getType());
Assert.assertEquals(account.getLedger(), savedAccount.getLedger());
Assert.assertEquals(account.getReferenceAccount(), savedAccount.getReferenceAccount());
Assert.assertTrue(account.getHolders().containsAll(savedAccount.getHolders()));
Assert.assertTrue(account.getSignatureAuthorities().containsAll(savedAccount.getSignatureAuthorities()));
Assert.assertEquals(account.getBalance(), savedAccount.getBalance());
Assert.assertNotNull(savedAccount.getCreatedBy());
Assert.assertNotNull(savedAccount.getCreatedOn());
Assert.assertNull(savedAccount.getLastModifiedBy());
Assert.assertNull(savedAccount.getLastModifiedOn());
Assert.assertEquals(Account.State.OPEN.name(), savedAccount.getState());
}
@Test
public void shouldNotFindAccountUnknown() {
final String randomName = RandomStringUtils.randomAlphanumeric(8);
try {
this.testSubject.findAccount(randomName);
Assert.fail();
} catch (final AccountNotFoundException ignored) {
}
}
@Test
public void shouldFetchAccounts() throws Exception {
final AccountPage currentAccountPage =
this.testSubject.fetchAccounts(true, null, null, true, null, null, null, null);
final Ledger ledger = LedgerGenerator.createRandomLedger();
this.testSubject.createLedger(ledger);
this.eventRecorder.wait(EventConstants.POST_LEDGER, ledger.getIdentifier());
final Account account = AccountGenerator.createRandomAccount(ledger.getIdentifier());
this.testSubject.createAccount(account);
this.eventRecorder.wait(EventConstants.POST_ACCOUNT, account.getIdentifier());
final AccountPage accountPage =
this.testSubject.fetchAccounts(true, null, null, true, null, null, null, null);
Assert.assertEquals(currentAccountPage.getTotalElements() + 1L, accountPage.getTotalElements().longValue());
}
@Test
public void shouldFetchAccountForTerm() throws Exception {
final Ledger ledger = LedgerGenerator.createRandomLedger();
this.testSubject.createLedger(ledger);
this.eventRecorder.wait(EventConstants.POST_LEDGER, ledger.getIdentifier());
final Account referenceAccount = AccountGenerator.createRandomAccount(ledger.getIdentifier());
referenceAccount.setIdentifier("001.1");
this.testSubject.createAccount(referenceAccount);
this.eventRecorder.wait(EventConstants.POST_ACCOUNT, referenceAccount.getIdentifier());
final Account account = AccountGenerator.createRandomAccount(ledger.getIdentifier());
account.setIdentifier("001.2");
account.setReferenceAccount(referenceAccount.getIdentifier());
this.testSubject.createAccount(account);
this.eventRecorder.wait(EventConstants.POST_ACCOUNT, account.getIdentifier());
final AccountPage accountPage = this.testSubject.fetchAccounts(
true, "001.", null, true, null, null, null, null);
Assert.assertEquals(Long.valueOf(2L), accountPage.getTotalElements());
}
@Test
public void shouldNotFetchAccountUnknownTerm() throws Exception {
final AccountPage accountPage =
this.testSubject.fetchAccounts(
true, RandomStringUtils.randomAlphanumeric(8), null, true, null, null, null, null);
Assert.assertTrue(accountPage.getTotalElements() == 0);
}
@Test
public void shouldFindOnlyActiveAccounts() throws Exception {
final Ledger ledger = LedgerGenerator.createRandomLedger();
this.testSubject.createLedger(ledger);
this.eventRecorder.wait(EventConstants.POST_LEDGER, ledger.getIdentifier());
final Account referenceAccount = AccountGenerator.createRandomAccount(ledger.getIdentifier());
this.testSubject.createAccount(referenceAccount);
this.eventRecorder.wait(EventConstants.POST_ACCOUNT, referenceAccount.getIdentifier());
final Account account = AccountGenerator.createRandomAccount(ledger.getIdentifier());
account.setReferenceAccount(referenceAccount.getIdentifier());
this.testSubject.createAccount(account);
this.eventRecorder.wait(EventConstants.POST_ACCOUNT, account.getIdentifier());
final AccountCommand accountCommand = new AccountCommand();
accountCommand.setAction(AccountCommand.Action.CLOSE.name());
accountCommand.setComment("close reference!");
this.testSubject.accountCommand(referenceAccount.getIdentifier(), accountCommand);
Assert.assertTrue(this.eventRecorder.wait(EventConstants.CLOSE_ACCOUNT, referenceAccount.getIdentifier()));
final AccountPage accountPage = this.testSubject.fetchAccounts(
false, null, null, true, null, null, null, null);
Assert.assertEquals(Long.valueOf(1), accountPage.getTotalElements());
}
@Test
public void shouldModifyAccount() throws Exception {
final Ledger ledger = LedgerGenerator.createRandomLedger();
this.testSubject.createLedger(ledger);
this.eventRecorder.wait(EventConstants.POST_LEDGER, ledger.getIdentifier());
final Account account = AccountGenerator.createRandomAccount(ledger.getIdentifier());
this.testSubject.createAccount(account);
this.eventRecorder.wait(EventConstants.POST_ACCOUNT, account.getIdentifier());
final Account modifiedAccount = AccountGenerator.createRandomAccount(ledger.getIdentifier());
modifiedAccount.setIdentifier(account.getIdentifier());
modifiedAccount.setType(account.getType());
this.testSubject.modifyAccount(modifiedAccount.getIdentifier(), modifiedAccount);
this.eventRecorder.wait(EventConstants.PUT_ACCOUNT, modifiedAccount.getIdentifier());
final Account fetchedAccount = this.testSubject.findAccount(account.getIdentifier());
Assert.assertNotNull(fetchedAccount);
Assert.assertEquals(modifiedAccount.getIdentifier(), fetchedAccount.getIdentifier());
Assert.assertEquals(modifiedAccount.getType(), fetchedAccount.getType());
Assert.assertEquals(modifiedAccount.getLedger(), fetchedAccount.getLedger());
Assert.assertEquals(modifiedAccount.getReferenceAccount(), fetchedAccount.getReferenceAccount());
Assert.assertTrue(modifiedAccount.getHolders().containsAll(fetchedAccount.getHolders()));
Assert.assertTrue(modifiedAccount.getSignatureAuthorities().containsAll(fetchedAccount.getSignatureAuthorities()));
Assert.assertEquals(modifiedAccount.getBalance(), fetchedAccount.getBalance());
Assert.assertNotNull(fetchedAccount.getCreatedBy());
Assert.assertNotNull(fetchedAccount.getCreatedOn());
Assert.assertNotNull(fetchedAccount.getLastModifiedBy());
Assert.assertNotNull(fetchedAccount.getLastModifiedOn());
Assert.assertEquals(Account.State.OPEN.name(), fetchedAccount.getState());
}
@Test
public void shouldListAccountEntries() throws InterruptedException {
final Ledger ledger = LedgerGenerator.createRandomLedger();
this.testSubject.createLedger(ledger);
this.eventRecorder.wait(EventConstants.POST_LEDGER, ledger.getIdentifier());
final Account debtorAccount = AccountGenerator.createRandomAccount(ledger.getIdentifier());
this.testSubject.createAccount(debtorAccount);
this.eventRecorder.wait(EventConstants.POST_ACCOUNT, debtorAccount.getIdentifier());
final Account creditorAccount = AccountGenerator.createRandomAccount(ledger.getIdentifier());
this.testSubject.createAccount(creditorAccount);
this.eventRecorder.wait(EventConstants.POST_ACCOUNT, creditorAccount.getIdentifier());
final int journaEntryCount = 58;
final List<JournalEntry> randomJournalEntries = Stream.generate(() -> JournalEntryGenerator.createRandomJournalEntry(debtorAccount, "50.00", creditorAccount, "50.00"))
.limit(journaEntryCount)
.collect(Collectors.toList());
randomJournalEntries.stream()
.map(randomJournalEntry -> {
this.testSubject.createJournalEntry(randomJournalEntry);
return randomJournalEntry.getTransactionIdentifier();
})
.forEach(transactionIdentifier -> {
try {
this.eventRecorder.wait(EventConstants.POST_JOURNAL_ENTRY, transactionIdentifier);
this.eventRecorder.wait(EventConstants.RELEASE_JOURNAL_ENTRY, transactionIdentifier);
}
catch (final InterruptedException e) {
throw new RuntimeException(e);
}
});
Thread.sleep(300L); // Short pause to make sure it really is last.
final JournalEntry lastRandomJournalEntry = JournalEntryGenerator.createRandomJournalEntry(debtorAccount, "50.00", creditorAccount, "50.00");
this.testSubject.createJournalEntry(lastRandomJournalEntry);
this.eventRecorder.wait(EventConstants.POST_JOURNAL_ENTRY, lastRandomJournalEntry.getTransactionIdentifier());
this.eventRecorder.wait(EventConstants.RELEASE_JOURNAL_ENTRY, lastRandomJournalEntry.getTransactionIdentifier());
final Set<String> journalEntryMessages
= randomJournalEntries.stream().map(JournalEntry::getMessage).collect(Collectors.toSet());
journalEntryMessages.add(lastRandomJournalEntry.getMessage());
final LocalDate today = LocalDate.now(Clock.systemUTC());
final String todayDateRange = new DateRange(today, today).toString();
final List<AccountEntry> accountEntriesForward = this.testSubject.fetchAccountEntriesStream(creditorAccount.getIdentifier(),
todayDateRange, null, "ASC")
.collect(Collectors.toList());
final Set<String> accountEntryMessages = accountEntriesForward.stream()
.map(AccountEntry::getMessage)
.collect(Collectors.toSet());
Assert.assertEquals(journalEntryMessages, accountEntryMessages);
Assert.assertEquals(journaEntryCount + 1, accountEntryMessages.size());
final String oneMessage = accountEntryMessages.iterator().next();
final List<AccountEntry> oneAccountEntry = this.testSubject.fetchAccountEntriesStream(creditorAccount.getIdentifier(),
todayDateRange, oneMessage, "ASC").collect(Collectors.toList());
Assert.assertEquals(1, oneAccountEntry.size());
Assert.assertEquals(oneMessage, oneAccountEntry.get(0).getMessage());
final List<AccountEntry> accountEntriesBackward = this.testSubject
.fetchAccountEntriesStream(
creditorAccount.getIdentifier(),
todayDateRange,
null, "DESC")
.collect(Collectors.toList());
final Optional<AccountEntry> lastAccountEntry = accountEntriesBackward.stream().findFirst();
Assert.assertTrue(lastAccountEntry.isPresent());
Assert.assertEquals(lastRandomJournalEntry.getMessage(), lastAccountEntry.get().getMessage());
Collections.reverse(accountEntriesBackward);
Assert.assertEquals(accountEntriesBackward, accountEntriesForward);
}
@Test
public void shouldCloseAccount() throws Exception {
final Ledger randomLedger = LedgerGenerator.createRandomLedger();
this.testSubject.createLedger(randomLedger);
this.eventRecorder.wait(EventConstants.POST_LEDGER, randomLedger.getIdentifier());
final Account randomAccount = AccountGenerator.createRandomAccount(randomLedger.getIdentifier());
this.testSubject.createAccount(randomAccount);
this.eventRecorder.wait(EventConstants.POST_ACCOUNT, randomAccount.getIdentifier());
final AccountCommand accountCommand = new AccountCommand();
accountCommand.setAction(AccountCommand.Action.CLOSE.name());
accountCommand.setComment("close this!");
this.testSubject.accountCommand(randomAccount.getIdentifier(), accountCommand);
Assert.assertTrue(this.eventRecorder.wait(EventConstants.CLOSE_ACCOUNT, randomAccount.getIdentifier()));
}
@Test
public void shouldReopenAccount() throws Exception {
final Ledger randomLedger = LedgerGenerator.createRandomLedger();
this.testSubject.createLedger(randomLedger);
this.eventRecorder.wait(EventConstants.POST_LEDGER, randomLedger.getIdentifier());
final Account randomAccount = AccountGenerator.createRandomAccount(randomLedger.getIdentifier());
this.testSubject.createAccount(randomAccount);
this.eventRecorder.wait(EventConstants.POST_ACCOUNT, randomAccount.getIdentifier());
final AccountCommand closeAccountCommand = new AccountCommand();
closeAccountCommand.setAction(AccountCommand.Action.CLOSE.name());
closeAccountCommand.setComment("close this!");
this.testSubject.accountCommand(randomAccount.getIdentifier(), closeAccountCommand);
this.eventRecorder.wait(EventConstants.CLOSE_ACCOUNT, randomAccount.getIdentifier());
final AccountCommand reopenAccountCommand = new AccountCommand();
reopenAccountCommand.setAction(AccountCommand.Action.REOPEN.name());
reopenAccountCommand.setComment("reopen it!");
this.testSubject.accountCommand(randomAccount.getIdentifier(), reopenAccountCommand);
Assert.assertTrue(this.eventRecorder.wait(EventConstants.REOPEN_ACCOUNT, randomAccount.getIdentifier()));
}
@Test
public void shouldLockAccount() throws Exception {
final Ledger randomLedger = LedgerGenerator.createRandomLedger();
this.testSubject.createLedger(randomLedger);
this.eventRecorder.wait(EventConstants.POST_LEDGER, randomLedger.getIdentifier());
final Account randomAccount = AccountGenerator.createRandomAccount(randomLedger.getIdentifier());
this.testSubject.createAccount(randomAccount);
this.eventRecorder.wait(EventConstants.POST_ACCOUNT, randomAccount.getIdentifier());
final AccountCommand accountCommand = new AccountCommand();
accountCommand.setAction(AccountCommand.Action.LOCK.name());
accountCommand.setComment("lock this!");
this.testSubject.accountCommand(randomAccount.getIdentifier(), accountCommand);
Assert.assertTrue(this.eventRecorder.wait(EventConstants.LOCK_ACCOUNT, randomAccount.getIdentifier()));
}
@Test
public void shouldUnlockAccount() throws Exception {
final Ledger randomLedger = LedgerGenerator.createRandomLedger();
this.testSubject.createLedger(randomLedger);
this.eventRecorder.wait(EventConstants.POST_LEDGER, randomLedger.getIdentifier());
final Account randomAccount = AccountGenerator.createRandomAccount(randomLedger.getIdentifier());
this.testSubject.createAccount(randomAccount);
this.eventRecorder.wait(EventConstants.POST_ACCOUNT, randomAccount.getIdentifier());
final AccountCommand lockAccountCommand = new AccountCommand();
lockAccountCommand.setAction(AccountCommand.Action.LOCK.name());
lockAccountCommand.setComment("lock this!");
this.testSubject.accountCommand(randomAccount.getIdentifier(), lockAccountCommand);
this.eventRecorder.wait(EventConstants.LOCK_ACCOUNT, randomAccount.getIdentifier());
final AccountCommand unlockAccountCommand = new AccountCommand();
unlockAccountCommand.setAction(AccountCommand.Action.UNLOCK.name());
unlockAccountCommand.setComment("unlock it!");
this.testSubject.accountCommand(randomAccount.getIdentifier(), unlockAccountCommand);
Assert.assertTrue(this.eventRecorder.wait(EventConstants.UNLOCK_ACCOUNT, randomAccount.getIdentifier()));
}
@Test
public void shouldDeleteAccount() throws Exception {
final Ledger randomLedger = LedgerGenerator.createRandomLedger();
this.testSubject.createLedger(randomLedger);
this.eventRecorder.wait(EventConstants.POST_LEDGER, randomLedger.getIdentifier());
final Account randomAccount = AccountGenerator.createRandomAccount(randomLedger.getIdentifier());
this.testSubject.createAccount(randomAccount);
this.eventRecorder.wait(EventConstants.POST_ACCOUNT, randomAccount.getIdentifier());
final AccountCommand accountCommand = new AccountCommand();
accountCommand.setAction(AccountCommand.Action.CLOSE.name());
accountCommand.setComment("close this!");
this.testSubject.accountCommand(randomAccount.getIdentifier(), accountCommand);
this.eventRecorder.wait(EventConstants.CLOSE_ACCOUNT, randomAccount.getIdentifier());
this.testSubject.deleteAccount(randomAccount.getIdentifier());
Assert.assertTrue(this.eventRecorder.wait(EventConstants.DELETE_ACCOUNT, randomAccount.getIdentifier()));
}
@Test
public void shouldNotDeleteAccountStillOpen() throws Exception {
final Ledger randomLedger = LedgerGenerator.createRandomLedger();
this.testSubject.createLedger(randomLedger);
this.eventRecorder.wait(EventConstants.POST_LEDGER, randomLedger.getIdentifier());
final Account randomAccount = AccountGenerator.createRandomAccount(randomLedger.getIdentifier());
this.testSubject.createAccount(randomAccount);
this.eventRecorder.wait(EventConstants.POST_ACCOUNT, randomAccount.getIdentifier());
try {
this.testSubject.deleteAccount(randomAccount.getIdentifier());
Assert.fail();
} catch (final AccountReferenceException ex) {
// do nothing, expected
}
}
@Test
public void shouldNotDeleteAccountEntriesExists() throws Exception {
final Ledger assetLedger = LedgerGenerator.createRandomLedger();
assetLedger.setType(AccountType.LIABILITY.name());
this.testSubject.createLedger(assetLedger);
this.eventRecorder.wait(EventConstants.POST_LEDGER, assetLedger.getIdentifier());
final Account debtorAccount = AccountGenerator.createRandomAccount(assetLedger.getIdentifier());
debtorAccount.setType(AccountType.LIABILITY.name());
debtorAccount.setBalance(100.00D);
this.testSubject.createAccount(debtorAccount);
this.eventRecorder.wait(EventConstants.POST_ACCOUNT, debtorAccount.getIdentifier());
final Ledger liabilityLedger = LedgerGenerator.createRandomLedger();
liabilityLedger.setType(AccountType.LIABILITY.name());
this.testSubject.createLedger(liabilityLedger);
this.eventRecorder.wait(EventConstants.POST_LEDGER, liabilityLedger.getIdentifier());
final Account creditorAccount = AccountGenerator.createRandomAccount(liabilityLedger.getIdentifier());
creditorAccount.setType(AccountType.LIABILITY.name());
creditorAccount.setBalance(100.00D);
this.testSubject.createAccount(creditorAccount);
this.eventRecorder.wait(EventConstants.POST_ACCOUNT, creditorAccount.getIdentifier());
final JournalEntry journalEntry = JournalEntryGenerator.createRandomJournalEntry(debtorAccount, "100.00",
creditorAccount, "100.00");
this.testSubject.createJournalEntry(journalEntry);
this.eventRecorder.wait(EventConstants.POST_JOURNAL_ENTRY, journalEntry.getTransactionIdentifier());
this.eventRecorder.wait(EventConstants.RELEASE_JOURNAL_ENTRY, journalEntry.getTransactionIdentifier());
final AccountCommand closeAccountCommand = new AccountCommand();
closeAccountCommand.setAction(AccountCommand.Action.CLOSE.name());
closeAccountCommand.setComment("close this!");
this.testSubject.accountCommand(debtorAccount.getIdentifier(), closeAccountCommand);
this.eventRecorder.wait(EventConstants.CLOSE_ACCOUNT, debtorAccount.getIdentifier());
try {
this.testSubject.deleteAccount(debtorAccount.getIdentifier());
Assert.fail();
} catch (final AccountReferenceException ex) {
// do nothing, expected
}
}
@Test
public void shouldNotDeleteAccountIsReferenced() throws Exception {
final Ledger randomLedger = LedgerGenerator.createRandomLedger();
this.testSubject.createLedger(randomLedger);
this.eventRecorder.wait(EventConstants.POST_LEDGER, randomLedger.getIdentifier());
final Account randomAccount = AccountGenerator.createRandomAccount(randomLedger.getIdentifier());
this.testSubject.createAccount(randomAccount);
this.eventRecorder.wait(EventConstants.POST_ACCOUNT, randomAccount.getIdentifier());
final Account referencingAccount = AccountGenerator.createRandomAccount(randomLedger.getIdentifier());
referencingAccount.setReferenceAccount(randomAccount.getIdentifier());
this.testSubject.createAccount(referencingAccount);
this.eventRecorder.wait(EventConstants.POST_ACCOUNT, referencingAccount.getIdentifier());
try {
this.testSubject.deleteAccount(randomAccount.getIdentifier());
Assert.fail();
} catch (final AccountReferenceException ex) {
// do nothing, expected
}
}
@Test
public void shouldReturnOnlyAvailableCommands() throws Exception {
final Ledger randomLedger = LedgerGenerator.createRandomLedger();
this.testSubject.createLedger(randomLedger);
this.eventRecorder.wait(EventConstants.POST_LEDGER, randomLedger.getIdentifier());
final Account randomAccount = AccountGenerator.createRandomAccount(randomLedger.getIdentifier());
this.testSubject.createAccount(randomAccount);
this.eventRecorder.wait(EventConstants.POST_ACCOUNT, randomAccount.getIdentifier());
final List<AccountCommand> openAccountCommands = super.testSubject.fetchActions(randomAccount.getIdentifier());
Assert.assertEquals(2, openAccountCommands.size());
Assert.assertEquals(AccountCommand.Action.LOCK.name(), openAccountCommands.get(0).getAction());
Assert.assertEquals(AccountCommand.Action.CLOSE.name(), openAccountCommands.get(1).getAction());
final AccountCommand lockAccountCommand = new AccountCommand();
lockAccountCommand.setAction(AccountCommand.Action.LOCK.name());
lockAccountCommand.setComment("lock this!");
this.testSubject.accountCommand(randomAccount.getIdentifier(), lockAccountCommand);
this.eventRecorder.wait(EventConstants.LOCK_ACCOUNT, randomAccount.getIdentifier());
final List<AccountCommand> lockedAccountCommands = super.testSubject.fetchActions(randomAccount.getIdentifier());
Assert.assertEquals(2, lockedAccountCommands.size());
Assert.assertEquals(AccountCommand.Action.UNLOCK.name(), lockedAccountCommands.get(0).getAction());
Assert.assertEquals(AccountCommand.Action.CLOSE.name(), lockedAccountCommands.get(1).getAction());
final AccountCommand unlockAccountCommand = new AccountCommand();
unlockAccountCommand.setAction(AccountCommand.Action.UNLOCK.name());
unlockAccountCommand.setComment("unlock this!");
this.testSubject.accountCommand(randomAccount.getIdentifier(), unlockAccountCommand);
this.eventRecorder.wait(EventConstants.UNLOCK_ACCOUNT, randomAccount.getIdentifier());
final List<AccountCommand> unlockedAccountCommands = super.testSubject.fetchActions(randomAccount.getIdentifier());
Assert.assertEquals(2, unlockedAccountCommands.size());
Assert.assertEquals(AccountCommand.Action.LOCK.name(), unlockedAccountCommands.get(0).getAction());
Assert.assertEquals(AccountCommand.Action.CLOSE.name(), unlockedAccountCommands.get(1).getAction());
final AccountCommand closeAccountCommand = new AccountCommand();
closeAccountCommand.setAction(AccountCommand.Action.CLOSE.name());
closeAccountCommand.setComment("unlock this!");
this.testSubject.accountCommand(randomAccount.getIdentifier(), closeAccountCommand);
this.eventRecorder.wait(EventConstants.CLOSE_ACCOUNT, randomAccount.getIdentifier());
final List<AccountCommand> closedAccountCommands = super.testSubject.fetchActions(randomAccount.getIdentifier());
Assert.assertEquals(1, closedAccountCommands.size());
Assert.assertEquals(AccountCommand.Action.REOPEN.name(), closedAccountCommands.get(0).getAction());
}
@Test
public void shouldFetchAccountsWithEmptyHolder() throws Exception {
final Ledger ledger = LedgerGenerator.createLedger("noholder-10000", AccountType.EQUITY);
this.testSubject.createLedger(ledger);
this.eventRecorder.wait(EventConstants.POST_LEDGER, ledger.getIdentifier());
final Account account1 =
AccountGenerator.createAccount(ledger.getIdentifier(), "noholder-10001", AccountType.EQUITY);
account1.setHolders(null);
this.testSubject.createAccount(account1);
this.eventRecorder.wait(EventConstants.POST_ACCOUNT, account1.getIdentifier());
final Account account2 =
AccountGenerator.createAccount(ledger.getIdentifier(), "noholder-10002", AccountType.EQUITY);
account2.setHolders(new HashSet<>());
this.testSubject.createAccount(account2);
this.eventRecorder.wait(EventConstants.POST_ACCOUNT, account2.getIdentifier());
final AccountPage accountPage =
this.testSubject.fetchAccounts(false, "noholder", AccountType.EQUITY.name(), false, null, null, null, null);
Assert.assertEquals(2L, accountPage.getTotalElements().longValue());
}
@Test
public void shouldFindAccountWithAlternativeAccountNumber() throws Exception {
final Ledger ledger = LedgerGenerator.createLedger("alt-account-10000", AccountType.EQUITY);
this.testSubject.createLedger(ledger);
this.eventRecorder.wait(EventConstants.POST_LEDGER, ledger.getIdentifier());
final Account altAccount =
AccountGenerator.createAccount(ledger.getIdentifier(), "alt-account-10001", AccountType.EQUITY);
altAccount.setAlternativeAccountNumber("08154711");
this.testSubject.createAccount(altAccount);
this.eventRecorder.wait(EventConstants.POST_ACCOUNT, altAccount.getIdentifier());
final AccountPage accountPage = this.testSubject.fetchAccounts(true, "08154711", null, true,
0, 10, null, null);
Assert.assertEquals(Long.valueOf(1L), accountPage.getTotalElements());
final Account account = accountPage.getAccounts().get(0);
Assert.assertEquals("alt-account-10001", account.getIdentifier());
Assert.assertEquals("08154711", account.getAlternativeAccountNumber());
}
}
| 4,727 |
0 | Create_ds/fineract-cn-accounting/component-test/src/main/java/org/apache/fineract/cn | Create_ds/fineract-cn-accounting/component-test/src/main/java/org/apache/fineract/cn/accounting/FinancialConditionApiDocumentation.java | /*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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.apache.fineract.cn.accounting;
import org.apache.fineract.cn.accounting.api.v1.EventConstants;
import org.apache.fineract.cn.accounting.api.v1.domain.Account;
import org.apache.fineract.cn.accounting.api.v1.domain.AccountType;
import org.apache.fineract.cn.accounting.api.v1.domain.JournalEntry;
import org.apache.fineract.cn.accounting.api.v1.domain.Ledger;
import org.apache.fineract.cn.accounting.util.AccountGenerator;
import org.apache.fineract.cn.accounting.util.JournalEntryGenerator;
import org.apache.fineract.cn.accounting.util.LedgerGenerator;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.restdocs.JUnitRestDocumentation;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
import org.springframework.web.context.WebApplicationContext;
import static org.springframework.restdocs.mockmvc.MockMvcRestDocumentation.document;
import static org.springframework.restdocs.mockmvc.MockMvcRestDocumentation.documentationConfiguration;
import static org.springframework.restdocs.mockmvc.RestDocumentationRequestBuilders.get;
import static org.springframework.restdocs.operation.preprocess.Preprocessors.preprocessRequest;
import static org.springframework.restdocs.operation.preprocess.Preprocessors.preprocessResponse;
import static org.springframework.restdocs.operation.preprocess.Preprocessors.prettyPrint;
import static org.springframework.restdocs.payload.PayloadDocumentation.fieldWithPath;
import static org.springframework.restdocs.payload.PayloadDocumentation.responseFields;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
public class FinancialConditionApiDocumentation extends AbstractAccountingTest {
@Rule
public final JUnitRestDocumentation restDocumentation = new JUnitRestDocumentation("build/doc/generated-snippets/test-financial-condition");
@Autowired
private WebApplicationContext context;
private MockMvc mockMvc;
@Before
public void setUp ( ) {
this.mockMvc = MockMvcBuilders.webAppContextSetup(this.context)
.apply(documentationConfiguration(this.restDocumentation))
.alwaysDo(document("{method-name}", preprocessRequest(prettyPrint()), preprocessResponse(prettyPrint())))
.build();
}
@Test
public void documentReturnFinancialCondition ( ) throws Exception {
this.fixtures();
this.sampleJournalEntries();
this.mockMvc.perform(get("/financialcondition")
.contentType(MediaType.APPLICATION_JSON_VALUE)
.accept(MediaType.ALL_VALUE))
.andExpect(status().isOk())
.andDo(document("document-return-financial-condition", preprocessRequest(prettyPrint()), preprocessResponse(prettyPrint()),
responseFields(
fieldWithPath("date").description("String").description("Date of Financial Condition Preparation"),
fieldWithPath("financialConditionSections[].type").description("Type").description("Type of assets section " +
" + \n" +
" + \n" +
" *enum* _Type_ { + \n" +
" ASSET, + \n" +
" EQUITY, + \n" +
" LIABILITY, + \n" +
"}"),
fieldWithPath("financialConditionSections[].description").type("String").description("first section's description"),
fieldWithPath("financialConditionSections[].financialConditionEntries[].description").type("String").description("first entry's description"),
fieldWithPath("financialConditionSections[].financialConditionEntries[].value").type("BigDecimal").description("first entry's value"),
fieldWithPath("financialConditionSections[].financialConditionEntries[1].description").type("String").description("second entry's description"),
fieldWithPath("financialConditionSections[].financialConditionEntries[1].value").type("BigDecimal").description("second entry's value"),
fieldWithPath("financialConditionSections[].subtotal").type("BigDecimal").description("First section's subtotal"),
fieldWithPath("financialConditionSections[1].type").description("Type").description("Type of first section " +
" + \n" +
" + \n" +
" *enum* _Type_ { + \n" +
" INCOME, + \n" +
" EXPENSES + \n" +
"}"),
fieldWithPath("financialConditionSections[1].description").type("String").description("first section's description"),
fieldWithPath("financialConditionSections[1].financialConditionEntries[].description").type("String").description("first entry's description"),
fieldWithPath("financialConditionSections[1].financialConditionEntries[].value").type("BigDecimal").description("first entry's value"),
fieldWithPath("financialConditionSections[1].subtotal").type("BigDecimal").description("Second section's subtotal"),
fieldWithPath("financialConditionSections[2].type").description("Type").description("Type of Equity & liability section " +
" + \n" +
" + \n" +
" *enum* _Type_ { + \n" +
" ASSET, + \n" +
" EQUITY, + \n" +
" LIABILITY, + \n" +
"}"),
fieldWithPath("financialConditionSections[2].description").type("String").description("liability section's description"),
fieldWithPath("financialConditionSections[2].financialConditionEntries[].description").type("String").description("first entry's description"),
fieldWithPath("financialConditionSections[2].financialConditionEntries[].value").type("BigDecimal").description("first entry's value"),
fieldWithPath("financialConditionSections[2].financialConditionEntries[1].description").type("String").description("second entry's description"),
fieldWithPath("financialConditionSections[2].financialConditionEntries[1].value").type("BigDecimal").description("second entry's value"),
fieldWithPath("financialConditionSections[2].subtotal").type("BigDecimal").description("First section's subtotal"),
fieldWithPath("totalAssets").type("BigDecimal").description("Gross Profit"),
fieldWithPath("totalEquitiesAndLiabilities").type("BigDecimal").description("Total Expenses")
)));
}
private void fixtures ( ) throws Exception {
final Ledger assetLedger = LedgerGenerator.createLedger("7000", AccountType.ASSET);
assetLedger.setName("Assets");
super.testSubject.createLedger(assetLedger);
Assert.assertTrue(super.eventRecorder.wait(EventConstants.POST_LEDGER, assetLedger.getIdentifier()));
final Ledger assetSubLedger7060 = LedgerGenerator.createLedger("7060", AccountType.ASSET);
assetSubLedger7060.setParentLedgerIdentifier(assetLedger.getParentLedgerIdentifier());
assetSubLedger7060.setName("Loans to Members");
super.testSubject.addSubLedger(assetLedger.getIdentifier(), assetSubLedger7060);
Assert.assertTrue(super.eventRecorder.wait(EventConstants.POST_LEDGER, assetSubLedger7060.getIdentifier()));
final Ledger assetSubLedger7080 = LedgerGenerator.createLedger("7080", AccountType.ASSET);
assetSubLedger7080.setParentLedgerIdentifier(assetLedger.getParentLedgerIdentifier());
assetSubLedger7080.setName("Lines of Credit to Members");
super.testSubject.addSubLedger(assetLedger.getIdentifier(), assetSubLedger7080);
Assert.assertTrue(super.eventRecorder.wait(EventConstants.POST_LEDGER, assetSubLedger7080.getIdentifier()));
final Account firstAssetAccount =
AccountGenerator.createAccount(assetSubLedger7060.getIdentifier(), "7061", AccountType.ASSET);
super.testSubject.createAccount(firstAssetAccount);
Assert.assertTrue(super.eventRecorder.wait(EventConstants.POST_ACCOUNT, firstAssetAccount.getIdentifier()));
final Account secondAssetAccount =
AccountGenerator.createAccount(assetSubLedger7080.getIdentifier(), "7081", AccountType.ASSET);
super.testSubject.createAccount(secondAssetAccount);
Assert.assertTrue(super.eventRecorder.wait(EventConstants.POST_ACCOUNT, secondAssetAccount.getIdentifier()));
final Ledger liabilityLedger = LedgerGenerator.createLedger("8000", AccountType.LIABILITY);
liabilityLedger.setName("Liabilities");
super.testSubject.createLedger(liabilityLedger);
Assert.assertTrue(super.eventRecorder.wait(EventConstants.POST_LEDGER, liabilityLedger.getIdentifier()));
final Ledger liabilitySubLedger8110 = LedgerGenerator.createLedger("8110", AccountType.LIABILITY);
liabilitySubLedger8110.setParentLedgerIdentifier(liabilityLedger.getParentLedgerIdentifier());
liabilitySubLedger8110.setName("Accounts Payable");
super.testSubject.addSubLedger(liabilityLedger.getIdentifier(), liabilitySubLedger8110);
Assert.assertTrue(super.eventRecorder.wait(EventConstants.POST_LEDGER, liabilitySubLedger8110.getIdentifier()));
final Ledger liabilitySubLedger8220 = LedgerGenerator.createLedger("8220", AccountType.LIABILITY);
liabilitySubLedger8220.setParentLedgerIdentifier(liabilityLedger.getParentLedgerIdentifier());
liabilitySubLedger8220.setName("Interest Payable");
super.testSubject.addSubLedger(liabilityLedger.getIdentifier(), liabilitySubLedger8220);
Assert.assertTrue(super.eventRecorder.wait(EventConstants.POST_LEDGER, liabilitySubLedger8220.getIdentifier()));
final Account firstLiabilityAccount =
AccountGenerator.createAccount(liabilitySubLedger8110.getIdentifier(), "8110", AccountType.LIABILITY);
super.testSubject.createAccount(firstLiabilityAccount);
Assert.assertTrue(super.eventRecorder.wait(EventConstants.POST_ACCOUNT, firstLiabilityAccount.getIdentifier()));
final Account secondLiabilityAccount =
AccountGenerator.createAccount(liabilitySubLedger8220.getIdentifier(), "8220", AccountType.LIABILITY);
super.testSubject.createAccount(secondLiabilityAccount);
Assert.assertTrue(super.eventRecorder.wait(EventConstants.POST_ACCOUNT, secondLiabilityAccount.getIdentifier()));
final Ledger equityLedger = LedgerGenerator.createLedger("9000", AccountType.EQUITY);
equityLedger.setName("Equities");
super.testSubject.createLedger(equityLedger);
Assert.assertTrue(super.eventRecorder.wait(EventConstants.POST_LEDGER, equityLedger.getIdentifier()));
final Ledger equitySubLedger9120 = LedgerGenerator.createLedger("9120", AccountType.EQUITY);
equitySubLedger9120.setParentLedgerIdentifier(equityLedger.getParentLedgerIdentifier());
equitySubLedger9120.setName("Member Savings");
super.testSubject.addSubLedger(equityLedger.getIdentifier(), equitySubLedger9120);
Assert.assertTrue(super.eventRecorder.wait(EventConstants.POST_LEDGER, equitySubLedger9120.getIdentifier()));
final Account firstEquityAccount =
AccountGenerator.createAccount(equitySubLedger9120.getIdentifier(), "9120", AccountType.EQUITY);
super.testSubject.createAccount(firstEquityAccount);
Assert.assertTrue(super.eventRecorder.wait(EventConstants.POST_ACCOUNT, firstEquityAccount.getIdentifier()));
}
private void sampleJournalEntries ( ) throws Exception {
final JournalEntry firstTransaction =
JournalEntryGenerator
.createRandomJournalEntry("7061", "150.00", "8110", "150.00");
super.testSubject.createJournalEntry(firstTransaction);
Assert.assertTrue(super.eventRecorder.wait(EventConstants.POST_JOURNAL_ENTRY, firstTransaction.getTransactionIdentifier()));
final JournalEntry secondTransaction =
JournalEntryGenerator
.createRandomJournalEntry("7081", "100.00", "8220", "100.00");
super.testSubject.createJournalEntry(secondTransaction);
Assert.assertTrue(super.eventRecorder.wait(EventConstants.POST_JOURNAL_ENTRY, secondTransaction.getTransactionIdentifier()));
final JournalEntry thirdTransaction =
JournalEntryGenerator
.createRandomJournalEntry("8220", "50.00", "9120", "50.00");
super.testSubject.createJournalEntry(thirdTransaction);
Assert.assertTrue(super.eventRecorder.wait(EventConstants.POST_JOURNAL_ENTRY, thirdTransaction.getTransactionIdentifier()));
}
}
| 4,728 |
0 | Create_ds/fineract-cn-accounting/component-test/src/main/java/org/apache/fineract/cn | Create_ds/fineract-cn-accounting/component-test/src/main/java/org/apache/fineract/cn/accounting/ChartOfAccountsApiDocumentation.java | /*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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.apache.fineract.cn.accounting;
import org.apache.fineract.cn.accounting.api.v1.EventConstants;
import org.apache.fineract.cn.accounting.api.v1.domain.Account;
import org.apache.fineract.cn.accounting.api.v1.domain.AccountType;
import org.apache.fineract.cn.accounting.api.v1.domain.Ledger;
import org.apache.fineract.cn.accounting.util.AccountGenerator;
import org.apache.fineract.cn.accounting.util.LedgerGenerator;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.restdocs.JUnitRestDocumentation;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
import org.springframework.web.context.WebApplicationContext;
import static org.springframework.restdocs.mockmvc.MockMvcRestDocumentation.document;
import static org.springframework.restdocs.mockmvc.MockMvcRestDocumentation.documentationConfiguration;
import static org.springframework.restdocs.mockmvc.RestDocumentationRequestBuilders.get;
import static org.springframework.restdocs.operation.preprocess.Preprocessors.preprocessRequest;
import static org.springframework.restdocs.operation.preprocess.Preprocessors.preprocessResponse;
import static org.springframework.restdocs.operation.preprocess.Preprocessors.prettyPrint;
import static org.springframework.restdocs.payload.PayloadDocumentation.fieldWithPath;
import static org.springframework.restdocs.payload.PayloadDocumentation.responseFields;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
public class ChartOfAccountsApiDocumentation extends AbstractAccountingTest {
@Rule
public final JUnitRestDocumentation restDocumentation = new JUnitRestDocumentation("build/doc/generated-snippets/test-chart-of-accounts");
@Autowired
private WebApplicationContext context;
private MockMvc mockMvc;
@Before
public void setUp ( ) {
this.mockMvc = MockMvcBuilders.webAppContextSetup(this.context)
.apply(documentationConfiguration(this.restDocumentation))
.alwaysDo(document("{method-name}", preprocessRequest(prettyPrint()), preprocessResponse(prettyPrint())))
.build();
}
@Test
public void documentShowChartOfAccounts ( ) throws Exception {
final Ledger parentRevenueLedger = LedgerGenerator.createLedger("10000", AccountType.REVENUE);
parentRevenueLedger.setName("Parent Revenue");
parentRevenueLedger.setDescription("Parent Revenue Ledger");
this.testSubject.createLedger(parentRevenueLedger);
this.eventRecorder.wait(EventConstants.POST_LEDGER, parentRevenueLedger.getIdentifier());
final Ledger interestRevenueLedger = LedgerGenerator.createLedger("11000", AccountType.REVENUE);
interestRevenueLedger.setName("Interest Revenue");
interestRevenueLedger.setDescription("Interest Revenue Ledger");
this.testSubject.addSubLedger(parentRevenueLedger.getIdentifier(), interestRevenueLedger);
this.eventRecorder.wait(EventConstants.POST_LEDGER, interestRevenueLedger.getIdentifier());
final Account consumerInterestRevenueAccount =
AccountGenerator.createAccount(interestRevenueLedger.getIdentifier(), "11100", AccountType.REVENUE);
consumerInterestRevenueAccount.setName("Consumer Interest");
this.testSubject.createAccount(consumerInterestRevenueAccount);
this.eventRecorder.wait(EventConstants.POST_ACCOUNT, consumerInterestRevenueAccount.getIdentifier());
final Ledger feeRevenueLedger = LedgerGenerator.createLedger("12000", AccountType.REVENUE);
feeRevenueLedger.setName("Fee Revenue");
feeRevenueLedger.setDescription("Fee Revenue Ledger");
this.testSubject.addSubLedger(parentRevenueLedger.getIdentifier(), feeRevenueLedger);
this.eventRecorder.wait(EventConstants.POST_LEDGER, feeRevenueLedger.getIdentifier());
final Ledger specialFeeRevenueLedger = LedgerGenerator.createLedger("12100", AccountType.REVENUE);
specialFeeRevenueLedger.setName("Special Fee Revenue");
specialFeeRevenueLedger.setDescription("Special Fee Revenue");
this.testSubject.addSubLedger(feeRevenueLedger.getIdentifier(), specialFeeRevenueLedger);
this.eventRecorder.wait(EventConstants.POST_LEDGER, specialFeeRevenueLedger.getIdentifier());
final Ledger parentAssetLedger = LedgerGenerator.createLedger("70000", AccountType.ASSET);
parentAssetLedger.setName("Parent Asset");
parentAssetLedger.setDescription("Parent Asset Ledger");
this.testSubject.createLedger(parentAssetLedger);
this.eventRecorder.wait(EventConstants.POST_LEDGER, parentAssetLedger.getIdentifier());
final Ledger consumerLoanAssetLedger = LedgerGenerator.createLedger("73000", AccountType.ASSET);
consumerInterestRevenueAccount.setName("Consumer Loan");
consumerLoanAssetLedger.setDescription("Consumer Loan Asset Ledger");
consumerLoanAssetLedger.setShowAccountsInChart(Boolean.FALSE);
this.testSubject.addSubLedger(parentAssetLedger.getIdentifier(), consumerLoanAssetLedger);
this.eventRecorder.wait(EventConstants.POST_LEDGER, consumerLoanAssetLedger.getIdentifier());
for (int i = 1; i < 100; i++) {
final String identifier = Integer.valueOf(73000 + i).toString();
final Account consumerLoanAccount =
AccountGenerator.createAccount(consumerLoanAssetLedger.getIdentifier(), identifier, AccountType.ASSET);
this.testSubject.createAccount(consumerLoanAccount);
this.eventRecorder.wait(EventConstants.POST_ACCOUNT, identifier);
}
this.mockMvc.perform(get("/chartofaccounts")
.contentType(MediaType.APPLICATION_JSON_VALUE)
.accept(MediaType.ALL_VALUE))
.andExpect(status().isOk())
.andDo(document("document-show-chart-of-accounts", preprocessRequest(prettyPrint()), preprocessResponse(prettyPrint()),
responseFields(
fieldWithPath("[].code").description("String").description("Date of Financial Condition Preparation"),
fieldWithPath("[].name").description("String").description("Type of assets section " +
" + \n" +
" + \n" +
" *enum* _Type_ { + \n" +
" ASSET, + \n" +
" EQUITY, + \n" +
" LIABILITY, + \n" +
"}"),
fieldWithPath("[].description").type("String").description("first section's description"),
fieldWithPath("[].type").type("String").description("first entry's description"),
fieldWithPath("[].level").type("Integer").description("first entry's value"),
fieldWithPath("[1].code").description("String").description("Date of Financial Condition Preparation"),
fieldWithPath("[1].name").description("String").description("Type of assets section " +
" + \n" +
" + \n" +
" *enum* _Type_ { + \n" +
" ASSET, + \n" +
" EQUITY, + \n" +
" LIABILITY, + \n" +
"}"),
fieldWithPath("[1].type").type("String").description("first entry's description"),
fieldWithPath("[1].level").type("Integer").description("first entry's value"),
fieldWithPath("[2].code").description("String").description("Date of Financial Condition Preparation"),
fieldWithPath("[2].name").description("String").description("Type of assets section " +
" + \n" +
" + \n" +
" *enum* _Type_ { + \n" +
" ASSET, + \n" +
" EQUITY, + \n" +
" LIABILITY, + \n" +
"}"),
fieldWithPath("[2].type").type("String").description("first entry's description"),
fieldWithPath("[2].level").type("Integer").description("first entry's value"),
fieldWithPath("[3].code").description("String").description("Date of Financial Condition Preparation"),
fieldWithPath("[3].name").description("String").description("Type of assets section " +
" + \n" +
" + \n" +
" *enum* _Type_ { + \n" +
" ASSET, + \n" +
" EQUITY, + \n" +
" LIABILITY, + \n" +
"}"),
fieldWithPath("[3].type").type("String").description("first entry's description"),
fieldWithPath("[3].level").type("Integer").description("first entry's value"),
fieldWithPath("[4].code").description("String").description("Date of Financial Condition Preparation"),
fieldWithPath("[4].name").description("String").description("Type of assets section " +
" + \n" +
" + \n" +
" *enum* _Type_ { + \n" +
" ASSET, + \n" +
" EQUITY, + \n" +
" LIABILITY, + \n" +
"}"),
fieldWithPath("[4].type").type("String").description("first entry's description"),
fieldWithPath("[4].level").type("Integer").description("first entry's value"),
fieldWithPath("[5].code").description("String").description("Date of Financial Condition Preparation"),
fieldWithPath("[5].name").description("String").description("Type of assets section " +
" + \n" +
" + \n" +
" *enum* _Type_ { + \n" +
" ASSET, + \n" +
" EQUITY, + \n" +
" LIABILITY, + \n" +
"}"),
fieldWithPath("[5].description").type("String").description("first section's description"),
fieldWithPath("[5].type").type("String").description("first entry's description"),
fieldWithPath("[5].level").type("Integer").description("first entry's value"),
fieldWithPath("[6].code").description("String").description("Date of Financial Condition Preparation"),
fieldWithPath("[6].name").description("String").description("Type of assets section " +
" + \n" +
" + \n" +
" *enum* _Type_ { + \n" +
" ASSET, + \n" +
" EQUITY, + \n" +
" LIABILITY, + \n" +
"}"),
fieldWithPath("[6].type").type("String").description("first entry's description"),
fieldWithPath("[6].level").type("Integer").description("first entry's value")
)));
}
}
| 4,729 |
0 | Create_ds/fineract-cn-accounting/component-test/src/main/java/org/apache/fineract/cn | Create_ds/fineract-cn-accounting/component-test/src/main/java/org/apache/fineract/cn/accounting/TestLedger.java | /*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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.apache.fineract.cn.accounting;
import org.apache.fineract.cn.accounting.api.v1.EventConstants;
import org.apache.fineract.cn.accounting.api.v1.client.LedgerAlreadyExistsException;
import org.apache.fineract.cn.accounting.api.v1.client.LedgerNotFoundException;
import org.apache.fineract.cn.accounting.api.v1.client.LedgerReferenceExistsException;
import org.apache.fineract.cn.accounting.api.v1.domain.Account;
import org.apache.fineract.cn.accounting.api.v1.domain.AccountType;
import org.apache.fineract.cn.accounting.api.v1.domain.Ledger;
import org.apache.fineract.cn.accounting.api.v1.domain.LedgerPage;
import org.apache.fineract.cn.accounting.util.AccountGenerator;
import org.apache.fineract.cn.accounting.util.LedgerGenerator;
import org.apache.commons.lang3.RandomStringUtils;
import org.junit.Assert;
import org.junit.Test;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;
public class TestLedger extends AbstractAccountingTest {
@Test
public void shouldCreateLedger() throws Exception {
final Ledger ledger = LedgerGenerator.createRandomLedger();
this.testSubject.createLedger(ledger);
Assert.assertTrue(this.eventRecorder.wait(EventConstants.POST_LEDGER, ledger.getIdentifier()));
}
@Test
public void shouldNotCreateLedgerAlreadyExists() throws Exception {
final Ledger ledger = LedgerGenerator.createRandomLedger();
this.testSubject.createLedger(ledger);
this.eventRecorder.wait(EventConstants.POST_LEDGER, ledger.getIdentifier());
try {
this.testSubject.createLedger(ledger);
Assert.fail();
} catch (final LedgerAlreadyExistsException ex) {
// do nothing, expected
}
}
@Test
public void shouldFetchLedgers() throws Exception {
final LedgerPage currentLedgerPage = this.testSubject.fetchLedgers(false, null, null, null, null, null, null);
final Ledger ledger = LedgerGenerator.createRandomLedger();
this.testSubject.createLedger(ledger);
this.eventRecorder.wait(EventConstants.POST_LEDGER, ledger.getIdentifier());
final LedgerPage ledgerPage = this.testSubject.fetchLedgers(false, null, null, null, null, null, null);
Assert.assertEquals(currentLedgerPage.getTotalElements() + 1L, ledgerPage.getTotalElements().longValue());
}
@Test
public void shouldFetchSubLedgers() throws Exception {
final Ledger parent = LedgerGenerator.createRandomLedger();
final Ledger child = LedgerGenerator.createRandomLedger();
parent.setSubLedgers(Collections.singletonList(child));
final LedgerPage currentLedgerPage = this.testSubject.fetchLedgers(true, child.getIdentifier(), null, null, null, null, null);
this.testSubject.createLedger(parent);
this.eventRecorder.wait(EventConstants.POST_LEDGER, parent.getIdentifier());
final LedgerPage ledgerPage = this.testSubject.fetchLedgers(true, child.getIdentifier(), null, null, null, null, null);
Assert.assertEquals(currentLedgerPage.getTotalElements() + 1L, ledgerPage.getTotalElements().longValue());
final Ledger fetchedSubLedger = ledgerPage.getLedgers().get(0);
Assert.assertEquals(parent.getIdentifier(), fetchedSubLedger.getParentLedgerIdentifier());
}
@Test
public void shouldFindLedger() throws Exception {
final Ledger ledger = LedgerGenerator.createRandomLedger();
this.testSubject.createLedger(ledger);
this.eventRecorder.wait(EventConstants.POST_LEDGER, ledger.getIdentifier());
final Ledger foundLedger = this.testSubject.findLedger(ledger.getIdentifier());
Assert.assertNotNull(foundLedger);
Assert.assertEquals(ledger.getIdentifier(), foundLedger.getIdentifier());
Assert.assertEquals(ledger.getType(), foundLedger.getType());
Assert.assertEquals(ledger.getName(), foundLedger.getName());
Assert.assertEquals(ledger.getDescription(), foundLedger.getDescription());
Assert.assertNull(ledger.getParentLedgerIdentifier());
Assert.assertTrue(foundLedger.getSubLedgers().size() == 0);
Assert.assertNotNull(foundLedger.getCreatedBy());
Assert.assertNotNull(foundLedger.getCreatedOn());
Assert.assertNull(foundLedger.getLastModifiedBy());
Assert.assertNull(foundLedger.getLastModifiedOn());
Assert.assertEquals(ledger.getShowAccountsInChart(), foundLedger.getShowAccountsInChart());
}
@Test
public void shouldNotFindLedgerUnknown() throws Exception {
try {
this.testSubject.findLedger(RandomStringUtils.randomAlphanumeric(8));
Assert.fail();
} catch (final LedgerNotFoundException ex) {
// do nothing, expected
}
}
@Test
public void shouldAddSubLedger() throws Exception {
final Ledger parentLedger = LedgerGenerator.createRandomLedger();
this.testSubject.createLedger(parentLedger);
this.eventRecorder.wait(EventConstants.POST_LEDGER, parentLedger.getIdentifier());
final Ledger subLedger = LedgerGenerator.createRandomLedger();
this.testSubject.addSubLedger(parentLedger.getIdentifier(), subLedger);
this.eventRecorder.wait(EventConstants.POST_LEDGER, subLedger.getIdentifier());
final Ledger foundParentLedger = this.testSubject.findLedger(parentLedger.getIdentifier());
Assert.assertTrue(foundParentLedger.getSubLedgers().size() == 1);
final Ledger foundSubLedger = foundParentLedger.getSubLedgers().get(0);
Assert.assertEquals(subLedger.getIdentifier(), foundSubLedger.getIdentifier());
}
@Test
public void shouldNotAddSubLedgerParentUnknown() throws Exception {
final Ledger subLedger = LedgerGenerator.createRandomLedger();
try {
this.testSubject.addSubLedger(RandomStringUtils.randomAlphanumeric(8), subLedger);
Assert.fail();
} catch (final LedgerNotFoundException ex) {
// do nothing, expected
}
}
@Test
public void shouldNotAddSubLedgerAlreadyExists() throws Exception {
final Ledger ledger = LedgerGenerator.createRandomLedger();
this.testSubject.createLedger(ledger);
this.eventRecorder.wait(EventConstants.POST_LEDGER, ledger.getIdentifier());
try {
final Ledger subLedger = LedgerGenerator.createRandomLedger();
subLedger.setIdentifier(ledger.getIdentifier());
this.testSubject.addSubLedger(ledger.getIdentifier(), subLedger);
Assert.fail();
} catch (final LedgerAlreadyExistsException ex) {
// do nothing, expected
}
}
@Test
public void shouldModifyLedger() throws Exception {
final Ledger ledger = LedgerGenerator.createRandomLedger();
this.testSubject.createLedger(ledger);
this.eventRecorder.wait(EventConstants.POST_LEDGER, ledger.getIdentifier());
ledger.setName(RandomStringUtils.randomAlphabetic(256));
ledger.setDescription(RandomStringUtils.randomAlphabetic(2048));
ledger.setShowAccountsInChart(Boolean.TRUE);
this.testSubject.modifyLedger(ledger.getIdentifier(), ledger);
this.eventRecorder.wait(EventConstants.PUT_LEDGER, ledger.getIdentifier());
final Ledger modifiedLedger = this.testSubject.findLedger(ledger.getIdentifier());
Assert.assertEquals(ledger.getName(), modifiedLedger.getName());
Assert.assertEquals(ledger.getDescription(), modifiedLedger.getDescription());
Assert.assertNotNull(modifiedLedger.getLastModifiedBy());
Assert.assertNotNull(modifiedLedger.getLastModifiedOn());
Assert.assertEquals(ledger.getShowAccountsInChart(), modifiedLedger.getShowAccountsInChart());
}
@Test
public void shouldNotModifyLedgerIdentifierMismatch() throws Exception {
final Ledger ledger = LedgerGenerator.createRandomLedger();
this.testSubject.createLedger(ledger);
this.eventRecorder.wait(EventConstants.POST_LEDGER, ledger.getIdentifier());
final String randomName = RandomStringUtils.randomAlphanumeric(8);
try {
this.testSubject.modifyLedger(randomName, ledger);
Assert.fail();
} catch (final IllegalArgumentException ex) {
Assert.assertTrue(ex.getMessage().contains(randomName));
// do nothing, expected
}
}
@Test
public void shouldNotModifyLedgerUnknown() {
final Ledger ledger = LedgerGenerator.createRandomLedger();
try {
this.testSubject.modifyLedger(ledger.getIdentifier(), ledger);
Assert.fail();
} catch (final LedgerNotFoundException ex) {
// do nothing , expected
}
}
@Test
public void shouldDeleteLedger() throws Exception {
final Ledger ledger2delete = LedgerGenerator.createRandomLedger();
this.testSubject.createLedger(ledger2delete);
this.eventRecorder.wait(EventConstants.POST_LEDGER, ledger2delete.getIdentifier());
this.testSubject.deleteLedger(ledger2delete.getIdentifier());
this.eventRecorder.wait(EventConstants.DELETE_LEDGER, ledger2delete.getIdentifier());
try {
this.testSubject.findLedger(ledger2delete.getIdentifier());
Assert.fail();
} catch (final LedgerNotFoundException ex) {
// do nothing, expected
}
}
@Test
public void shouldNotDeleteLedgerUnknown() throws Exception {
try {
this.testSubject.deleteLedger(RandomStringUtils.randomAlphanumeric(8));
Assert.fail();
} catch (final LedgerNotFoundException ex) {
// do nothing, expected
}
}
@Test
public void shouldNotDeleteLedgerHoldsSubLedger() throws Exception {
final Ledger ledger2delete = LedgerGenerator.createRandomLedger();
ledger2delete.setSubLedgers(Collections.singletonList(LedgerGenerator.createRandomLedger()));
this.testSubject.createLedger(ledger2delete);
this.eventRecorder.wait(EventConstants.POST_LEDGER, ledger2delete.getIdentifier());
try {
this.testSubject.deleteLedger(ledger2delete.getIdentifier());
Assert.fail();
} catch (final LedgerReferenceExistsException ex) {
// do nothing, expected
}
}
@Test
public void shouldNotDeleteLedgerHoldsAccount() throws Exception {
final Ledger ledger2delete = LedgerGenerator.createRandomLedger();
this.testSubject.createLedger(ledger2delete);
this.eventRecorder.wait(EventConstants.POST_LEDGER, ledger2delete.getIdentifier());
final Account ledgerAccount = AccountGenerator.createRandomAccount(ledger2delete.getIdentifier());
this.testSubject.createAccount(ledgerAccount);
this.eventRecorder.wait(EventConstants.POST_ACCOUNT, ledgerAccount.getIdentifier());
try {
this.testSubject.deleteLedger(ledger2delete.getIdentifier());
Assert.fail();
} catch (final LedgerReferenceExistsException ex) {
// do nothing, expected
}
}
@Test
public void shouldFindLedgerWithSeparatorInIdentifier() throws Exception {
// RFC 3986 unreserved characters: ALPHA DIGIT "-", ".", "_", "~"
final String[] unreservedCharacters = new String[] {
"-",
".",
"_"
};
this.logger.info("Creating {} ledgers with unreserved characters.", unreservedCharacters.length);
boolean failed = false;
for (String unreservedCharacter : unreservedCharacters) {
final Ledger ledger = LedgerGenerator.createRandomLedger();
final String identifier = RandomStringUtils.randomAlphanumeric(3) + unreservedCharacter + RandomStringUtils.randomAlphanumeric(2);
ledger.setIdentifier(identifier);
this.logger.info("Creating ledger '{}' with unreserved character '{}' in identifier.", identifier, unreservedCharacter);
this.testSubject.createLedger(ledger);
Assert.assertTrue(this.eventRecorder.wait(EventConstants.POST_LEDGER, ledger.getIdentifier()));
try {
this.testSubject.findLedger(ledger.getIdentifier());
this.logger.info("Ledger '{}' with unreserved character '{}' in identifier found.", identifier, unreservedCharacter);
} catch (final Exception ex) {
this.logger.error("Ledger '{}' with unreserved character '{}' in identifier not found.", identifier, unreservedCharacter);
failed = true;
}
}
Assert.assertFalse(failed);
}
@Test
public void shouldStreamAllAccountsBelongingToLedger() throws InterruptedException {
final Ledger assetLedger = LedgerGenerator.createRandomLedger();
assetLedger.setType(AccountType.ASSET.name());
this.testSubject.createLedger(assetLedger);
this.eventRecorder.wait(EventConstants.POST_LEDGER, assetLedger.getIdentifier());
final List<Account> createdAssetAccounts = Stream.generate(() -> AccountGenerator.createRandomAccount(assetLedger.getIdentifier())).limit(1)
.peek(account -> {
account.setType(AccountType.ASSET.name());
this.testSubject.createAccount(account);
})
.collect(Collectors.toList());
for (final Account account : createdAssetAccounts) {
this.eventRecorder.wait(EventConstants.POST_ACCOUNT, account.getIdentifier());
}
final List<Account> foundAccounts = testSubject.streamAccountsOfLedger(assetLedger.getIdentifier(), "ASC")
.peek(account -> account.setState(null))
.collect(Collectors.toList());
Assert.assertEquals(createdAssetAccounts, foundAccounts);
}
}
| 4,730 |
0 | Create_ds/fineract-cn-accounting/component-test/src/main/java/org/apache/fineract/cn | Create_ds/fineract-cn-accounting/component-test/src/main/java/org/apache/fineract/cn/accounting/TestTransactionType.java | /*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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.apache.fineract.cn.accounting;
import org.apache.fineract.cn.accounting.api.v1.EventConstants;
import org.apache.fineract.cn.accounting.api.v1.client.TransactionTypeAlreadyExists;
import org.apache.fineract.cn.accounting.api.v1.client.TransactionTypeNotFoundException;
import org.apache.fineract.cn.accounting.api.v1.client.TransactionTypeValidationException;
import org.apache.fineract.cn.accounting.api.v1.domain.TransactionType;
import org.apache.fineract.cn.accounting.api.v1.domain.TransactionTypePage;
import org.apache.fineract.cn.accounting.util.TransactionTypeGenerator;
import org.junit.Assert;
import org.junit.Test;
import org.springframework.data.domain.Sort;
public class TestTransactionType extends AbstractAccountingTest {
public TestTransactionType() {
super();
}
@Test
public void shouldFetchPreConfiguredTypes() {
final TransactionTypePage transactionTypePage =
super.testSubject.fetchTransactionTypes(null, 0, 100, "identifier", Sort.Direction.DESC.name());
Assert.assertTrue(transactionTypePage.getTotalElements() >= 54L);
}
@Test
public void shouldCreateTransactionType() throws Exception {
final TransactionType transactionType = TransactionTypeGenerator.createRandomTransactionType();
super.testSubject.createTransactionType(transactionType);
Assert.assertTrue(super.eventRecorder.wait(EventConstants.POST_TX_TYPE, transactionType.getCode()));
}
@Test(expected = TransactionTypeAlreadyExists.class)
public void shouldNotCreateTransactionTypeAlreadyExists() throws Exception {
final TransactionType transactionType = TransactionTypeGenerator.createRandomTransactionType();
transactionType.setCode("duplicate");
super.testSubject.createTransactionType(transactionType);
Assert.assertTrue(super.eventRecorder.wait(EventConstants.POST_TX_TYPE, transactionType.getCode()));
super.testSubject.createTransactionType(transactionType);
}
@Test
public void shouldChangeTransactionType() throws Exception {
final String code = "changeable";
final TransactionType transactionType = TransactionTypeGenerator.createRandomTransactionType();
transactionType.setCode(code);
super.testSubject.createTransactionType(transactionType);
Assert.assertTrue(super.eventRecorder.wait(EventConstants.POST_TX_TYPE, transactionType.getCode()));
final String changedName = "Changed name";
transactionType.setName(changedName);
super.testSubject.changeTransactionType(code, transactionType);
Assert.assertTrue(super.eventRecorder.wait(EventConstants.PUT_TX_TYPE, transactionType.getCode()));
final TransactionTypePage transactionTypePage =
super.testSubject.fetchTransactionTypes(code, 0, 1, null, null);
Assert.assertTrue(transactionTypePage.getTotalElements() == 1L);
final TransactionType fetchedTransactionType = transactionTypePage.getTransactionTypes().get(0);
Assert.assertEquals(changedName, fetchedTransactionType.getName());
}
@Test(expected = TransactionTypeNotFoundException.class)
public void shouldNotChangeTransactionTypeNotFound() {
final String code = "unknown";
final TransactionType transactionType = TransactionTypeGenerator.createRandomTransactionType();
transactionType.setCode(code);
super.testSubject.changeTransactionType(code, transactionType);
}
@Test(expected = TransactionTypeValidationException.class)
public void shouldNotChangeTransactionTypeCodeMismatch() {
final String code = "mismatch";
final TransactionType transactionType = TransactionTypeGenerator.createRandomTransactionType();
super.testSubject.changeTransactionType(code, transactionType);
}
@Test
public void shouldFindTransactionType() throws Exception {
final TransactionType randomTransactionType = TransactionTypeGenerator.createRandomTransactionType();
super.testSubject.createTransactionType(randomTransactionType);
Assert.assertTrue(super.eventRecorder.wait(EventConstants.POST_TX_TYPE, randomTransactionType.getCode()));
final TransactionType fetchedTransactionType = super.testSubject.findTransactionType(randomTransactionType.getCode());
Assert.assertNotNull(fetchedTransactionType);
Assert.assertEquals(randomTransactionType.getCode(), fetchedTransactionType.getCode());
Assert.assertEquals(randomTransactionType.getName(), fetchedTransactionType.getName());
Assert.assertEquals(randomTransactionType.getDescription(), fetchedTransactionType.getDescription());
}
@Test(expected = TransactionTypeNotFoundException.class)
public void shouldNotFindTransactionTypeNotFound() {
super.testSubject.findTransactionType("unknown");
}
}
| 4,731 |
0 | Create_ds/fineract-cn-accounting/component-test/src/main/java/org/apache/fineract/cn | Create_ds/fineract-cn-accounting/component-test/src/main/java/org/apache/fineract/cn/accounting/TestTrialBalance.java | /*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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.apache.fineract.cn.accounting;
import org.apache.fineract.cn.accounting.api.v1.EventConstants;
import org.apache.fineract.cn.accounting.api.v1.domain.Account;
import org.apache.fineract.cn.accounting.api.v1.domain.AccountType;
import org.apache.fineract.cn.accounting.api.v1.domain.JournalEntry;
import org.apache.fineract.cn.accounting.api.v1.domain.Ledger;
import org.apache.fineract.cn.accounting.api.v1.domain.financial.statement.TrialBalance;
import org.apache.fineract.cn.accounting.util.AccountGenerator;
import org.apache.fineract.cn.accounting.util.JournalEntryGenerator;
import org.apache.fineract.cn.accounting.util.LedgerGenerator;
import org.junit.Assert;
import org.junit.Test;
import java.math.BigDecimal;
public class TestTrialBalance extends AbstractAccountingTest {
@Test
public void shouldGenerateTrialBalance() throws Exception {
final Ledger assetLedger = LedgerGenerator.createRandomLedger();
this.testSubject.createLedger(assetLedger);
this.eventRecorder.wait(EventConstants.POST_LEDGER, assetLedger.getIdentifier());
final Ledger assetSubLedgerOne = LedgerGenerator.createRandomLedger();
this.testSubject.addSubLedger(assetLedger.getIdentifier(), assetSubLedgerOne);
this.eventRecorder.wait(EventConstants.POST_LEDGER, assetSubLedgerOne.getIdentifier());
final Ledger assetSubLedgerTwo = LedgerGenerator.createRandomLedger();
this.testSubject.addSubLedger(assetLedger.getIdentifier(), assetSubLedgerTwo);
this.eventRecorder.wait(EventConstants.POST_LEDGER, assetSubLedgerTwo.getIdentifier());
final Ledger liabilityLedger = LedgerGenerator.createRandomLedger();
liabilityLedger.setType(AccountType.LIABILITY.name());
this.testSubject.createLedger(liabilityLedger);
this.eventRecorder.wait(EventConstants.POST_LEDGER, liabilityLedger.getIdentifier());
final Ledger liabilitySubLedger = LedgerGenerator.createRandomLedger();
liabilitySubLedger.setType(AccountType.LIABILITY.name());
this.testSubject.addSubLedger(liabilityLedger.getIdentifier(), liabilitySubLedger);
this.eventRecorder.wait(EventConstants.POST_LEDGER, liabilitySubLedger.getIdentifier());
final Account account4ledgerOne = AccountGenerator.createRandomAccount(assetSubLedgerOne.getIdentifier());
this.testSubject.createAccount(account4ledgerOne);
this.eventRecorder.wait(EventConstants.POST_ACCOUNT, account4ledgerOne.getIdentifier());
final Account secondAccount4ledgerOne = AccountGenerator.createRandomAccount(assetSubLedgerOne.getIdentifier());
this.testSubject.createAccount(secondAccount4ledgerOne);
this.eventRecorder.wait(EventConstants.POST_ACCOUNT, secondAccount4ledgerOne.getIdentifier());
final Account account4subLedgerOne = AccountGenerator.createRandomAccount(assetSubLedgerTwo.getIdentifier());
this.testSubject.createAccount(account4subLedgerOne);
this.eventRecorder.wait(EventConstants.POST_ACCOUNT, account4subLedgerOne.getIdentifier());
final Account account4ledgerTwo = AccountGenerator.createRandomAccount(liabilitySubLedger.getIdentifier());
account4ledgerTwo.setType(AccountType.LIABILITY.name());
this.testSubject.createAccount(account4ledgerTwo);
this.eventRecorder.wait(EventConstants.POST_ACCOUNT, account4ledgerTwo.getIdentifier());
final JournalEntry firstBooking =
JournalEntryGenerator.createRandomJournalEntry(secondAccount4ledgerOne, "50.00", account4ledgerTwo, "50.00");
this.testSubject.createJournalEntry(firstBooking);
this.eventRecorder.wait(EventConstants.RELEASE_JOURNAL_ENTRY, firstBooking.getTransactionIdentifier());
final JournalEntry secondBooking =
JournalEntryGenerator.createRandomJournalEntry(secondAccount4ledgerOne, "50.00", account4ledgerOne, "50.00");
this.testSubject.createJournalEntry(secondBooking);
this.eventRecorder.wait(EventConstants.RELEASE_JOURNAL_ENTRY, secondBooking.getTransactionIdentifier());
final JournalEntry thirdBooking =
JournalEntryGenerator.createRandomJournalEntry(account4subLedgerOne, "50.00", account4ledgerTwo, "50.00");
this.testSubject.createJournalEntry(thirdBooking);
this.eventRecorder.wait(EventConstants.RELEASE_JOURNAL_ENTRY, thirdBooking.getTransactionIdentifier());
final TrialBalance trialBalance = this.testSubject.getTrialBalance(true);
Assert.assertNotNull(trialBalance);
Assert.assertEquals(3, trialBalance.getTrialBalanceEntries().size());
final BigDecimal expectedValue = BigDecimal.valueOf(100.00D);
Assert.assertTrue(trialBalance.getDebitTotal().compareTo(expectedValue) == 0);
Assert.assertTrue(trialBalance.getCreditTotal().compareTo(expectedValue) == 0);
}
}
| 4,732 |
0 | Create_ds/fineract-cn-accounting/component-test/src/main/java/org/apache/fineract/cn | Create_ds/fineract-cn-accounting/component-test/src/main/java/org/apache/fineract/cn/accounting/TrialBalanceApiDocumentation.java | /*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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.apache.fineract.cn.accounting;
import org.apache.fineract.cn.accounting.api.v1.EventConstants;
import org.apache.fineract.cn.accounting.api.v1.domain.Account;
import org.apache.fineract.cn.accounting.api.v1.domain.AccountType;
import org.apache.fineract.cn.accounting.api.v1.domain.JournalEntry;
import org.apache.fineract.cn.accounting.api.v1.domain.Ledger;
import org.apache.fineract.cn.accounting.util.AccountGenerator;
import org.apache.fineract.cn.accounting.util.JournalEntryGenerator;
import org.apache.fineract.cn.accounting.util.LedgerGenerator;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.restdocs.JUnitRestDocumentation;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
import org.springframework.web.context.WebApplicationContext;
import static org.springframework.restdocs.mockmvc.MockMvcRestDocumentation.document;
import static org.springframework.restdocs.mockmvc.MockMvcRestDocumentation.documentationConfiguration;
import static org.springframework.restdocs.mockmvc.RestDocumentationRequestBuilders.get;
import static org.springframework.restdocs.operation.preprocess.Preprocessors.preprocessRequest;
import static org.springframework.restdocs.operation.preprocess.Preprocessors.preprocessResponse;
import static org.springframework.restdocs.operation.preprocess.Preprocessors.prettyPrint;
import static org.springframework.restdocs.payload.PayloadDocumentation.fieldWithPath;
import static org.springframework.restdocs.payload.PayloadDocumentation.responseFields;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
public class TrialBalanceApiDocumentation extends AbstractAccountingTest {
@Rule
public final JUnitRestDocumentation restDocumentation = new JUnitRestDocumentation("build/doc/generated-snippets/test-trial-balance");
@Autowired
private WebApplicationContext context;
private MockMvc mockMvc;
@Before
public void setUp ( ) {
this.mockMvc = MockMvcBuilders.webAppContextSetup(this.context)
.apply(documentationConfiguration(this.restDocumentation))
.alwaysDo(document("{method-name}", preprocessRequest(prettyPrint()), preprocessResponse(prettyPrint())))
.build();
}
@Test
public void documentGenerateTrialBalance ( ) throws Exception {
final Ledger assetLedger = LedgerGenerator.createRandomLedger();
this.testSubject.createLedger(assetLedger);
this.eventRecorder.wait(EventConstants.POST_LEDGER, assetLedger.getIdentifier());
final Ledger assetSubLedgerOne = LedgerGenerator.createRandomLedger();
this.testSubject.addSubLedger(assetLedger.getIdentifier(), assetSubLedgerOne);
this.eventRecorder.wait(EventConstants.POST_LEDGER, assetSubLedgerOne.getIdentifier());
final Ledger assetSubLedgerTwo = LedgerGenerator.createRandomLedger();
this.testSubject.addSubLedger(assetLedger.getIdentifier(), assetSubLedgerTwo);
this.eventRecorder.wait(EventConstants.POST_LEDGER, assetSubLedgerTwo.getIdentifier());
final Ledger liabilityLedger = LedgerGenerator.createRandomLedger();
liabilityLedger.setType(AccountType.LIABILITY.name());
this.testSubject.createLedger(liabilityLedger);
this.eventRecorder.wait(EventConstants.POST_LEDGER, liabilityLedger.getIdentifier());
final Ledger liabilitySubLedger = LedgerGenerator.createRandomLedger();
liabilitySubLedger.setType(AccountType.LIABILITY.name());
this.testSubject.addSubLedger(liabilityLedger.getIdentifier(), liabilitySubLedger);
this.eventRecorder.wait(EventConstants.POST_LEDGER, liabilitySubLedger.getIdentifier());
final Account account4ledgerOne = AccountGenerator.createRandomAccount(assetSubLedgerOne.getIdentifier());
this.testSubject.createAccount(account4ledgerOne);
this.eventRecorder.wait(EventConstants.POST_ACCOUNT, account4ledgerOne.getIdentifier());
final Account secondAccount4ledgerOne = AccountGenerator.createRandomAccount(assetSubLedgerOne.getIdentifier());
this.testSubject.createAccount(secondAccount4ledgerOne);
this.eventRecorder.wait(EventConstants.POST_ACCOUNT, secondAccount4ledgerOne.getIdentifier());
final Account account4subLedgerOne = AccountGenerator.createRandomAccount(assetSubLedgerTwo.getIdentifier());
this.testSubject.createAccount(account4subLedgerOne);
this.eventRecorder.wait(EventConstants.POST_ACCOUNT, account4subLedgerOne.getIdentifier());
final Account account4ledgerTwo = AccountGenerator.createRandomAccount(liabilitySubLedger.getIdentifier());
account4ledgerTwo.setType(AccountType.LIABILITY.name());
this.testSubject.createAccount(account4ledgerTwo);
this.eventRecorder.wait(EventConstants.POST_ACCOUNT, account4ledgerTwo.getIdentifier());
final JournalEntry firstBooking =
JournalEntryGenerator.createRandomJournalEntry(secondAccount4ledgerOne, "50.00", account4ledgerTwo, "50.00");
this.testSubject.createJournalEntry(firstBooking);
this.eventRecorder.wait(EventConstants.RELEASE_JOURNAL_ENTRY, firstBooking.getTransactionIdentifier());
final JournalEntry secondBooking =
JournalEntryGenerator.createRandomJournalEntry(secondAccount4ledgerOne, "50.00", account4ledgerOne, "50.00");
this.testSubject.createJournalEntry(secondBooking);
this.eventRecorder.wait(EventConstants.RELEASE_JOURNAL_ENTRY, secondBooking.getTransactionIdentifier());
final JournalEntry thirdBooking =
JournalEntryGenerator.createRandomJournalEntry(account4subLedgerOne, "50.00", account4ledgerTwo, "50.00");
this.testSubject.createJournalEntry(thirdBooking);
this.eventRecorder.wait(EventConstants.RELEASE_JOURNAL_ENTRY, thirdBooking.getTransactionIdentifier());
this.mockMvc.perform(get("/trialbalance")
.contentType(MediaType.APPLICATION_JSON_VALUE)
.accept(MediaType.ALL_VALUE))
.andExpect(status().isOk())
.andDo(document("document-show-chart-of-accounts", preprocessRequest(prettyPrint()), preprocessResponse(prettyPrint()),
responseFields(
fieldWithPath("trialBalanceEntries[].ledger.identifier").description("String").description("First Trial Balance Entry Identifier"),
fieldWithPath("trialBalanceEntries[].ledger.type").description("Type").description("Type of trial balance " +
" + \n" +
" + \n" +
" *enum* _Type_ { + \n" +
" DEBIT, + \n" +
" CREDIT, + \n" +
"}"),
fieldWithPath("trialBalanceEntries[].ledger.name").description("String").description("Ledger Name"),
fieldWithPath("trialBalanceEntries[].ledger.description").description("String").description("Description of Ledger"),
fieldWithPath("trialBalanceEntries[].ledger.parentLedgerIdentifier").description("String").description("Parent Ledger"),
fieldWithPath("trialBalanceEntries[].ledger.subLedgers").description("String").description("Name of Subledger"),
fieldWithPath("trialBalanceEntries[].ledger.totalValue").description("BigDecimal").description("Total Value"),
fieldWithPath("trialBalanceEntries[].ledger.createdOn").description("String").description("Creation Date"),
fieldWithPath("trialBalanceEntries[].ledger.createdBy").description("String").description("Employee Who Created"),
fieldWithPath("trialBalanceEntries[].ledger.lastModifiedOn").description("String").description("Last Modified Date"),
fieldWithPath("trialBalanceEntries[].ledger.lastModifiedBy").description("String").description("Empoyee Who Last Modified"),
fieldWithPath("trialBalanceEntries[].ledger.showAccountsInChart").description("String").description("Should We Show Chart of Accounts"),
fieldWithPath("trialBalanceEntries[].type").description("Type").description("Type of trial balance entry " +
" + \n" +
" + \n" +
" *enum* _Type_ { + \n" +
" DEBIT, + \n" +
" CREDIT, + \n" +
"}"),
fieldWithPath("trialBalanceEntries[].amount").description("BigDecimal").description("Amount"),
fieldWithPath("trialBalanceEntries[1].ledger.identifier").description("String").description("Second Trial Balance Entry Identifier"),
fieldWithPath("trialBalanceEntries[1].ledger.type").description("Type").description("Type of trial balance " +
" + \n" +
" + \n" +
" *enum* _Type_ { + \n" +
" DEBIT, + \n" +
" CREDIT, + \n" +
"}"),
fieldWithPath("trialBalanceEntries[1].ledger.name").description("String").description("Ledger Name"),
fieldWithPath("trialBalanceEntries[1].ledger.description").description("String").description("Description of Ledger"),
fieldWithPath("trialBalanceEntries[1].ledger.parentLedgerIdentifier").description("String").description("Parent Ledger"),
fieldWithPath("trialBalanceEntries[1].ledger.subLedgers").description("String").description("Name of Subledger"),
fieldWithPath("trialBalanceEntries[1].ledger.totalValue").description("BigDecimal").description("Total Value"),
fieldWithPath("trialBalanceEntries[1].ledger.createdOn").description("String").description("Creation Date"),
fieldWithPath("trialBalanceEntries[1].ledger.createdBy").description("String").description("Employee Who Created"),
fieldWithPath("trialBalanceEntries[1].ledger.lastModifiedOn").description("String").description("Last Modified Date"),
fieldWithPath("trialBalanceEntries[1].ledger.lastModifiedBy").description("String").description("Empoyee Who Last Modified"),
fieldWithPath("trialBalanceEntries[1].ledger.showAccountsInChart").description("String").description("Should We Show Chart of Accounts"),
fieldWithPath("trialBalanceEntries[1].type").description("Type").description("Type of trial balance entry " +
" + \n" +
" + \n" +
" *enum* _Type_ { + \n" +
" DEBIT, + \n" +
" CREDIT, + \n" +
"}"),
fieldWithPath("trialBalanceEntries[1].amount").description("BigDecimal").description("Amount"),
fieldWithPath("trialBalanceEntries[1].ledger.identifier").description("String").description("Third Trial Balance Entry Identifier"),
fieldWithPath("trialBalanceEntries[2].ledger.type").description("Type").description("Type of trial balance " +
" + \n" +
" + \n" +
" *enum* _Type_ { + \n" +
" DEBIT, + \n" +
" CREDIT, + \n" +
"}"),
fieldWithPath("trialBalanceEntries[2].ledger.name").description("String").description("Ledger Name"),
fieldWithPath("trialBalanceEntries[2].ledger.description").description("String").description("Description of Ledger"),
fieldWithPath("trialBalanceEntries[2].ledger.parentLedgerIdentifier").description("String").description("Parent Ledger"),
fieldWithPath("trialBalanceEntries[2].ledger.subLedgers").description("String").description("Name of Subledger"),
fieldWithPath("trialBalanceEntries[2].ledger.totalValue").description("BigDecimal").description("Total Value"),
fieldWithPath("trialBalanceEntries[2].ledger.createdOn").description("String").description("Creation Date"),
fieldWithPath("trialBalanceEntries[2].ledger.createdBy").description("String").description("Employee Who Created"),
fieldWithPath("trialBalanceEntries[2].ledger.lastModifiedOn").description("String").description("Last Modified Date"),
fieldWithPath("trialBalanceEntries[2].ledger.lastModifiedBy").description("String").description("Empoyee Who Last Modified"),
fieldWithPath("trialBalanceEntries[2].ledger.showAccountsInChart").description("String").description("Should We Show Chart of Accounts"),
fieldWithPath("trialBalanceEntries[2].type").description("Type").description("Type of trial balance entry " +
" + \n" +
" + \n" +
" *enum* _Type_ { + \n" +
" DEBIT, + \n" +
" CREDIT, + \n" +
"}"),
fieldWithPath("trialBalanceEntries[2].amount").description("BigDecimal").description("Amount"),
fieldWithPath("debitTotal").type("BigDecimal").description("Total Debit"),
fieldWithPath("creditTotal").type("BigDecimal").description("Total Credit")
)));
}
}
| 4,733 |
0 | Create_ds/fineract-cn-accounting/component-test/src/main/java/org/apache/fineract/cn | Create_ds/fineract-cn-accounting/component-test/src/main/java/org/apache/fineract/cn/accounting/LedgerApiDocumentation.java | /*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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.apache.fineract.cn.accounting;
import com.google.gson.Gson;
import org.apache.commons.lang3.RandomStringUtils;
import org.apache.fineract.cn.accounting.api.v1.EventConstants;
import org.apache.fineract.cn.accounting.api.v1.domain.*;
import org.apache.fineract.cn.accounting.util.AccountGenerator;
import org.apache.fineract.cn.accounting.util.LedgerGenerator;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Sort;
import org.springframework.http.MediaType;
import org.springframework.restdocs.JUnitRestDocumentation;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
import org.springframework.web.context.WebApplicationContext;
import java.math.BigDecimal;
import java.time.LocalDate;
import java.util.*;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import static org.springframework.restdocs.mockmvc.MockMvcRestDocumentation.document;
import static org.springframework.restdocs.mockmvc.MockMvcRestDocumentation.documentationConfiguration;
import static org.springframework.restdocs.mockmvc.RestDocumentationRequestBuilders.get;
import static org.springframework.restdocs.mockmvc.RestDocumentationRequestBuilders.put;
import static org.springframework.restdocs.mockmvc.RestDocumentationRequestBuilders.post;
import static org.springframework.restdocs.mockmvc.RestDocumentationRequestBuilders.delete;
import static org.springframework.restdocs.operation.preprocess.Preprocessors.preprocessRequest;
import static org.springframework.restdocs.operation.preprocess.Preprocessors.preprocessResponse;
import static org.springframework.restdocs.operation.preprocess.Preprocessors.prettyPrint;
import static org.springframework.restdocs.payload.PayloadDocumentation.fieldWithPath;
import static org.springframework.restdocs.payload.PayloadDocumentation.requestFields;
import static org.springframework.restdocs.payload.PayloadDocumentation.responseFields;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
public class LedgerApiDocumentation extends AbstractAccountingTest {
@Rule
public final JUnitRestDocumentation restDocumentation = new JUnitRestDocumentation("build/doc/generated-snippets/test-ledger");
@Autowired
private WebApplicationContext context;
private MockMvc mockMvc;
@Before
public void setUp ( ) {
this.mockMvc = MockMvcBuilders.webAppContextSetup(this.context)
.apply(documentationConfiguration(this.restDocumentation))
.alwaysDo(document("{method-name}", preprocessRequest(prettyPrint()), preprocessResponse(prettyPrint())))
.build();
}
@Test
public void documentCreateLedger ( ) throws Exception {
final Ledger ledger = LedgerGenerator.createRandomLedger();
ledger.setType(AccountType.ASSET.name());
ledger.setIdentifier("1000");
ledger.setName("Cash");
ledger.setDescription("Cash Ledger");
ledger.setShowAccountsInChart(Boolean.TRUE);
Gson gson = new Gson();
this.mockMvc.perform(post("/ledgers")
.contentType(MediaType.APPLICATION_JSON_VALUE)
.accept(MediaType.APPLICATION_JSON_VALUE)
.content(gson.toJson(ledger)))
.andExpect(status().isAccepted())
.andDo(document("document-create-ledger", preprocessRequest(prettyPrint()), preprocessResponse(prettyPrint()),
requestFields(
fieldWithPath("type").description("Type of ledger " +
" + \n" +
" + \n" +
" *enum* _AccountType_ { + \n" +
" ASSET, + \n" +
" LIABILITY, + \n" +
" EQUITY, + \n" +
" REVENUE, + \n" +
" EXPENSE + \n" +
"}"),
fieldWithPath("identifier").description("Account identifier"),
fieldWithPath("name").description("Name of account"),
fieldWithPath("description").description("Description of account"),
fieldWithPath("showAccountsInChart").type("Boolean").description("Should account be shown in charts ?")
)));
}
@Test
public void documentFetchLedgers ( ) throws Exception {
final Ledger ledgerOne = LedgerGenerator.createRandomLedger();
ledgerOne.setIdentifier("1021");
ledgerOne.setName("Name of " + ledgerOne.getIdentifier());
ledgerOne.setDescription("Description of " + ledgerOne.getIdentifier());
ledgerOne.setShowAccountsInChart(Boolean.TRUE);
final Ledger ledgerTwo = LedgerGenerator.createRandomLedger();
ledgerTwo.setIdentifier("1022");
ledgerTwo.setName("Name of " + ledgerTwo.getIdentifier());
ledgerTwo.setDescription("Description of " + ledgerTwo.getIdentifier());
ledgerTwo.setShowAccountsInChart(Boolean.FALSE);
final Ledger ledgerThree = LedgerGenerator.createRandomLedger();
ledgerThree.setIdentifier("1023");
ledgerThree.setName("Name of " + ledgerThree.getIdentifier());
ledgerThree.setDescription("Description of " + ledgerThree.getIdentifier());
ledgerThree.setShowAccountsInChart(Boolean.TRUE);
List <Ledger> ledgerList = new ArrayList <>();
Stream.of(ledgerOne, ledgerTwo, ledgerThree).forEach(ledger -> {
ledgerList.add(ledger);
});
ledgerList.stream()
.forEach(ledger -> {
this.testSubject.createLedger(ledger);
try {
this.eventRecorder.wait(EventConstants.POST_LEDGER, ledger.getIdentifier());
} catch (InterruptedException e) {
e.printStackTrace();
}
});
this.mockMvc.perform(get("/ledgers")
.contentType(MediaType.APPLICATION_JSON_VALUE)
.accept(MediaType.ALL_VALUE))
.andExpect(status().isOk())
.andDo(document("document-fetch-ledgers", preprocessRequest(prettyPrint()), preprocessResponse(prettyPrint()),
responseFields(
fieldWithPath("ledgers").type("List<Ledger>").description("List of Ledgers"),
fieldWithPath("ledgers[].type").description("AccountType").description("Type of first ledger " +
" + \n" +
" + \n" +
" *enum* _AccountType_ { + \n" +
" ASSET, + \n" +
" LIABILITY, + \n" +
" EQUITY, + \n" +
" REVENUE, + \n" +
" EXPENSE + \n" +
"}"),
fieldWithPath("ledgers[].identifier").type("String").description("first ledger identifier"),
fieldWithPath("ledgers[].name").type("String").description("first ledger name"),
fieldWithPath("ledgers[].description").type("String").description("description of first ledger"),
fieldWithPath("ledgers[].parentLedgerIdentifier").description("first ledger's parent "),
fieldWithPath("ledgers[].totalValue").type("String").description("Total Value of first ledger"),
fieldWithPath("ledgers[].createdOn").type("String").description("date first ledger was created"),
fieldWithPath("ledgers[].createdBy").type("String").description("employee who created first ledger"),
fieldWithPath("ledgers[].lastModifiedOn").type("String").description("date first ledger was modified"),
fieldWithPath("ledgers[].lastModifiedBy").type("String").description("employee who last modified first ledger"),
fieldWithPath("ledgers[].showAccountsInChart").type("Boolean").description("Should ledger be shown in charts ?"),
fieldWithPath("ledgers[1].type").description("AccountType").description("Type of second ledger " +
" + \n" +
" + \n" +
" *enum* _AccountType_ { + \n" +
" ASSET, + \n" +
" LIABILITY, + \n" +
" EQUITY, + \n" +
" REVENUE, + \n" +
" EXPENSE + \n" +
"}"),
fieldWithPath("ledgers[1].identifier").type("String").description("second ledger identifier"),
fieldWithPath("ledgers[1].name").type("String").description("second ledger name"),
fieldWithPath("ledgers[1].description").type("String").description("description of second ledger"),
fieldWithPath("ledgers[1].parentLedgerIdentifier").description("second ledger's parent "),
fieldWithPath("ledgers[1].totalValue").type("String").description("Total Value of second ledger"),
fieldWithPath("ledgers[1].createdOn").type("String").description("date second ledger was created"),
fieldWithPath("ledgers[1].createdBy").type("String").description("employee who created second ledger"),
fieldWithPath("ledgers[1].lastModifiedOn").type("String").description("date second ledger was modified"),
fieldWithPath("ledgers[1].lastModifiedBy").type("String").description("employee who last modified second ledger"),
fieldWithPath("ledgers[1].showAccountsInChart").type("Boolean").description("Should ledger be shown in charts ?"),
fieldWithPath("ledgers[2].type").description("AccountType").description("Type of third ledger " +
" + \n" +
" + \n" +
" *enum* _AccountType_ { + \n" +
" ASSET, + \n" +
" LIABILITY, + \n" +
" EQUITY, + \n" +
" REVENUE, + \n" +
" EXPENSE + \n" +
"}"),
fieldWithPath("ledgers[2].identifier").type("String").description("third ledger identifier"),
fieldWithPath("ledgers[2].name").type("String").description("third ledger name"),
fieldWithPath("ledgers[2].description").type("String").description("description of third ledger"),
fieldWithPath("ledgers[2].parentLedgerIdentifier").description("third ledger's parent "),
fieldWithPath("ledgers[2].totalValue").type("String").description("Total Value of third ledger"),
fieldWithPath("ledgers[2].createdOn").type("String").description("date third ledger was created"),
fieldWithPath("ledgers[2].createdBy").type("String").description("employee who created third ledger"),
fieldWithPath("ledgers[2].lastModifiedOn").type("String").description("date second ledger was modified"),
fieldWithPath("ledgers[2].lastModifiedBy").type("String").description("employee who last modified third ledger"),
fieldWithPath("ledgers[2].showAccountsInChart").type("Boolean").description("Should ledger be shown in charts ?"),
fieldWithPath("totalPages").type("Integer").description("Total number of pages"),
fieldWithPath("totalElements").type("String").description("Total number of elements")
)));
}
@Test
public void documentFindLedger ( ) throws Exception {
final Ledger ledger = LedgerGenerator.createRandomLedger();
ledger.setIdentifier("7200");
ledger.setName("Name of" + ledger.getIdentifier());
ledger.setDescription("Description of " + ledger.getIdentifier());
this.testSubject.createLedger(ledger);
this.eventRecorder.wait(EventConstants.POST_LEDGER, ledger.getIdentifier());
Gson gson = new Gson();
this.mockMvc.perform(get("/ledgers/" + ledger.getIdentifier())
.contentType(MediaType.APPLICATION_JSON_VALUE)
.accept(MediaType.ALL_VALUE))
.andExpect(status().isOk())
.andDo(document("document-find-ledger", preprocessRequest(prettyPrint()), preprocessResponse(prettyPrint()),
responseFields(
fieldWithPath("type").description("AccountType").description("Type of first ledger " +
" + \n" +
" + \n" +
" *enum* _AccountType_ { + \n" +
" ASSET, + \n" +
" LIABILITY, + \n" +
" EQUITY, + \n" +
" REVENUE, + \n" +
" EXPENSE + \n" +
"}"),
fieldWithPath("identifier").type("String").description("first ledger identifier"),
fieldWithPath("name").type("String").description("first ledger name"),
fieldWithPath("description").type("String").description("description of first ledger"),
fieldWithPath("subLedgers").type("List<Ledger>").description("list of sub ledgers"),
fieldWithPath(".parentLedgerIdentifier").description("first ledger's parent "),
fieldWithPath("totalValue").type("String").description("Total Value of first ledger"),
fieldWithPath("createdOn").type("String").description("date first ledger was created"),
fieldWithPath("createdBy").type("String").description("employee who created first ledger"),
fieldWithPath("lastModifiedOn").type("String").description("date first ledger was modified"),
fieldWithPath("lastModifiedBy").type("String").description("employee who last modified first ledger"),
fieldWithPath("showAccountsInChart").type("Boolean").description("Should ledger be shown in charts ?")
)));
}
@Test
public void documentAddSubLedger ( ) throws Exception {
final Ledger parentLedger = LedgerGenerator.createRandomLedger();
parentLedger.setIdentifier("6220");
parentLedger.setName("Name of" + parentLedger.getIdentifier());
parentLedger.setDescription("Description of " + parentLedger.getIdentifier());
this.testSubject.createLedger(parentLedger);
this.eventRecorder.wait(EventConstants.POST_LEDGER, parentLedger.getIdentifier());
final Ledger subLedger = LedgerGenerator.createRandomLedger();
subLedger.setIdentifier("6221");
subLedger.setName("SubLedger One of " + parentLedger.getIdentifier());
subLedger.setDescription("First Sub Ledger of " + parentLedger.getIdentifier());
Gson gson = new Gson();
this.mockMvc.perform(post("/ledgers/" + parentLedger.getIdentifier())
.contentType(MediaType.APPLICATION_JSON_VALUE)
.accept(MediaType.APPLICATION_JSON_VALUE)
.content(gson.toJson(subLedger)))
.andExpect(status().isAccepted())
.andDo(document("document-add-sub-ledger", preprocessRequest(prettyPrint()), preprocessResponse(prettyPrint()),
requestFields(
fieldWithPath("type").description("Type of Ledger " +
" + \n" +
" + \n" +
" *enum* _AccountType_ { + \n" +
" ASSET, + \n" +
" LIABILITY, + \n" +
" EQUITY, + \n" +
" REVENUE, + \n" +
" EXPENSE + \n" +
"}"),
fieldWithPath("identifier").description("Sub Ledger identifier"),
fieldWithPath("name").description("Name of sub ledger"),
fieldWithPath("description").description("Description of sub ledger"),
fieldWithPath("showAccountsInChart").type("Boolean").description("Should ledger be shown in charts ?")
)));
}
@Test
public void documentModifyLedger ( ) throws Exception {
final Ledger ledger = LedgerGenerator.createRandomLedger();
ledger.setIdentifier("6210");
ledger.setName("Old Name Of" + ledger.getIdentifier());
ledger.setDescription("Old Description Of " + ledger.getIdentifier());
this.testSubject.createLedger(ledger);
this.eventRecorder.wait(EventConstants.POST_LEDGER, ledger.getIdentifier());
ledger.setName("New Name Of " + ledger.getIdentifier());
ledger.setDescription("New Description Of " + ledger.getIdentifier());
ledger.setShowAccountsInChart(Boolean.TRUE);
Gson gson = new Gson();
this.mockMvc.perform(put("/ledgers/" + ledger.getIdentifier())
.contentType(MediaType.APPLICATION_JSON_VALUE)
.accept(MediaType.APPLICATION_JSON_VALUE)
.content(gson.toJson(ledger)))
.andExpect(status().isAccepted())
.andDo(document("document-modify-ledger", preprocessRequest(prettyPrint()), preprocessResponse(prettyPrint()),
requestFields(
fieldWithPath("type").description("Type of Ledger " +
" + \n" +
" + \n" +
" *enum* _AccountType_ { + \n" +
" ASSET, + \n" +
" LIABILITY, + \n" +
" EQUITY, + \n" +
" REVENUE, + \n" +
" EXPENSE + \n" +
"}"),
fieldWithPath("identifier").description("Sub Ledger identifier"),
fieldWithPath("name").description("Name of sub ledger"),
fieldWithPath("description").description("Description of sub ledger"),
fieldWithPath("showAccountsInChart").type("Boolean").description("Should ledger be shown in charts ?")
)));
}
@Test
public void documentDeleteLedger ( ) throws Exception {
final Ledger ledger = LedgerGenerator.createRandomLedger();
ledger.setIdentifier("6200");
ledger.setName("Old Name Of" + ledger.getIdentifier());
ledger.setDescription("Old Description Of " + ledger.getIdentifier());
this.testSubject.createLedger(ledger);
this.eventRecorder.wait(EventConstants.POST_LEDGER, ledger.getIdentifier());
Gson gson = new Gson();
this.mockMvc.perform(delete("/ledgers/" + ledger.getIdentifier())
.contentType(MediaType.APPLICATION_JSON_VALUE)
.accept(MediaType.ALL_VALUE))
.andExpect(status().isAccepted())
.andDo(document("document-delete-ledger", preprocessRequest(prettyPrint()), preprocessResponse(prettyPrint())));
}
@Test
public void documentFetchAccountsForLedger ( ) throws Exception {
Set <String> holdersListOne = new HashSet <>();
String holderOne = "Holder One";
holdersListOne.add(holderOne);
Set <String> signatoriesOne = new HashSet <>();
String signatureOne = "Signatory One";
signatoriesOne.add(signatureOne);
final Ledger liabilityLedger = LedgerGenerator.createRandomLedger();
liabilityLedger.setType(AccountType.LIABILITY.name());
liabilityLedger.setIdentifier("6100");
this.testSubject.createLedger(liabilityLedger);
this.eventRecorder.wait(EventConstants.POST_LEDGER, liabilityLedger.getIdentifier());
final List <Account> createdLiabilityAccounts = Stream.generate(( ) -> AccountGenerator.createRandomAccount(liabilityLedger.getIdentifier())).limit(1)
.peek(account -> {
account.setType(AccountType.LIABILITY.name());
account.setIdentifier("6100.10");
account.setName("First Account Of " + liabilityLedger.getIdentifier());
account.setHolders(holdersListOne);
account.setSignatureAuthorities(signatoriesOne);
account.setBalance(1234.0);
account.setLedger(liabilityLedger.getIdentifier());
this.testSubject.createAccount(account);
})
.collect(Collectors.toList());
createdLiabilityAccounts.stream().forEach(
account -> {
try {
this.eventRecorder.wait(EventConstants.POST_ACCOUNT, account.getIdentifier());
} catch (InterruptedException e) {
e.printStackTrace();
}
});
final AccountPage accountPage =
this.testSubject.fetchAccounts(true, liabilityLedger.getIdentifier(), null, true,
0, createdLiabilityAccounts.size(), null, null);
accountPage.setAccounts(createdLiabilityAccounts);
accountPage.setTotalElements(new Long(createdLiabilityAccounts.size()));
accountPage.setTotalPages(1);
Gson gson = new Gson();
this.mockMvc.perform(get("/ledgers/" + liabilityLedger.getIdentifier() + "/accounts")
.contentType(MediaType.APPLICATION_JSON_VALUE)
.accept(MediaType.ALL_VALUE)
.content(gson.toJson(accountPage)))
.andExpect(status().isOk())
.andDo(document("document-fetch-accounts-for-ledger", preprocessRequest(prettyPrint()), preprocessResponse(prettyPrint()),
requestFields(
fieldWithPath("accounts").type("List<Account>").description("List of Accounts"),
fieldWithPath("accounts[].type").description("AccountType").description("Type of first Account " +
" + \n" +
" + \n" +
" *enum* _AccountType_ { + \n" +
" ASSET, + \n" +
" LIABILITY, + \n" +
" EQUITY, + \n" +
" REVENUE, + \n" +
" EXPENSE + \n" +
"}"),
fieldWithPath("accounts[].identifier").type("String").description("first account identifier"),
fieldWithPath("accounts[].name").type("String").description("first account name"),
fieldWithPath("accounts[].holders").type("Set<String>").description("Set of account holders"),
fieldWithPath("accounts[].signatureAuthorities").type("Set<String>").description("Set of signatories to account"),
fieldWithPath("accounts[].balance").type("Double").description("first account's balance"),
fieldWithPath("accounts[].ledger").type("String").description("Associated ledger"),
fieldWithPath("totalPages").type("Integer").description("Total pages"),
fieldWithPath("totalElements").type("Integer").description("Total accounts in page")
),
responseFields(
fieldWithPath("accounts").type("List<Account>").description("List of Accounts"),
fieldWithPath("totalPages").type("Integer").description("Total number of pages"),
fieldWithPath("totalElements").type("String").description("Total number of elements")
)));
}
}
| 4,734 |
0 | Create_ds/fineract-cn-accounting/component-test/src/main/java/org/apache/fineract/cn | Create_ds/fineract-cn-accounting/component-test/src/main/java/org/apache/fineract/cn/accounting/AbstractAccountingTest.java | /*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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.apache.fineract.cn.accounting;
import org.apache.fineract.cn.accounting.api.v1.EventConstants;
import org.apache.fineract.cn.accounting.api.v1.client.LedgerManager;
import org.apache.fineract.cn.accounting.service.AccountingServiceConfiguration;
import org.apache.fineract.cn.anubis.test.v1.TenantApplicationSecurityEnvironmentTestRule;
import org.apache.fineract.cn.api.context.AutoUserContext;
import org.apache.fineract.cn.test.fixture.TenantDataStoreContextTestRule;
import org.apache.fineract.cn.test.listener.EnableEventRecording;
import org.apache.fineract.cn.test.listener.EventRecorder;
import org.junit.After;
import org.junit.Before;
import org.junit.ClassRule;
import org.junit.Rule;
import org.junit.runner.RunWith;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.cloud.netflix.feign.EnableFeignClients;
import org.springframework.cloud.netflix.ribbon.RibbonClient;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import org.springframework.test.context.junit4.SpringRunner;
/**
* @author Myrle Krantz
*/
@SuppressWarnings("SpringAutowiredFieldsWarningInspection")
@RunWith(SpringRunner.class)
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT,
classes = {AbstractAccountingTest.TestConfiguration.class})
public class AbstractAccountingTest extends SuiteTestEnvironment{
protected static final String TEST_USER = "setna";
public static final String TEST_LOGGER = "test-logger";
@ClassRule
public final static TenantDataStoreContextTestRule tenantDataStoreContext = TenantDataStoreContextTestRule.forRandomTenantName(cassandraInitializer, postgreSQLInitializer);
@Rule
public final TenantApplicationSecurityEnvironmentTestRule tenantApplicationSecurityEnvironment
= new TenantApplicationSecurityEnvironmentTestRule(testEnvironment, this::waitForInitialize);
@Autowired
protected LedgerManager testSubject;
@Autowired
@Qualifier(TEST_LOGGER)
protected Logger logger;
@Autowired
protected EventRecorder eventRecorder;
private AutoUserContext autoUserContext;
public AbstractAccountingTest() {
super();
}
@Before
public void prepTest() throws Exception {
this.autoUserContext = this.tenantApplicationSecurityEnvironment.createAutoUserContext(AbstractAccountingTest.TEST_USER);
}
@After
public void cleanTest() throws Exception {
this.autoUserContext.close();
}
public boolean waitForInitialize() {
try {
return this.eventRecorder.wait(EventConstants.INITIALIZE, "1");
} catch (final InterruptedException e) {
throw new IllegalStateException(e);
}
}
@Configuration
@EnableEventRecording
@EnableFeignClients(basePackages = {"org.apache.fineract.cn.accounting.api.v1"})
@Import({AccountingServiceConfiguration.class})
@ComponentScan("org.apache.fineract.cn.accounting.listener")
public static class TestConfiguration {
public TestConfiguration() {
super();
}
@Bean(name= TEST_LOGGER)
public Logger logger() {
return LoggerFactory.getLogger(TEST_LOGGER);
}
}
}
| 4,735 |
0 | Create_ds/fineract-cn-accounting/component-test/src/main/java/org/apache/fineract/cn | Create_ds/fineract-cn-accounting/component-test/src/main/java/org/apache/fineract/cn/accounting/SuiteTestEnvironment.java | /*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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.apache.fineract.cn.accounting;
import org.apache.fineract.cn.test.env.TestEnvironment;
import org.apache.fineract.cn.test.fixture.cassandra.CassandraInitializer;
import org.apache.fineract.cn.test.fixture.postgresql.PostgreSQLInitializer;
import org.junit.ClassRule;
import org.junit.rules.RuleChain;
import org.junit.rules.RunExternalResourceOnce;
import org.junit.rules.TestRule;
/**
* @author Myrle Krantz
*/
public class SuiteTestEnvironment {
static final String APP_NAME = "accounting-v1";
static final TestEnvironment testEnvironment = new TestEnvironment(APP_NAME);
static final CassandraInitializer cassandraInitializer = new CassandraInitializer();
static final PostgreSQLInitializer postgreSQLInitializer = new PostgreSQLInitializer();
@ClassRule
public static TestRule orderClassRules = RuleChain
.outerRule(new RunExternalResourceOnce(testEnvironment))
.around(new RunExternalResourceOnce(cassandraInitializer))
.around(new RunExternalResourceOnce(postgreSQLInitializer));
} | 4,736 |
0 | Create_ds/fineract-cn-accounting/component-test/src/main/java/org/apache/fineract/cn | Create_ds/fineract-cn-accounting/component-test/src/main/java/org/apache/fineract/cn/accounting/IncomeStatementApiDocumentation.java | /*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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.apache.fineract.cn.accounting;
import org.apache.fineract.cn.accounting.api.v1.EventConstants;
import org.apache.fineract.cn.accounting.api.v1.domain.Account;
import org.apache.fineract.cn.accounting.api.v1.domain.AccountType;
import org.apache.fineract.cn.accounting.api.v1.domain.JournalEntry;
import org.apache.fineract.cn.accounting.api.v1.domain.Ledger;
import org.apache.fineract.cn.accounting.util.AccountGenerator;
import org.apache.fineract.cn.accounting.util.JournalEntryGenerator;
import org.apache.fineract.cn.accounting.util.LedgerGenerator;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.restdocs.JUnitRestDocumentation;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
import org.springframework.web.context.WebApplicationContext;
import static org.springframework.restdocs.mockmvc.MockMvcRestDocumentation.document;
import static org.springframework.restdocs.mockmvc.MockMvcRestDocumentation.documentationConfiguration;
import static org.springframework.restdocs.mockmvc.RestDocumentationRequestBuilders.get;
import static org.springframework.restdocs.operation.preprocess.Preprocessors.preprocessRequest;
import static org.springframework.restdocs.operation.preprocess.Preprocessors.preprocessResponse;
import static org.springframework.restdocs.operation.preprocess.Preprocessors.prettyPrint;
import static org.springframework.restdocs.payload.PayloadDocumentation.fieldWithPath;
import static org.springframework.restdocs.payload.PayloadDocumentation.responseFields;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
public class IncomeStatementApiDocumentation extends AbstractAccountingTest {
@Rule
public final JUnitRestDocumentation restDocumentation = new JUnitRestDocumentation("build/doc/generated-snippets/test-income-statement");
@Autowired
private WebApplicationContext context;
private MockMvc mockMvc;
@Before
public void setUp ( ) {
this.mockMvc = MockMvcBuilders.webAppContextSetup(this.context)
.apply(documentationConfiguration(this.restDocumentation))
.alwaysDo(document("{method-name}", preprocessRequest(prettyPrint()), preprocessResponse(prettyPrint())))
.build();
}
@Test
public void documentReturnIncomeStatement ( ) throws Exception {
this.fixtures();
this.sampleJournalEntries();
this.mockMvc.perform(get("/incomestatement")
.contentType(MediaType.APPLICATION_JSON_VALUE)
.accept(MediaType.ALL_VALUE))
.andExpect(status().isOk())
.andDo(document("document-return-income-statement", preprocessRequest(prettyPrint()), preprocessResponse(prettyPrint()),
responseFields(
fieldWithPath("date").type("String").description("Date Of Income Statement Preparation"),
fieldWithPath("incomeStatementSections[].type").description("Type").description("Type of first section " +
" + \n" +
" + \n" +
" *enum* _Type_ { + \n" +
" INCOME, + \n" +
" EXPENSES + \n" +
"}"),
fieldWithPath("incomeStatementSections[].description").type("String").description("first section's description"),
fieldWithPath("incomeStatementSections[].incomeStatementEntries[].description").type("String").description("first entry's description"),
fieldWithPath("incomeStatementSections[].incomeStatementEntries[].value").type("BigDecimal").description("first entry's value"),
fieldWithPath("incomeStatementSections[].incomeStatementEntries[1].description").type("String").description("second entry's description"),
fieldWithPath("incomeStatementSections[].incomeStatementEntries[1].value").type("BigDecimal").description("second entry's value"),
fieldWithPath("incomeStatementSections[].subtotal").type("BigDecimal").description("First section's subtotal"),
fieldWithPath("incomeStatementSections[1].type").description("Type").description("Type of first section " +
" + \n" +
" + \n" +
" *enum* _Type_ { + \n" +
" INCOME, + \n" +
" EXPENSES + \n" +
"}"),
fieldWithPath("incomeStatementSections[1].description").type("String").description("first section's description"),
fieldWithPath("incomeStatementSections[1].incomeStatementEntries[].description").type("String").description("first entry's description"),
fieldWithPath("incomeStatementSections[1].incomeStatementEntries[].value").type("BigDecimal").description("first entry's value"),
fieldWithPath("incomeStatementSections[1].incomeStatementEntries[1].description").type("String").description("second entry's description"),
fieldWithPath("incomeStatementSections[1].incomeStatementEntries[1].value").type("BigDecimal").description("second entry's value"),
fieldWithPath("incomeStatementSections[1].subtotal").type("BigDecimal").description("First section's subtotal"),
fieldWithPath("grossProfit").type("BigDecimal").description("Gross Profit"),
fieldWithPath("totalExpenses").type("BigDecimal").description("Total Expenses"),
fieldWithPath("netIncome").type("BigDecimal").description("Net Income")
)));
}
private void fixtures ( ) throws Exception {
final Ledger incomeLedger = LedgerGenerator.createLedger("1170", AccountType.REVENUE);
incomeLedger.setName("Revenue");
super.testSubject.createLedger(incomeLedger);
Assert.assertTrue(super.eventRecorder.wait(EventConstants.POST_LEDGER, incomeLedger.getIdentifier()));
final Ledger incomeSubLedger1100 = LedgerGenerator.createLedger("1070", AccountType.REVENUE);
incomeSubLedger1100.setParentLedgerIdentifier(incomeLedger.getParentLedgerIdentifier());
incomeSubLedger1100.setName("Revenue From Loans");
super.testSubject.addSubLedger(incomeLedger.getIdentifier(), incomeSubLedger1100);
Assert.assertTrue(super.eventRecorder.wait(EventConstants.POST_LEDGER, incomeSubLedger1100.getIdentifier()));
final Ledger incomeSubLedger1300 = LedgerGenerator.createLedger("1370", AccountType.REVENUE);
incomeSubLedger1300.setParentLedgerIdentifier(incomeLedger.getParentLedgerIdentifier());
incomeSubLedger1300.setName("Fees");
super.testSubject.addSubLedger(incomeLedger.getIdentifier(), incomeSubLedger1300);
Assert.assertTrue(super.eventRecorder.wait(EventConstants.POST_LEDGER, incomeSubLedger1300.getIdentifier()));
final Account account1170 =
AccountGenerator.createAccount(incomeSubLedger1100.getIdentifier(), "1170", AccountType.REVENUE);
super.testSubject.createAccount(account1170);
Assert.assertTrue(super.eventRecorder.wait(EventConstants.POST_ACCOUNT, account1170.getIdentifier()));
final Account account1370 =
AccountGenerator.createAccount(incomeSubLedger1300.getIdentifier(), "1370", AccountType.REVENUE);
super.testSubject.createAccount(account1370);
Assert.assertTrue(super.eventRecorder.wait(EventConstants.POST_ACCOUNT, account1370.getIdentifier()));
final Ledger expenseLedger = LedgerGenerator.createLedger("3070", AccountType.EXPENSE);
expenseLedger.setName("Expenses");
super.testSubject.createLedger(expenseLedger);
Assert.assertTrue(super.eventRecorder.wait(EventConstants.POST_LEDGER, expenseLedger.getIdentifier()));
final Ledger expenseSubLedger3570 = LedgerGenerator.createLedger("3570", AccountType.EXPENSE);
expenseSubLedger3570.setParentLedgerIdentifier(expenseLedger.getParentLedgerIdentifier());
expenseSubLedger3570.setName("Annual Meeting Expenses");
super.testSubject.addSubLedger(expenseLedger.getIdentifier(), expenseSubLedger3570);
Assert.assertTrue(super.eventRecorder.wait(EventConstants.POST_LEDGER, expenseSubLedger3570.getIdentifier()));
final Ledger expenseSubLedger3770 = LedgerGenerator.createLedger("3770", AccountType.EXPENSE);
expenseSubLedger3770.setParentLedgerIdentifier(expenseLedger.getParentLedgerIdentifier());
expenseSubLedger3770.setName("Interest (Dividend) Expense");
super.testSubject.addSubLedger(expenseLedger.getIdentifier(), expenseSubLedger3770);
Assert.assertTrue(super.eventRecorder.wait(EventConstants.POST_LEDGER, expenseSubLedger3770.getIdentifier()));
final Account account3570 =
AccountGenerator.createAccount(expenseSubLedger3570.getIdentifier(), "3570", AccountType.EXPENSE);
super.testSubject.createAccount(account3570);
Assert.assertTrue(super.eventRecorder.wait(EventConstants.POST_ACCOUNT, account3570.getIdentifier()));
final Account account3770 =
AccountGenerator.createAccount(expenseSubLedger3770.getIdentifier(), "3770", AccountType.EXPENSE);
super.testSubject.createAccount(account3770);
Assert.assertTrue(super.eventRecorder.wait(EventConstants.POST_ACCOUNT, account3770.getIdentifier()));
final Ledger assetLedger = LedgerGenerator.createLedger("7070", AccountType.ASSET);
super.testSubject.createLedger(assetLedger);
Assert.assertTrue(super.eventRecorder.wait(EventConstants.POST_LEDGER, assetLedger.getIdentifier()));
final Account assetAccount =
AccountGenerator.createAccount(assetLedger.getIdentifier(), "7077", AccountType.ASSET);
super.testSubject.createAccount(assetAccount);
Assert.assertTrue(super.eventRecorder.wait(EventConstants.POST_ACCOUNT, assetAccount.getIdentifier()));
final Ledger liabilityLedger = LedgerGenerator.createLedger("8070", AccountType.LIABILITY);
super.testSubject.createLedger(liabilityLedger);
Assert.assertTrue(super.eventRecorder.wait(EventConstants.POST_LEDGER, liabilityLedger.getIdentifier()));
final Account liabilityAccount =
AccountGenerator.createAccount(liabilityLedger.getIdentifier(), "8077", AccountType.LIABILITY);
super.testSubject.createAccount(liabilityAccount);
Assert.assertTrue(super.eventRecorder.wait(EventConstants.POST_ACCOUNT, liabilityAccount.getIdentifier()));
}
private void sampleJournalEntries ( ) throws Exception {
final JournalEntry firstTransaction =
JournalEntryGenerator
.createRandomJournalEntry("7077", "150.00", "1170", "150.00");
super.testSubject.createJournalEntry(firstTransaction);
Assert.assertTrue(super.eventRecorder.wait(EventConstants.POST_JOURNAL_ENTRY, firstTransaction.getTransactionIdentifier()));
final JournalEntry secondTransaction =
JournalEntryGenerator
.createRandomJournalEntry("7077", "200.00", "1370", "200.00");
super.testSubject.createJournalEntry(secondTransaction);
Assert.assertTrue(super.eventRecorder.wait(EventConstants.POST_JOURNAL_ENTRY, secondTransaction.getTransactionIdentifier()));
final JournalEntry thirdTransaction =
JournalEntryGenerator
.createRandomJournalEntry("3570", "50.00", "8077", "50.00");
super.testSubject.createJournalEntry(thirdTransaction);
Assert.assertTrue(super.eventRecorder.wait(EventConstants.POST_JOURNAL_ENTRY, thirdTransaction.getTransactionIdentifier()));
final JournalEntry fourthTransaction =
JournalEntryGenerator
.createRandomJournalEntry("3770", "75.00", "8077", "75.00");
super.testSubject.createJournalEntry(fourthTransaction);
Assert.assertTrue(super.eventRecorder.wait(EventConstants.POST_JOURNAL_ENTRY, fourthTransaction.getTransactionIdentifier()));
}
}
| 4,737 |
0 | Create_ds/fineract-cn-accounting/component-test/src/main/java/org/apache/fineract/cn | Create_ds/fineract-cn-accounting/component-test/src/main/java/org/apache/fineract/cn/accounting/TestJournalEntry.java | /*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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.apache.fineract.cn.accounting;
import org.apache.fineract.cn.accounting.api.v1.EventConstants;
import org.apache.fineract.cn.accounting.api.v1.client.JournalEntryAlreadyExistsException;
import org.apache.fineract.cn.accounting.api.v1.client.JournalEntryValidationException;
import org.apache.fineract.cn.accounting.api.v1.domain.Account;
import org.apache.fineract.cn.accounting.api.v1.domain.AccountEntryPage;
import org.apache.fineract.cn.accounting.api.v1.domain.AccountType;
import org.apache.fineract.cn.accounting.api.v1.domain.JournalEntry;
import org.apache.fineract.cn.accounting.api.v1.domain.Ledger;
import org.apache.fineract.cn.accounting.util.AccountGenerator;
import org.apache.fineract.cn.accounting.util.JournalEntryGenerator;
import org.apache.fineract.cn.accounting.util.LedgerGenerator;
import java.math.BigDecimal;
import java.text.MessageFormat;
import java.time.LocalDate;
import java.time.OffsetDateTime;
import java.time.ZoneOffset;
import java.time.format.DateTimeFormatter;
import java.util.List;
import org.apache.commons.lang.RandomStringUtils;
import org.apache.fineract.cn.lang.DateConverter;
import org.junit.Assert;
import org.junit.Test;
public class TestJournalEntry extends AbstractAccountingTest {
@Test
public void shouldCreateJournalEntry() throws Exception {
final Ledger assetLedger = LedgerGenerator.createRandomLedger();
assetLedger.setType(AccountType.ASSET.name());
this.testSubject.createLedger(assetLedger);
this.eventRecorder.wait(EventConstants.POST_LEDGER, assetLedger.getIdentifier());
final Account debtorAccount = AccountGenerator.createRandomAccount(assetLedger.getIdentifier());
debtorAccount.setType(AccountType.ASSET.name());
debtorAccount.setBalance(100.00D);
this.testSubject.createAccount(debtorAccount);
this.eventRecorder.wait(EventConstants.POST_ACCOUNT, debtorAccount.getIdentifier());
final Ledger liabilityLedger = LedgerGenerator.createRandomLedger();
liabilityLedger.setType(AccountType.LIABILITY.name());
this.testSubject.createLedger(liabilityLedger);
this.eventRecorder.wait(EventConstants.POST_LEDGER, liabilityLedger.getIdentifier());
final Account creditorAccount = AccountGenerator.createRandomAccount(liabilityLedger.getIdentifier());
creditorAccount.setType(AccountType.LIABILITY.name());
creditorAccount.setBalance(100.00D);
this.testSubject.createAccount(creditorAccount);
this.eventRecorder.wait(EventConstants.POST_ACCOUNT, creditorAccount.getIdentifier());
final JournalEntry journalEntry = JournalEntryGenerator.createRandomJournalEntry(debtorAccount, "50.00",
creditorAccount, "50.00");
this.testSubject.createJournalEntry(journalEntry);
this.eventRecorder.wait(EventConstants.POST_JOURNAL_ENTRY, journalEntry.getTransactionIdentifier());
this.eventRecorder.wait(EventConstants.RELEASE_JOURNAL_ENTRY, journalEntry.getTransactionIdentifier());
final JournalEntry foundJournalEntry = this.testSubject.findJournalEntry(journalEntry.getTransactionIdentifier());
Assert.assertNotNull(foundJournalEntry);
Assert.assertEquals(JournalEntry.State.PROCESSED.name(), foundJournalEntry.getState());
Assert.assertEquals(journalEntry.getTransactionType(), foundJournalEntry.getTransactionType());
final Account modifiedDebtorAccount = this.testSubject.findAccount(debtorAccount.getIdentifier());
Assert.assertNotNull(modifiedDebtorAccount);
Assert.assertEquals(150.0D, modifiedDebtorAccount.getBalance(), 0.0D);
final Account modifiedCreditorAccount = this.testSubject.findAccount(creditorAccount.getIdentifier());
Assert.assertNotNull(modifiedCreditorAccount);
Assert.assertEquals(150.0d, modifiedCreditorAccount.getBalance(), 0.0D);
}
@Test
public void shouldFetchJournalEntriesWithDateRange() throws Exception{
final Ledger assetLedger = LedgerGenerator.createRandomLedger();
assetLedger.setType(AccountType.ASSET.name());
this.testSubject.createLedger(assetLedger);
this.eventRecorder.wait(EventConstants.POST_LEDGER, assetLedger.getIdentifier());
final Account debtorAccount = AccountGenerator.createRandomAccount(assetLedger.getIdentifier());
debtorAccount.setType(AccountType.ASSET.name());
debtorAccount.setBalance(100.00D);
this.testSubject.createAccount(debtorAccount);
this.eventRecorder.wait(EventConstants.POST_ACCOUNT, debtorAccount.getIdentifier());
final Ledger liabilityLedger = LedgerGenerator.createRandomLedger();
liabilityLedger.setType(AccountType.LIABILITY.name());
this.testSubject.createLedger(liabilityLedger);
this.eventRecorder.wait(EventConstants.POST_LEDGER, liabilityLedger.getIdentifier());
final Account creditorAccount = AccountGenerator.createRandomAccount(liabilityLedger.getIdentifier());
creditorAccount.setType(AccountType.LIABILITY.name());
creditorAccount.setBalance(100.00D);
this.testSubject.createAccount(creditorAccount);
this.eventRecorder.wait(EventConstants.POST_ACCOUNT, creditorAccount.getIdentifier());
final JournalEntry journalEntryOne = JournalEntryGenerator.createRandomJournalEntry(debtorAccount, "50.00",
creditorAccount, "50.00");
final OffsetDateTime start = OffsetDateTime.of(1982, 6, 24, 1, 0, 0, 0, ZoneOffset.UTC);
journalEntryOne.setTransactionDate(start.format(DateTimeFormatter.ISO_ZONED_DATE_TIME));
this.testSubject.createJournalEntry(journalEntryOne);
this.eventRecorder.wait(EventConstants.POST_JOURNAL_ENTRY, journalEntryOne.getTransactionIdentifier());
this.eventRecorder.wait(EventConstants.RELEASE_JOURNAL_ENTRY, journalEntryOne.getTransactionIdentifier());
final JournalEntry journalEntryTwo = JournalEntryGenerator.createRandomJournalEntry(debtorAccount, "50.00",
creditorAccount, "50.00");
final OffsetDateTime end = OffsetDateTime.of(1982, 6, 26, 1, 0, 0, 0, ZoneOffset.UTC);
journalEntryTwo.setTransactionDate(end.format(DateTimeFormatter.ISO_ZONED_DATE_TIME));
this.testSubject.createJournalEntry(journalEntryTwo);
this.eventRecorder.wait(EventConstants.POST_JOURNAL_ENTRY, journalEntryTwo.getTransactionIdentifier());
this.eventRecorder.wait(EventConstants.RELEASE_JOURNAL_ENTRY, journalEntryTwo.getTransactionIdentifier());
final LocalDate beginDate = LocalDate.of(1982, 6, 24);
final LocalDate endDate = LocalDate.of(1982, 6, 26);
final String dateRange = MessageFormat.format("{0}..{1}",
DateConverter.toIsoString(beginDate),
DateConverter.toIsoString(endDate));
final List<JournalEntry> journalEntries = this.testSubject.fetchJournalEntries(dateRange, null, null);
Assert.assertTrue(journalEntries.size() >= 2);
checkAccountEntries(debtorAccount, creditorAccount, journalEntryOne, journalEntryTwo, dateRange);
}
@Test
public void shouldFetchJournalEntriesWithDateRangeAndAccount() throws Exception{
final Ledger assetLedger = LedgerGenerator.createRandomLedger();
assetLedger.setType(AccountType.ASSET.name());
this.testSubject.createLedger(assetLedger);
this.eventRecorder.wait(EventConstants.POST_LEDGER, assetLedger.getIdentifier());
final Account debtorAccount = AccountGenerator.createRandomAccount(assetLedger.getIdentifier());
debtorAccount.setType(AccountType.ASSET.name());
debtorAccount.setBalance(100.00D);
this.testSubject.createAccount(debtorAccount);
this.eventRecorder.wait(EventConstants.POST_ACCOUNT, debtorAccount.getIdentifier());
final Ledger liabilityLedger = LedgerGenerator.createRandomLedger();
liabilityLedger.setType(AccountType.LIABILITY.name());
this.testSubject.createLedger(liabilityLedger);
this.eventRecorder.wait(EventConstants.POST_LEDGER, liabilityLedger.getIdentifier());
final Account creditorAccount = AccountGenerator.createRandomAccount(liabilityLedger.getIdentifier());
creditorAccount.setType(AccountType.LIABILITY.name());
creditorAccount.setBalance(100.00D);
this.testSubject.createAccount(creditorAccount);
this.eventRecorder.wait(EventConstants.POST_ACCOUNT, creditorAccount.getIdentifier());
final JournalEntry journalEntryOne = JournalEntryGenerator.createRandomJournalEntry(debtorAccount, "50.00",
creditorAccount, "50.00");
final OffsetDateTime start = OffsetDateTime.of(1982, 6, 24, 1, 0, 0, 0, ZoneOffset.UTC);
journalEntryOne.setTransactionDate(start.format(DateTimeFormatter.ISO_ZONED_DATE_TIME));
this.testSubject.createJournalEntry(journalEntryOne);
this.eventRecorder.wait(EventConstants.POST_JOURNAL_ENTRY, journalEntryOne.getTransactionIdentifier());
this.eventRecorder.wait(EventConstants.RELEASE_JOURNAL_ENTRY, journalEntryOne.getTransactionIdentifier());
final JournalEntry journalEntryTwo = JournalEntryGenerator.createRandomJournalEntry(debtorAccount, "50.00",
creditorAccount, "50.00");
final OffsetDateTime end = OffsetDateTime.of(1982, 6, 26, 1, 0, 0, 0, ZoneOffset.UTC);
journalEntryTwo.setTransactionDate(end.format(DateTimeFormatter.ISO_ZONED_DATE_TIME));
this.testSubject.createJournalEntry(journalEntryTwo);
this.eventRecorder.wait(EventConstants.POST_JOURNAL_ENTRY, journalEntryTwo.getTransactionIdentifier());
this.eventRecorder.wait(EventConstants.RELEASE_JOURNAL_ENTRY, journalEntryTwo.getTransactionIdentifier());
final LocalDate beginDate = LocalDate.of(1982, 6, 24);
final LocalDate endDate = LocalDate.of(1982, 6, 26);
final String dateRange = MessageFormat.format("{0}..{1}",
DateConverter.toIsoString(beginDate),
DateConverter.toIsoString(endDate));
final List<JournalEntry> journalEntries = this.testSubject.fetchJournalEntries(dateRange, debtorAccount.getIdentifier(), null);
Assert.assertEquals(2, journalEntries.size());
checkAccountEntries(debtorAccount, creditorAccount, journalEntryOne, journalEntryTwo, dateRange);
}
@Test
public void shouldFetchJournalEntriesWithDateRangeAndAmount() throws Exception{
final Ledger assetLedger = LedgerGenerator.createRandomLedger();
assetLedger.setType(AccountType.ASSET.name());
this.testSubject.createLedger(assetLedger);
this.eventRecorder.wait(EventConstants.POST_LEDGER, assetLedger.getIdentifier());
final Account debtorAccount = AccountGenerator.createRandomAccount(assetLedger.getIdentifier());
debtorAccount.setType(AccountType.ASSET.name());
debtorAccount.setBalance(100.00D);
this.testSubject.createAccount(debtorAccount);
this.eventRecorder.wait(EventConstants.POST_ACCOUNT, debtorAccount.getIdentifier());
final Ledger liabilityLedger = LedgerGenerator.createRandomLedger();
liabilityLedger.setType(AccountType.LIABILITY.name());
this.testSubject.createLedger(liabilityLedger);
this.eventRecorder.wait(EventConstants.POST_LEDGER, liabilityLedger.getIdentifier());
final Account creditorAccount = AccountGenerator.createRandomAccount(liabilityLedger.getIdentifier());
creditorAccount.setType(AccountType.LIABILITY.name());
creditorAccount.setBalance(100.00D);
this.testSubject.createAccount(creditorAccount);
this.eventRecorder.wait(EventConstants.POST_ACCOUNT, creditorAccount.getIdentifier());
final JournalEntry journalEntryOne = JournalEntryGenerator.createRandomJournalEntry(debtorAccount, "50.00",
creditorAccount, "50.00");
final OffsetDateTime start = OffsetDateTime.of(1982, 6, 24, 1, 0, 0, 0, ZoneOffset.UTC);
journalEntryOne.setTransactionDate(start.format(DateTimeFormatter.ISO_ZONED_DATE_TIME));
this.testSubject.createJournalEntry(journalEntryOne);
this.eventRecorder.wait(EventConstants.POST_JOURNAL_ENTRY, journalEntryOne.getTransactionIdentifier());
this.eventRecorder.wait(EventConstants.RELEASE_JOURNAL_ENTRY, journalEntryOne.getTransactionIdentifier());
final JournalEntry journalEntryTwo = JournalEntryGenerator.createRandomJournalEntry(debtorAccount, "50.00",
creditorAccount, "50.00");
final OffsetDateTime end = OffsetDateTime.of(1982, 6, 26, 1, 0, 0, 0, ZoneOffset.UTC);
journalEntryTwo.setTransactionDate(end.format(DateTimeFormatter.ISO_ZONED_DATE_TIME));
this.testSubject.createJournalEntry(journalEntryTwo);
this.eventRecorder.wait(EventConstants.POST_JOURNAL_ENTRY, journalEntryTwo.getTransactionIdentifier());
this.eventRecorder.wait(EventConstants.RELEASE_JOURNAL_ENTRY, journalEntryTwo.getTransactionIdentifier());
final LocalDate beginDate = LocalDate.of(1982, 6, 24);
final LocalDate endDate = LocalDate.of(1982, 6, 26);
final String dateRange = MessageFormat.format("{0}..{1}",
DateConverter.toIsoString(beginDate),
DateConverter.toIsoString(endDate));
final List<JournalEntry> journalEntries = this.testSubject.fetchJournalEntries(dateRange, null, BigDecimal.valueOf(50.00D));
Assert.assertEquals(2, journalEntries.size());
checkAccountEntries(debtorAccount, creditorAccount, journalEntryOne, journalEntryTwo, dateRange);
}
@Test
public void shouldFetchJournalEntriesWithDateRangeAndAccountAndAmount() throws Exception{
final Ledger assetLedger = LedgerGenerator.createRandomLedger();
assetLedger.setType(AccountType.ASSET.name());
this.testSubject.createLedger(assetLedger);
this.eventRecorder.wait(EventConstants.POST_LEDGER, assetLedger.getIdentifier());
final Account debtorAccount = AccountGenerator.createRandomAccount(assetLedger.getIdentifier());
debtorAccount.setType(AccountType.ASSET.name());
debtorAccount.setBalance(100.00D);
this.testSubject.createAccount(debtorAccount);
this.eventRecorder.wait(EventConstants.POST_ACCOUNT, debtorAccount.getIdentifier());
final Ledger liabilityLedger = LedgerGenerator.createRandomLedger();
liabilityLedger.setType(AccountType.LIABILITY.name());
this.testSubject.createLedger(liabilityLedger);
this.eventRecorder.wait(EventConstants.POST_LEDGER, liabilityLedger.getIdentifier());
final Account creditorAccount = AccountGenerator.createRandomAccount(liabilityLedger.getIdentifier());
creditorAccount.setType(AccountType.LIABILITY.name());
creditorAccount.setBalance(100.00D);
this.testSubject.createAccount(creditorAccount);
this.eventRecorder.wait(EventConstants.POST_ACCOUNT, creditorAccount.getIdentifier());
final JournalEntry journalEntryOne = JournalEntryGenerator.createRandomJournalEntry(debtorAccount, "50.00",
creditorAccount, "50.00");
final OffsetDateTime start = OffsetDateTime.of(1982, 6, 24, 1, 0, 0, 0, ZoneOffset.UTC);
journalEntryOne.setTransactionDate(start.format(DateTimeFormatter.ISO_ZONED_DATE_TIME));
this.testSubject.createJournalEntry(journalEntryOne);
this.eventRecorder.wait(EventConstants.POST_JOURNAL_ENTRY, journalEntryOne.getTransactionIdentifier());
this.eventRecorder.wait(EventConstants.RELEASE_JOURNAL_ENTRY, journalEntryOne.getTransactionIdentifier());
final JournalEntry journalEntryTwo = JournalEntryGenerator.createRandomJournalEntry(debtorAccount, "50.00",
creditorAccount, "50.00");
final OffsetDateTime end = OffsetDateTime.of(1982, 6, 26, 1, 0, 0, 0, ZoneOffset.UTC);
journalEntryTwo.setTransactionDate(end.format(DateTimeFormatter.ISO_ZONED_DATE_TIME));
this.testSubject.createJournalEntry(journalEntryTwo);
this.eventRecorder.wait(EventConstants.POST_JOURNAL_ENTRY, journalEntryTwo.getTransactionIdentifier());
this.eventRecorder.wait(EventConstants.RELEASE_JOURNAL_ENTRY, journalEntryTwo.getTransactionIdentifier());
final LocalDate beginDate = LocalDate.of(1982, 6, 24);
final LocalDate endDate = LocalDate.of(1982, 6, 26);
final String dateRange = MessageFormat.format("{0}..{1}",
DateConverter.toIsoString(beginDate),
DateConverter.toIsoString(endDate));
final List<JournalEntry> journalEntries = this.testSubject.fetchJournalEntries(dateRange, creditorAccount.getIdentifier(), BigDecimal.valueOf(50.00D));
Assert.assertEquals(2, journalEntries.size());
checkAccountEntries(debtorAccount, creditorAccount, journalEntryOne, journalEntryTwo, dateRange);
}
@Test(expected = JournalEntryValidationException.class)
public void shouldNotCreateJournalEntryMissingDebtors() throws Exception {
final Ledger liabilityLedger = LedgerGenerator.createRandomLedger();
liabilityLedger.setType(AccountType.LIABILITY.name());
this.testSubject.createLedger(liabilityLedger);
this.eventRecorder.wait(EventConstants.POST_LEDGER, liabilityLedger.getIdentifier());
final Account creditorAccount = AccountGenerator.createRandomAccount(liabilityLedger.getIdentifier());
creditorAccount.setType(AccountType.LIABILITY.name());
creditorAccount.setBalance(100.00D);
this.testSubject.createAccount(creditorAccount);
this.eventRecorder.wait(EventConstants.POST_ACCOUNT, creditorAccount.getIdentifier());
final JournalEntry journalEntry = JournalEntryGenerator.createRandomJournalEntry(null, null,
creditorAccount, "50.00");
this.testSubject.createJournalEntry(journalEntry);
}
@Test(expected = JournalEntryAlreadyExistsException.class)
public void shouldNotCreateJournalAlreadyExists() throws Exception {
final Ledger assetLedger = LedgerGenerator.createRandomLedger();
assetLedger.setType(AccountType.ASSET.name());
this.testSubject.createLedger(assetLedger);
this.eventRecorder.wait(EventConstants.POST_LEDGER, assetLedger.getIdentifier());
final Account debtorAccount = AccountGenerator.createRandomAccount(assetLedger.getIdentifier());
debtorAccount.setType(AccountType.ASSET.name());
debtorAccount.setBalance(100.00D);
this.testSubject.createAccount(debtorAccount);
this.eventRecorder.wait(EventConstants.POST_ACCOUNT, debtorAccount.getIdentifier());
final Ledger liabilityLedger = LedgerGenerator.createRandomLedger();
liabilityLedger.setType(AccountType.LIABILITY.name());
this.testSubject.createLedger(liabilityLedger);
this.eventRecorder.wait(EventConstants.POST_LEDGER, liabilityLedger.getIdentifier());
final Account creditorAccount = AccountGenerator.createRandomAccount(liabilityLedger.getIdentifier());
creditorAccount.setType(AccountType.LIABILITY.name());
creditorAccount.setBalance(100.00D);
this.testSubject.createAccount(creditorAccount);
this.eventRecorder.wait(EventConstants.POST_ACCOUNT, creditorAccount.getIdentifier());
final JournalEntry journalEntry = JournalEntryGenerator.createRandomJournalEntry(creditorAccount, "50.00",
creditorAccount, "50.00");
this.testSubject.createJournalEntry(journalEntry);
this.eventRecorder.wait(EventConstants.POST_JOURNAL_ENTRY, journalEntry.getTransactionIdentifier());
this.testSubject.createJournalEntry(journalEntry);
}
@Test(expected = JournalEntryValidationException.class)
public void shouldNotCreateJournalEntryMissingCreditors() throws Exception {
final Ledger assetLedger = LedgerGenerator.createRandomLedger();
assetLedger.setType(AccountType.ASSET.name());
this.testSubject.createLedger(assetLedger);
this.eventRecorder.wait(EventConstants.POST_LEDGER, assetLedger.getIdentifier());
final Account debtorAccount = AccountGenerator.createRandomAccount(assetLedger.getIdentifier());
debtorAccount.setType(AccountType.ASSET.name());
debtorAccount.setBalance(100.00D);
this.testSubject.createAccount(debtorAccount);
this.eventRecorder.wait(EventConstants.POST_ACCOUNT, debtorAccount.getIdentifier());
final JournalEntry journalEntry = JournalEntryGenerator.createRandomJournalEntry(debtorAccount, "50.00",
null, null);
this.testSubject.createJournalEntry(journalEntry);
}
private void checkAccountEntries(
final Account debtorAccount,
final Account creditorAccount,
final JournalEntry journalEntryOne,
final JournalEntry journalEntryTwo,
final String dateRange) {
final AccountEntryPage creditorAccountEntries = this.testSubject.fetchAccountEntries(
creditorAccount.getIdentifier(),
dateRange,
null,
null,
null,
null,
"ASC");
Assert.assertEquals(Long.valueOf(2L), creditorAccountEntries.getTotalElements());
Assert.assertEquals("Sort order check for ascending.",
journalEntryOne.getMessage(),
creditorAccountEntries.getAccountEntries().get(0).getMessage());
final AccountEntryPage creditorAccountEntriesWithMessage1 = this.testSubject.fetchAccountEntries(
creditorAccount.getIdentifier(),
dateRange,
journalEntryOne.getMessage(),
null,
null,
null,
null);
Assert.assertEquals(Long.valueOf(1L), creditorAccountEntriesWithMessage1.getTotalElements());
Assert.assertEquals("Correct entry returned.",
journalEntryOne.getMessage(),
creditorAccountEntriesWithMessage1.getAccountEntries().get(0).getMessage());
final AccountEntryPage debtorAccountEntries = this.testSubject.fetchAccountEntries(
debtorAccount.getIdentifier(),
dateRange,
null,
null,
null,
null,
"DESC");
Assert.assertEquals(Long.valueOf(2L), debtorAccountEntries.getTotalElements());
Assert.assertEquals("Sort order check for descending.",
journalEntryTwo.getMessage(),
debtorAccountEntries.getAccountEntries().get(0).getMessage());
final AccountEntryPage debtorAccountEntriesWithMessage2 = this.testSubject.fetchAccountEntries(
creditorAccount.getIdentifier(),
dateRange,
journalEntryTwo.getMessage(),
null,
null,
null,
null);
Assert.assertEquals(Long.valueOf(1L), debtorAccountEntriesWithMessage2.getTotalElements());
Assert.assertEquals("Correct entry returned.",
journalEntryTwo.getMessage(),
debtorAccountEntriesWithMessage2.getAccountEntries().get(0).getMessage());
final AccountEntryPage debtorAccountEntriesWithRandomMessage = this.testSubject.fetchAccountEntries(
creditorAccount.getIdentifier(),
dateRange,
RandomStringUtils.randomAlphanumeric(20),
null,
null,
null,
null);
Assert.assertEquals(Long.valueOf(0L), debtorAccountEntriesWithRandomMessage.getTotalElements());
}
}
| 4,738 |
0 | Create_ds/fineract-cn-accounting/component-test/src/main/java/org/apache/fineract/cn | Create_ds/fineract-cn-accounting/component-test/src/main/java/org/apache/fineract/cn/accounting/TestFinancialCondition.java | /*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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.apache.fineract.cn.accounting;
import org.apache.fineract.cn.accounting.api.v1.EventConstants;
import org.apache.fineract.cn.accounting.api.v1.domain.Account;
import org.apache.fineract.cn.accounting.api.v1.domain.AccountType;
import org.apache.fineract.cn.accounting.api.v1.domain.JournalEntry;
import org.apache.fineract.cn.accounting.api.v1.domain.Ledger;
import org.apache.fineract.cn.accounting.api.v1.domain.financial.statement.FinancialCondition;
import org.apache.fineract.cn.accounting.util.AccountGenerator;
import org.apache.fineract.cn.accounting.util.JournalEntryGenerator;
import org.apache.fineract.cn.accounting.util.LedgerGenerator;
import org.junit.Assert;
import org.junit.Test;
import java.math.BigDecimal;
public class TestFinancialCondition extends AbstractAccountingTest {
public TestFinancialCondition() {
super();
}
@Test
public void shouldReturnFinancialCondition() throws Exception {
this.fixtures();
this.sampleJournalEntries();
final BigDecimal totalAssets = BigDecimal.valueOf(250.00D);
final BigDecimal expectedEquitiesAndLiabilities = BigDecimal.valueOf(250.00D);
final FinancialCondition financialCondition = super.testSubject.getFinancialCondition();
Assert.assertTrue(financialCondition.getTotalAssets().compareTo(totalAssets) == 0);
Assert.assertTrue(financialCondition.getTotalEquitiesAndLiabilities().compareTo(expectedEquitiesAndLiabilities) == 0);
}
private void fixtures() throws Exception {
final Ledger assetLedger = LedgerGenerator.createLedger("7000", AccountType.ASSET);
assetLedger.setName("Assets");
super.testSubject.createLedger(assetLedger);
Assert.assertTrue(super.eventRecorder.wait(EventConstants.POST_LEDGER, assetLedger.getIdentifier()));
final Ledger assetSubLedger7010 = LedgerGenerator.createLedger("7010", AccountType.ASSET);
assetSubLedger7010.setParentLedgerIdentifier(assetLedger.getParentLedgerIdentifier());
assetSubLedger7010.setName("Loans to Members");
super.testSubject.addSubLedger(assetLedger.getIdentifier(), assetSubLedger7010);
Assert.assertTrue(super.eventRecorder.wait(EventConstants.POST_LEDGER, assetSubLedger7010.getIdentifier()));
final Ledger assetSubLedger7020 = LedgerGenerator.createLedger("7020", AccountType.ASSET);
assetSubLedger7020.setParentLedgerIdentifier(assetLedger.getParentLedgerIdentifier());
assetSubLedger7020.setName("Lines of Credit to Members");
super.testSubject.addSubLedger(assetLedger.getIdentifier(), assetSubLedger7020);
Assert.assertTrue(super.eventRecorder.wait(EventConstants.POST_LEDGER, assetSubLedger7020.getIdentifier()));
final Account firstAssetAccount =
AccountGenerator.createAccount(assetSubLedger7010.getIdentifier(), "7011", AccountType.ASSET);
super.testSubject.createAccount(firstAssetAccount);
Assert.assertTrue(super.eventRecorder.wait(EventConstants.POST_ACCOUNT, firstAssetAccount.getIdentifier()));
final Account secondAssetAccount =
AccountGenerator.createAccount(assetSubLedger7020.getIdentifier(), "7021", AccountType.ASSET);
super.testSubject.createAccount(secondAssetAccount);
Assert.assertTrue(super.eventRecorder.wait(EventConstants.POST_ACCOUNT, secondAssetAccount.getIdentifier()));
final Ledger liabilityLedger = LedgerGenerator.createLedger("8000", AccountType.LIABILITY);
liabilityLedger.setName("Liabilities");
super.testSubject.createLedger(liabilityLedger);
Assert.assertTrue(super.eventRecorder.wait(EventConstants.POST_LEDGER, liabilityLedger.getIdentifier()));
final Ledger liabilitySubLedger8100 = LedgerGenerator.createLedger("8100", AccountType.LIABILITY);
liabilitySubLedger8100.setParentLedgerIdentifier(liabilityLedger.getParentLedgerIdentifier());
liabilitySubLedger8100.setName("Accounts Payable");
super.testSubject.addSubLedger(liabilityLedger.getIdentifier(), liabilitySubLedger8100);
Assert.assertTrue(super.eventRecorder.wait(EventConstants.POST_LEDGER, liabilitySubLedger8100.getIdentifier()));
final Ledger liabilitySubLedger8200 = LedgerGenerator.createLedger("8200", AccountType.LIABILITY);
liabilitySubLedger8200.setParentLedgerIdentifier(liabilityLedger.getParentLedgerIdentifier());
liabilitySubLedger8200.setName("Interest Payable");
super.testSubject.addSubLedger(liabilityLedger.getIdentifier(), liabilitySubLedger8200);
Assert.assertTrue(super.eventRecorder.wait(EventConstants.POST_LEDGER, liabilitySubLedger8200.getIdentifier()));
final Account firstLiabilityAccount =
AccountGenerator.createAccount(liabilitySubLedger8100.getIdentifier(), "8110", AccountType.LIABILITY);
super.testSubject.createAccount(firstLiabilityAccount);
Assert.assertTrue(super.eventRecorder.wait(EventConstants.POST_ACCOUNT, firstLiabilityAccount.getIdentifier()));
final Account secondLiabilityAccount =
AccountGenerator.createAccount(liabilitySubLedger8200.getIdentifier(), "8210", AccountType.LIABILITY);
super.testSubject.createAccount(secondLiabilityAccount);
Assert.assertTrue(super.eventRecorder.wait(EventConstants.POST_ACCOUNT, secondLiabilityAccount.getIdentifier()));
final Ledger equityLedger = LedgerGenerator.createLedger("9000", AccountType.EQUITY);
equityLedger.setName("Equities");
super.testSubject.createLedger(equityLedger);
Assert.assertTrue(super.eventRecorder.wait(EventConstants.POST_LEDGER, equityLedger.getIdentifier()));
final Ledger equitySubLedger9100 = LedgerGenerator.createLedger("9100", AccountType.EQUITY);
equitySubLedger9100.setParentLedgerIdentifier(equityLedger.getParentLedgerIdentifier());
equitySubLedger9100.setName("Member Savings");
super.testSubject.addSubLedger(equityLedger.getIdentifier(), equitySubLedger9100);
Assert.assertTrue(super.eventRecorder.wait(EventConstants.POST_LEDGER, equitySubLedger9100.getIdentifier()));
final Account firstEquityAccount =
AccountGenerator.createAccount(equitySubLedger9100.getIdentifier(), "9110", AccountType.EQUITY);
super.testSubject.createAccount(firstEquityAccount);
Assert.assertTrue(super.eventRecorder.wait(EventConstants.POST_ACCOUNT, firstEquityAccount.getIdentifier()));
}
private void sampleJournalEntries() throws Exception {
final JournalEntry firstTransaction =
JournalEntryGenerator
.createRandomJournalEntry("7011", "150.00", "8110", "150.00");
super.testSubject.createJournalEntry(firstTransaction);
Assert.assertTrue(super.eventRecorder.wait(EventConstants.POST_JOURNAL_ENTRY, firstTransaction.getTransactionIdentifier()));
final JournalEntry secondTransaction =
JournalEntryGenerator
.createRandomJournalEntry("7021", "100.00", "8210", "100.00");
super.testSubject.createJournalEntry(secondTransaction);
Assert.assertTrue(super.eventRecorder.wait(EventConstants.POST_JOURNAL_ENTRY, secondTransaction.getTransactionIdentifier()));
final JournalEntry thirdTransaction =
JournalEntryGenerator
.createRandomJournalEntry("8210", "50.00", "9110", "50.00");
super.testSubject.createJournalEntry(thirdTransaction);
Assert.assertTrue(super.eventRecorder.wait(EventConstants.POST_JOURNAL_ENTRY, thirdTransaction.getTransactionIdentifier()));
}
}
| 4,739 |
0 | Create_ds/fineract-cn-accounting/component-test/src/main/java/org/apache/fineract/cn | Create_ds/fineract-cn-accounting/component-test/src/main/java/org/apache/fineract/cn/accounting/AccountApiDocumentation.java | /*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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.apache.fineract.cn.accounting;
import com.google.gson.Gson;
import org.apache.fineract.cn.accounting.api.v1.EventConstants;
import org.apache.fineract.cn.accounting.api.v1.domain.*;
import org.apache.fineract.cn.accounting.util.AccountGenerator;
import org.apache.fineract.cn.accounting.util.JournalEntryGenerator;
import org.apache.fineract.cn.accounting.util.LedgerGenerator;
import org.apache.fineract.cn.lang.DateRange;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Sort;
import org.springframework.http.MediaType;
import org.springframework.restdocs.JUnitRestDocumentation;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
import org.springframework.web.context.WebApplicationContext;
import java.math.BigDecimal;
import java.time.Clock;
import java.time.LocalDate;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import static org.springframework.restdocs.mockmvc.MockMvcRestDocumentation.document;
import static org.springframework.restdocs.mockmvc.MockMvcRestDocumentation.documentationConfiguration;
import static org.springframework.restdocs.mockmvc.RestDocumentationRequestBuilders.delete;
import static org.springframework.restdocs.mockmvc.RestDocumentationRequestBuilders.post;
import static org.springframework.restdocs.mockmvc.RestDocumentationRequestBuilders.get;
import static org.springframework.restdocs.mockmvc.RestDocumentationRequestBuilders.put;
import static org.springframework.restdocs.operation.preprocess.Preprocessors.preprocessRequest;
import static org.springframework.restdocs.operation.preprocess.Preprocessors.preprocessResponse;
import static org.springframework.restdocs.operation.preprocess.Preprocessors.prettyPrint;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
import static org.springframework.restdocs.payload.PayloadDocumentation.fieldWithPath;
import static org.springframework.restdocs.payload.PayloadDocumentation.requestFields;
import static org.springframework.restdocs.payload.PayloadDocumentation.responseFields;
public class AccountApiDocumentation extends AbstractAccountingTest {
@Rule
public final JUnitRestDocumentation restDocumentation = new JUnitRestDocumentation("build/doc/generated-snippets/test-account");
@Autowired
private WebApplicationContext context;
private MockMvc mockMvc;
@Before
public void setUp ( ) {
this.mockMvc = MockMvcBuilders.webAppContextSetup(this.context)
.apply(documentationConfiguration(this.restDocumentation))
.alwaysDo(document("{method-name}", preprocessRequest(prettyPrint()), preprocessResponse(prettyPrint())))
.build();
}
@Test
public void documentCreateAccount ( ) throws Exception {
final Ledger ledger = LedgerGenerator.createRandomLedger();
ledger.setType(AccountType.ASSET.name());
ledger.setIdentifier("1111");
ledger.setName("Receivables");
ledger.setDescription("Receivables Account");
Ledger rentsReceivable = LedgerGenerator.createLedger("10011", AccountType.ASSET);
Ledger tradeReceivables = LedgerGenerator.createLedger("10012", AccountType.ASSET);
List <Ledger> subLedgers = new ArrayList <>();
subLedgers.add(rentsReceivable);
subLedgers.add(tradeReceivables);
BigDecimal value = new BigDecimal(1000000);
ledger.setTotalValue(value);
ledger.setCreatedOn(LocalDate.ofYearDay(2017, 17).toString());
ledger.setCreatedBy("Epie E.");
ledger.setLastModifiedOn(LocalDate.ofYearDay(2018, 160).toString());
ledger.setLastModifiedBy("Epie Ngome");
ledger.setShowAccountsInChart(Boolean.TRUE);
this.testSubject.createLedger(ledger);
this.eventRecorder.wait(EventConstants.POST_LEDGER, ledger.getIdentifier());
final Account account = AccountGenerator.createRandomAccount(ledger.getIdentifier());
Set <String> holdersList = new HashSet <>();
String holderOne = "First Holder";
String holderTwo = "Second Holder";
holdersList.add(holderOne);
holdersList.add(holderTwo);
Set <String> signatories = new HashSet <>();
String signatureOne = "First To Sign";
String signatureTwo = "Second To Sign";
signatories.add(signatureOne);
signatories.add(signatureTwo);
Double bal = 105.0;
account.setType(AccountType.ASSET.name());
account.setIdentifier("10013");
account.setName("Interest Receivables");
account.setHolders(holdersList);
account.setSignatureAuthorities(signatories);
account.setBalance(bal);
account.setLedger(ledger.getIdentifier());
Gson gson = new Gson();
this.mockMvc.perform(post("/accounts")
.contentType(MediaType.APPLICATION_JSON_VALUE)
.accept(MediaType.APPLICATION_JSON_VALUE)
.content(gson.toJson(account)))
.andExpect(status().isAccepted())
.andDo(document("document-create-account", preprocessRequest(prettyPrint()), preprocessResponse(prettyPrint()),
requestFields(
fieldWithPath("type").description("Type of Account " +
" + \n" +
" + \n" +
" *enum* _AccountType_ { + \n" +
" ASSET, + \n" +
" LIABILITY, + \n" +
" EQUITY, + \n" +
" REVENUE, + \n" +
" EXPENSE + \n" +
"}"),
fieldWithPath("identifier").description("Account identifier"),
fieldWithPath("name").description("Name of account"),
fieldWithPath("holders").type("Set<String>").description("Account Holders"),
fieldWithPath("signatureAuthorities").type("Set<String>").description("Account signatories"),
fieldWithPath("balance").type("Double").description("Account balance"),
fieldWithPath("ledger").description("Associated ledger")
)));
}
@Test
public void documentFindAccount ( ) throws Exception {
final Ledger ledger = LedgerGenerator.createRandomLedger();
ledger.setIdentifier("1001");
this.testSubject.createLedger(ledger);
this.eventRecorder.wait(EventConstants.POST_LEDGER, ledger.getIdentifier());
final Account referenceAccount = AccountGenerator.createRandomAccount(ledger.getIdentifier());
referenceAccount.setIdentifier("1000");
this.testSubject.createAccount(referenceAccount);
this.eventRecorder.wait(EventConstants.POST_ACCOUNT, referenceAccount.getIdentifier());
final Account account = AccountGenerator.createRandomAccount(ledger.getIdentifier());
Set <String> holdersList = new HashSet <>();
String holderOne = "Holder One";
String holderTwo = "Holder Two";
holdersList.add(holderOne);
holdersList.add(holderTwo);
Set <String> signatories = new HashSet <>();
String signatureOne = "Signatory One";
String signatureTwo = "Signatory Two";
signatories.add(signatureOne);
signatories.add(signatureTwo);
Double bal = 906.4;
account.setType(AccountType.ASSET.name());
account.setIdentifier("1001");
account.setName("Receivables");
account.setHolders(holdersList);
account.setSignatureAuthorities(signatories);
account.setBalance(bal);
account.setLedger(ledger.getIdentifier());
account.setReferenceAccount(referenceAccount.getIdentifier());
this.testSubject.createAccount(account);
this.eventRecorder.wait(EventConstants.POST_ACCOUNT, account.getIdentifier());
Gson gson = new Gson();
this.mockMvc.perform(get("/accounts/" + account.getIdentifier())
.contentType(MediaType.APPLICATION_JSON_VALUE)
.accept(MediaType.ALL_VALUE)
.content(gson.toJson(account)))
.andExpect(status().isOk())
.andDo(document("document-find-account", preprocessRequest(prettyPrint()), preprocessResponse(prettyPrint()),
responseFields(
fieldWithPath("type").description("Type of Account " +
" + \n" +
" + \n" +
" *enum* _AccountType_ { + \n" +
" ASSET, + \n" +
" LIABILITY, + \n" +
" EQUITY, + \n" +
" REVENUE, + \n" +
" EXPENSE + \n" +
"}"),
fieldWithPath("identifier").description("Account identifier"),
fieldWithPath("name").description("Name of account"),
fieldWithPath("holders").type("Set<String>").description("Account Holders"),
fieldWithPath("signatureAuthorities").type("Set<String>").description("Account signatories"),
fieldWithPath("balance").type("Double").description("Account balance"),
fieldWithPath("ledger").description("Associated ledger"),
fieldWithPath("referenceAccount").description("Reference Account"),
fieldWithPath("state").description("State of account " +
" + \n" +
" + \n" +
"*enum* _State_ {\n" +
" OPEN, + \n" +
" LOCKED, + \n" +
" CLOSED + \n" +
" }"),
fieldWithPath("alternativeAccountNumber").type("String").description("Alternative account"),
fieldWithPath("createdOn").description("Date account was created"),
fieldWithPath("createdBy").description("Account creator"),
fieldWithPath("lastModifiedOn").type("String").description("Date when account was last modified"),
fieldWithPath("lastModifiedBy").type("String").description("Employee who last modified account")
)));
}
@Test
public void documentFetchAccounts ( ) throws Exception {
Set <String> holdersListOne = new HashSet <>();
String holderOne = "Holder One";
holdersListOne.add(holderOne);
Set <String> holdersListTwo = new HashSet <>();
String holderTwo = "Holder Two";
holdersListTwo.add(holderTwo);
Set <String> signatoriesOne = new HashSet <>();
String signatureOne = "Signatory One";
signatoriesOne.add(signatureOne);
Set <String> signatoriesTwo = new HashSet <>();
String signatureTwo = "Signatory Two";
signatoriesTwo.add(signatureTwo);
final Account salesAccountOne = AccountGenerator.createAccount(
"Organic Sales", "1111", AccountType.EXPENSE);
salesAccountOne.setName("Organic Maize");
salesAccountOne.setHolders(holdersListOne);
salesAccountOne.setSignatureAuthorities(signatoriesOne);
salesAccountOne.setBalance(225.0);
final Account salesAccountTwo = AccountGenerator.createAccount(
"Inorganic Sales", "1112", AccountType.EXPENSE);
salesAccountTwo.setName("Organic Beans");
salesAccountTwo.setHolders(holdersListTwo);
salesAccountTwo.setSignatureAuthorities(signatoriesTwo);
salesAccountTwo.setBalance(895.0);
List <Account> accountList = new ArrayList <>();
Stream.of(salesAccountOne, salesAccountTwo).forEach(account -> {
accountList.add(account);
});
final Ledger ledger = LedgerGenerator.createRandomLedger();
ledger.setIdentifier("11021");
this.testSubject.createLedger(ledger);
this.eventRecorder.wait(EventConstants.POST_LEDGER, ledger.getIdentifier());
final AccountPage accountPage =
this.testSubject.fetchAccounts(true, null, null, true,
0, 3, null, null);
accountPage.setAccounts(accountList);
accountPage.setTotalElements(new Long(accountList.size()));
accountPage.setTotalPages(1);
Gson gson = new Gson();
this.mockMvc.perform(get("/accounts")
.contentType(MediaType.APPLICATION_JSON_VALUE)
.accept(MediaType.ALL_VALUE)
.content(gson.toJson(accountPage)))
.andExpect(status().isOk())
.andDo(document("document-fetch-accounts", preprocessRequest(prettyPrint()), preprocessResponse(prettyPrint()),
requestFields(
fieldWithPath("accounts").type("List<Account>").description("List of Accounts"),
fieldWithPath("accounts[].type").description("AccountType").description("Type of first Account " +
" + \n" +
" + \n" +
" *enum* _AccountType_ { + \n" +
" ASSET, + \n" +
" LIABILITY, + \n" +
" EQUITY, + \n" +
" REVENUE, + \n" +
" EXPENSE + \n" +
"}"),
fieldWithPath("accounts[].identifier").type("String").description("first account identifier"),
fieldWithPath("accounts[].name").type("String").description("first account name"),
fieldWithPath("accounts[].holders").type("Set<String>").description("Set of account holders"),
fieldWithPath("accounts[].signatureAuthorities").type("Set<String>").description("Set of signatories to account"),
fieldWithPath("accounts[].balance").type("Double").description("first account's balance"),
fieldWithPath("accounts[].ledger").type("String").description("Associated ledger"),
fieldWithPath("accounts[1].type").description("AccountType").description("Type of second Account " +
" + \n" +
" + \n" +
" *enum* _AccountType_ { + \n" +
" ASSET, + \n" +
" LIABILITY, + \n" +
" EQUITY, + \n" +
" REVENUE, + \n" +
" EXPENSE + \n" +
"}"),
fieldWithPath("accounts[1].identifier").type("String").description("second account identifier"),
fieldWithPath("accounts[1].name").type("String").description("second account's name"),
fieldWithPath("accounts[1].holders").type("Set<String>").description("Set of account holders"),
fieldWithPath("accounts[1].signatureAuthorities").type("Set<String>").description("Set of signatories to account"),
fieldWithPath("accounts[1].balance").type("Double").description("second account balance"),
fieldWithPath("accounts[1].ledger").type("String").description("Associated ledger"),
fieldWithPath("totalPages").type("Integer").description("Total number of pages"),
fieldWithPath("totalElements").type("String").description("Total number of elements")
),
responseFields(
fieldWithPath("accounts").type("List<Account>").description("List of Accounts"),
fieldWithPath("totalPages").type("Integer").description("Total number of pages"),
fieldWithPath("totalElements").type("String").description("Total number of elements")
)));
}
@Test
public void documentFetchAccountsForTerm ( ) throws Exception {
Set <String> holdersListOne = new HashSet <>();
String holderOne = "Holder One";
holdersListOne.add(holderOne);
Set <String> holdersListTwo = new HashSet <>();
String holderTwo = "Holder Two";
holdersListTwo.add(holderTwo);
Set <String> signatoriesOne = new HashSet <>();
String signatureOne = "Signatory One";
signatoriesOne.add(signatureOne);
Set <String> signatoriesTwo = new HashSet <>();
String signatureTwo = "Signatory Two";
signatoriesTwo.add(signatureTwo);
final Ledger ledger = LedgerGenerator.createRandomLedger();
ledger.setIdentifier("2100");
this.testSubject.createLedger(ledger);
this.eventRecorder.wait(EventConstants.POST_LEDGER, ledger.getIdentifier());
final Account salesAccountOne = AccountGenerator.createAccount(
"Organic Sales", "2100.1", AccountType.REVENUE);
salesAccountOne.setName("Organic Maize");
salesAccountOne.setHolders(holdersListOne);
salesAccountOne.setSignatureAuthorities(signatoriesOne);
salesAccountOne.setBalance(225.0);
final Account salesAccountTwo = AccountGenerator.createAccount(
"Inorganic Sales", "100", AccountType.REVENUE);
salesAccountTwo.setName("Organic Beans");
salesAccountTwo.setHolders(holdersListTwo);
salesAccountTwo.setSignatureAuthorities(signatoriesTwo);
salesAccountTwo.setBalance(895.0);
List <Account> accountList = new ArrayList <>();
Stream.of(salesAccountOne, salesAccountTwo).forEach(account -> {
accountList.add(account);
});
List <Account> accountListForTerm = new ArrayList <>();
Stream.of(salesAccountOne, salesAccountTwo).
forEach(acc -> {
if (acc.getIdentifier().contains(ledger.getIdentifier()))
accountListForTerm.add(acc);
});
Assert.assertTrue(accountListForTerm.size() == 1);
final AccountPage accountPage =
this.testSubject.fetchAccounts(true, ledger.getIdentifier(), null, true,
0, 3, null, null);
accountPage.setAccounts(accountListForTerm);
accountPage.setTotalElements(new Long(accountListForTerm.size()));
accountPage.setTotalPages(1);
Gson gson = new Gson();
this.mockMvc.perform(get("/accounts")
.contentType(MediaType.APPLICATION_JSON_VALUE)
.accept(MediaType.ALL_VALUE)
.content(gson.toJson(accountPage)))
.andExpect(status().isOk())
.andDo(document("document-fetch-accounts-for-term", preprocessRequest(prettyPrint()), preprocessResponse(prettyPrint()),
requestFields(
fieldWithPath("accounts").type("List<Account>").description("List of Accounts"),
fieldWithPath("accounts[].type").description("AccountType").description("Type of first Account " +
" + \n" +
" + \n" +
" *enum* _AccountType_ { + \n" +
" ASSET, + \n" +
" LIABILITY, + \n" +
" EQUITY, + \n" +
" REVENUE, + \n" +
" EXPENSE + \n" +
"}"),
fieldWithPath("accounts[].identifier").type("String").description("first account identifier"),
fieldWithPath("accounts[].name").type("String").description("first account name"),
fieldWithPath("accounts[].holders").type("Set<String>").description("Set of account holders"),
fieldWithPath("accounts[].signatureAuthorities").type("Set<String>").description("Set of signatories to account"),
fieldWithPath("accounts[].balance").type("Double").description("first account's balance"),
fieldWithPath("accounts[].ledger").type("String").description("Associated ledger"),
fieldWithPath("totalPages").type("Integer").description("Total pages"),
fieldWithPath("totalElements").type("Integer").description("Total accounts in page")
),
responseFields(
fieldWithPath("accounts").type("List<Account>").description("List of Accounts"),
fieldWithPath("totalPages").type("Integer").description("Total number of pages"),
fieldWithPath("totalElements").type("String").description("Total number of elements")
)));
}
@Test
public void documentFetchActiveAccounts ( ) throws Exception {
Set <String> holdersListOne = new HashSet <>();
String holderOne = "Holder One";
holdersListOne.add(holderOne);
Set <String> holdersListTwo = new HashSet <>();
String holderTwo = "Holder Two";
holdersListTwo.add(holderTwo);
Set <String> holdersListThree = new HashSet <>();
String holderThree = "Holder Three";
holdersListThree.add(holderThree);
Set <String> holdersListFour = new HashSet <>();
String holderFour = "Holder Four";
holdersListFour.add(holderFour);
Set <String> signatoriesOne = new HashSet <>();
String signatureOne = "Signatory One";
signatoriesOne.add(signatureOne);
Set <String> signatoriesTwo = new HashSet <>();
String signatureTwo = "Signatory Two";
signatoriesTwo.add(signatureTwo);
Set <String> signatoriesThree = new HashSet <>();
String signatureThree = "Signatory Three";
signatoriesThree.add(signatureThree);
Set <String> signatoriesFour = new HashSet <>();
String signatureFour = "Signatory Four";
signatoriesFour.add(signatureFour);
final Ledger ledger = LedgerGenerator.createRandomLedger();
ledger.setIdentifier("3100");
this.testSubject.createLedger(ledger);
this.eventRecorder.wait(EventConstants.POST_LEDGER, ledger.getIdentifier());
final Account salesAccountOne = AccountGenerator.createAccount(
"Organic Sales", "3100.10", AccountType.REVENUE);
salesAccountOne.setState(Account.State.OPEN.name());
salesAccountOne.setName("Organic Maize");
salesAccountOne.setHolders(holdersListOne);
salesAccountOne.setSignatureAuthorities(signatoriesOne);
salesAccountOne.setBalance(225.0);
salesAccountOne.setState(Account.State.CLOSED.name());
final Account salesAccountTwo = AccountGenerator.createAccount(
"Inorganic Sales", "3100.20", AccountType.REVENUE);
salesAccountTwo.setState(Account.State.OPEN.name());
salesAccountTwo.setName("Organic Pens");
salesAccountTwo.setHolders(holdersListTwo);
salesAccountTwo.setSignatureAuthorities(signatoriesTwo);
salesAccountTwo.setBalance(895.0);
final Account salesAccountThree = AccountGenerator.createAccount(
"Organic Sales", "3100.30", AccountType.REVENUE);
salesAccountThree.setState(Account.State.OPEN.name());
salesAccountThree.setName("Organic Peas");
salesAccountThree.setHolders(holdersListThree);
salesAccountThree.setSignatureAuthorities(signatoriesThree);
salesAccountThree.setBalance(953.0);
salesAccountOne.setState(Account.State.CLOSED.name());
final Account salesAccountFour = AccountGenerator.createAccount(
"Inorganic Sales", "3100.40", AccountType.REVENUE);
salesAccountFour.setState(Account.State.OPEN.name());
salesAccountFour.setName("Organic Pencils");
salesAccountFour.setHolders(holdersListFour);
salesAccountFour.setSignatureAuthorities(signatoriesFour);
salesAccountFour.setBalance(345.0);
List <Account> accountList = new ArrayList <>();
Stream.of(salesAccountOne, salesAccountTwo, salesAccountThree, salesAccountFour).forEach(account -> {
accountList.add(account);
});
List <Account> listOfActiveAccounts = new ArrayList <>();
Stream.of(salesAccountOne, salesAccountTwo, salesAccountThree, salesAccountFour).
forEach(acc -> {
if (acc.getState() == Account.State.OPEN.name())
listOfActiveAccounts.add(acc);
});
final AccountPage accountPage =
this.testSubject.fetchAccounts(true, ledger.getIdentifier(), null, true,
0, 3, null, null);
accountPage.setAccounts(listOfActiveAccounts);
accountPage.setTotalElements(new Long(listOfActiveAccounts.size()));
accountPage.setTotalPages(1);
Gson gson = new Gson();
this.mockMvc.perform(get("/accounts")
.contentType(MediaType.APPLICATION_JSON_VALUE)
.accept(MediaType.ALL_VALUE)
.content(gson.toJson(accountPage)))
.andExpect(status().isOk())
.andDo(document("document-fetch-active-accounts", preprocessRequest(prettyPrint()), preprocessResponse(prettyPrint()),
requestFields(
fieldWithPath("accounts").type("List<Account>").description("List of Accounts"),
fieldWithPath("accounts[].type").description("AccountType").description("Type of first Account " +
" + \n" +
" + \n" +
" *enum* _AccountType_ { + \n" +
" ASSET, + \n" +
" LIABILITY, + \n" +
" EQUITY, + \n" +
" REVENUE, + \n" +
" EXPENSE + \n" +
"}"),
fieldWithPath("accounts[].identifier").type("String").description("first account identifier"),
fieldWithPath("accounts[].name").type("String").description("first account name"),
fieldWithPath("accounts[].holders").type("Set<String>").description("Set of account holders"),
fieldWithPath("accounts[].signatureAuthorities").type("Set<String>").description("Set of signatories to account"),
fieldWithPath("accounts[].balance").type("Double").description("first account's balance"),
fieldWithPath("accounts[].ledger").type("String").description("Associated ledger"),
fieldWithPath("totalPages").type("Integer").description("Total pages"),
fieldWithPath("totalElements").type("Integer").description("Total accounts in page")
),
responseFields(
fieldWithPath("accounts").type("List<Account>").description("List of Accounts"),
fieldWithPath("totalPages").type("Integer").description("Total number of pages"),
fieldWithPath("totalElements").type("String").description("Total number of elements")
)));
}
@Test
public void documentFindAccountWithAlternativeAccountNumber ( ) throws Exception {
Set <String> holdersList = new HashSet <>();
String holderOne = "Only Holder";
holdersList.add(holderOne);
Set <String> signatories = new HashSet <>();
String signatureOne = "Only Signatory";
signatories.add(signatureOne);
final Ledger ledger = LedgerGenerator.createRandomLedger();
ledger.setIdentifier("7100");
ledger.setType(AccountType.REVENUE.name());
this.testSubject.createLedger(ledger);
this.eventRecorder.wait(EventConstants.POST_LEDGER, ledger.getIdentifier());
final String altNumber = "7-1-0-0-.-1-0";
final Account salesAccount = AccountGenerator.createAccount(
"7100", "7100.10", AccountType.REVENUE);
salesAccount.setState(Account.State.OPEN.name());
salesAccount.setName("Organic Maize");
salesAccount.setHolders(holdersList);
salesAccount.setSignatureAuthorities(signatories);
salesAccount.setBalance(3435.0);
salesAccount.setState(Account.State.CLOSED.name());
salesAccount.setAlternativeAccountNumber(altNumber);
this.testSubject.createAccount(salesAccount);
this.eventRecorder.wait(EventConstants.POST_ACCOUNT, salesAccount.getIdentifier());
final AccountPage accountPage =
this.testSubject.fetchAccounts(true, altNumber, null, true,
0, 3, null, null);
Gson gson = new Gson();
this.mockMvc.perform(get("/accounts/" + salesAccount.getIdentifier())
.contentType(MediaType.APPLICATION_JSON_VALUE)
.accept(MediaType.ALL_VALUE)
/*.content(gson.toJson())*/)
.andExpect(status().isOk())
.andDo(document("document-find-account-with-alternative-account-number", preprocessRequest(prettyPrint()), preprocessResponse(prettyPrint()),
responseFields(
fieldWithPath("type").description("AccountType").description("Type of Account " +
" + \n" +
" + \n" +
" *enum* _AccountType_ { + \n" +
" ASSET, + \n" +
" LIABILITY, + \n" +
" EQUITY, + \n" +
" REVENUE, + \n" +
" EXPENSE + \n" +
"}"),
fieldWithPath("identifier").type("String").description("Account identifier"),
fieldWithPath("name").type("String").description("Account name"),
fieldWithPath("holders").type("Set<String>").description("Set of account holders"),
fieldWithPath("signatureAuthorities").type("Set<String>").description("Set of signatories to account"),
fieldWithPath("balance").type("Double").description("account's balance"),
fieldWithPath("referenceAccount").type("String").description("Reference Account"),
fieldWithPath("ledger").type("String").description("Associated ledger"),
fieldWithPath("state").type("State").description("State of Account " +
" + \n" +
" + \n" +
" *enum* _State_ { + \n" +
" OPEN, + \n" +
" LOCKED, + \n" +
" CLOSED, + \n" +
"}"),
fieldWithPath("alternativeAccountNumber").type("Integer").description("Total accounts in page"),
fieldWithPath("createdOn").type("List<Account>").description("List of Accounts"),
fieldWithPath("createdBy").type("Integer").description("Total number of pages"),
fieldWithPath("lastModifiedOn").type("String").description("Total number of elements"),
fieldWithPath("lastModifiedBy").type("String").description("Total number of elements")
)));
}
@Test
public void documentModifyAccount ( ) throws Exception {
final Ledger ledger = LedgerGenerator.createRandomLedger();
ledger.setIdentifier("2000");
this.testSubject.createLedger(ledger);
this.eventRecorder.wait(EventConstants.POST_LEDGER, ledger.getIdentifier());
final Account account = AccountGenerator.createRandomAccount(ledger.getIdentifier());
Set <String> holdersList = new HashSet <>();
String holderOne = "Holder First";
String holderTwo = "Holder Second";
holdersList.add(holderOne);
holdersList.add(holderTwo);
Set <String> signatories = new HashSet <>();
String signatureOne = "First Signatory";
String signatureTwo = "Second Signatory";
signatories.add(signatureOne);
signatories.add(signatureTwo);
Double bal = 342.0;
account.setType(AccountType.ASSET.name());
account.setIdentifier("2001");
account.setName("Payables");
account.setHolders(holdersList);
account.setSignatureAuthorities(signatories);
account.setBalance(bal);
account.setLedger(ledger.getIdentifier());
this.testSubject.createAccount(account);
this.eventRecorder.wait(EventConstants.POST_ACCOUNT, account.getIdentifier());
Gson gson = new Gson();
this.mockMvc.perform(put("/accounts/" + account.getIdentifier())
.contentType(MediaType.APPLICATION_JSON_VALUE)
.accept(MediaType.APPLICATION_JSON_VALUE)
.content(gson.toJson(account)))
.andExpect(status().isAccepted())
.andDo(document("document-modify-account", preprocessRequest(prettyPrint()), preprocessResponse(prettyPrint()),
requestFields(
fieldWithPath("type").description("Type of Account " +
" + \n" +
" + \n" +
" *enum* _AccountType_ { + \n" +
" ASSET, + \n" +
" LIABILITY, + \n" +
" EQUITY, + \n" +
" REVENUE, + \n" +
" EXPENSE + \n" +
"}"),
fieldWithPath("identifier").description("Account identifier"),
fieldWithPath("name").description("Name of account"),
fieldWithPath("holders").type("Set<String>").description("Account Holders"),
fieldWithPath("signatureAuthorities").type("Set<String>").description("Account signatories"),
fieldWithPath("balance").type("Double").description("Account balance"),
fieldWithPath("ledger").description("Associated ledger")
)));
}
@Test
public void documentCloseAccount ( ) throws Exception {
final Ledger randomLedger = LedgerGenerator.createRandomLedger();
randomLedger.setIdentifier("3000");
this.testSubject.createLedger(randomLedger);
this.eventRecorder.wait(EventConstants.POST_LEDGER, randomLedger.getIdentifier());
final Account randomAccount = AccountGenerator.createRandomAccount(randomLedger.getIdentifier());
randomAccount.setIdentifier("3001");
randomAccount.setState(Account.State.OPEN.name());
this.testSubject.createAccount(randomAccount);
this.eventRecorder.wait(EventConstants.POST_ACCOUNT, randomAccount.getIdentifier());
final AccountCommand closeCommand = new AccountCommand();
closeCommand.setAction(AccountCommand.Action.CLOSE.name());
closeCommand.setComment("Close Account");
this.testSubject.accountCommand(randomAccount.getIdentifier(), closeCommand);
Gson gson = new Gson();
this.mockMvc.perform(post("/accounts/" + randomAccount.getIdentifier() + "/commands")
.contentType(MediaType.APPLICATION_JSON_VALUE)
.accept(MediaType.APPLICATION_JSON_VALUE)
.content(gson.toJson(closeCommand)))
.andExpect(status().isAccepted())
.andDo(document("document-close-account", preprocessRequest(prettyPrint()), preprocessResponse(prettyPrint()),
requestFields(
fieldWithPath("action").description("Action CLOSE " +
" +\n" +
" *enum* _Action_ { +\n" +
" LOCK, +\n" +
" UNLOCK, +\n" +
" CLOSE, +\n" +
" REOPEN +\n" +
" }"),
fieldWithPath("comment").description("Close comment"))));
}
@Test
public void documentLockAccount ( ) throws Exception {
final Ledger ledger = LedgerGenerator.createRandomLedger();
ledger.setIdentifier("4000");
this.testSubject.createLedger(ledger);
this.eventRecorder.wait(EventConstants.POST_LEDGER, ledger.getIdentifier());
final Account rAccount = AccountGenerator.createRandomAccount(ledger.getIdentifier());
rAccount.setIdentifier("4001");
rAccount.setState(Account.State.OPEN.name());
this.testSubject.createAccount(rAccount);
this.eventRecorder.wait(EventConstants.POST_ACCOUNT, rAccount.getIdentifier());
final AccountCommand lockCommand = new AccountCommand();
lockCommand.setAction(AccountCommand.Action.LOCK.name());
lockCommand.setComment("Lock Account");
this.testSubject.accountCommand(rAccount.getIdentifier(), lockCommand);
Gson gson = new Gson();
this.mockMvc.perform(post("/accounts/" + rAccount.getIdentifier() + "/commands")
.contentType(MediaType.APPLICATION_JSON_VALUE)
.accept(MediaType.APPLICATION_JSON_VALUE)
.content(gson.toJson(lockCommand)))
.andExpect(status().isAccepted())
.andDo(document("document-lock-account", preprocessRequest(prettyPrint()), preprocessResponse(prettyPrint()),
requestFields(
fieldWithPath("action").description("Action LOCK " +
" +\n" +
" *enum* _Action_ { +\n" +
" LOCK, +\n" +
" UNLOCK, +\n" +
" CLOSE, +\n" +
" REOPEN +\n" +
" }"),
fieldWithPath("comment").description("Lock comment"))));
}
@Test
public void documentUnlockAccount ( ) throws Exception {
final Ledger ledger = LedgerGenerator.createRandomLedger();
ledger.setIdentifier("5100");
this.testSubject.createLedger(ledger);
this.eventRecorder.wait(EventConstants.POST_LEDGER, ledger.getIdentifier());
final Account ulAccount = AccountGenerator.createRandomAccount(ledger.getIdentifier());
ulAccount.setIdentifier("5001");
ulAccount.setState(Account.State.LOCKED.name());
this.testSubject.createAccount(ulAccount);
this.eventRecorder.wait(EventConstants.POST_ACCOUNT, ulAccount.getIdentifier());
final AccountCommand unlockCommand = new AccountCommand();
unlockCommand.setAction(AccountCommand.Action.UNLOCK.name());
unlockCommand.setComment("Unlock Account");
this.testSubject.accountCommand(ulAccount.getIdentifier(), unlockCommand);
Gson gson = new Gson();
this.mockMvc.perform(post("/accounts/" + ulAccount.getIdentifier() + "/commands")
.contentType(MediaType.APPLICATION_JSON_VALUE)
.accept(MediaType.APPLICATION_JSON_VALUE)
.content(gson.toJson(unlockCommand)))
.andExpect(status().isAccepted())
.andDo(document("document-unlock-account", preprocessRequest(prettyPrint()), preprocessResponse(prettyPrint()),
requestFields(
fieldWithPath("action").description("Action UNLOCK " +
" +\n" +
" *enum* _Action_ { +\n" +
" LOCK, +\n" +
" UNLOCK, +\n" +
" CLOSE, +\n" +
" REOPEN +\n" +
" }"),
fieldWithPath("comment").description("Unlock comment"))));
}
@Test
public void documentReopenAccount ( ) throws Exception {
final Ledger ledger = LedgerGenerator.createRandomLedger();
ledger.setIdentifier("6000");
this.testSubject.createLedger(ledger);
this.eventRecorder.wait(EventConstants.POST_LEDGER, ledger.getIdentifier());
final Account roAccount = AccountGenerator.createRandomAccount(ledger.getIdentifier());
roAccount.setIdentifier("6001");
roAccount.setState(Account.State.CLOSED.name());
this.testSubject.createAccount(roAccount);
this.eventRecorder.wait(EventConstants.POST_ACCOUNT, roAccount.getIdentifier());
final AccountCommand reopenCommand = new AccountCommand();
reopenCommand.setAction(AccountCommand.Action.REOPEN.name());
reopenCommand.setComment("Reopen Account");
this.testSubject.accountCommand(roAccount.getIdentifier(), reopenCommand);
Gson gson = new Gson();
this.mockMvc.perform(post("/accounts/" + roAccount.getIdentifier() + "/commands")
.contentType(MediaType.APPLICATION_JSON_VALUE)
.accept(MediaType.APPLICATION_JSON_VALUE)
.content(gson.toJson(reopenCommand)))
.andExpect(status().isAccepted())
.andDo(document("document-reopen-account", preprocessRequest(prettyPrint()), preprocessResponse(prettyPrint()),
requestFields(
fieldWithPath("action").description("Action REOPEN " +
" +\n" +
" *enum* _Action_ { +\n" +
" LOCK, +\n" +
" UNLOCK, +\n" +
" CLOSE, +\n" +
" REOPEN +\n" +
" }"),
fieldWithPath("comment").description("Reopen comment"))));
}
@Test
public void documentDeleteAccount ( ) throws Exception {
final Ledger randomLedger = LedgerGenerator.createRandomLedger();
randomLedger.setIdentifier("5000");
this.testSubject.createLedger(randomLedger);
this.eventRecorder.wait(EventConstants.POST_LEDGER, randomLedger.getIdentifier());
final Account randomAccount = AccountGenerator.createRandomAccount(randomLedger.getIdentifier());
randomAccount.setIdentifier("5002");
this.testSubject.createAccount(randomAccount);
this.eventRecorder.wait(EventConstants.POST_ACCOUNT, randomAccount.getIdentifier());
final AccountCommand closeCommand = new AccountCommand();
closeCommand.setAction(AccountCommand.Action.CLOSE.name());
closeCommand.setComment("Close Account!");
this.testSubject.accountCommand(randomAccount.getIdentifier(), closeCommand);
this.eventRecorder.wait(EventConstants.CLOSE_ACCOUNT, randomAccount.getIdentifier());
this.mockMvc.perform(delete("/accounts/" + randomAccount.getIdentifier())
.accept(MediaType.ALL_VALUE)
.contentType(MediaType.APPLICATION_JSON_VALUE))
.andExpect(status().isAccepted())
.andDo(document("document-delete-account", preprocessRequest(prettyPrint()), preprocessResponse(prettyPrint())));
}
@Test
public void documentFetchActions ( ) throws Exception {
final Ledger randomLedger = LedgerGenerator.createRandomLedger();
randomLedger.setIdentifier("5200");
this.testSubject.createLedger(randomLedger);
this.eventRecorder.wait(EventConstants.POST_LEDGER, randomLedger.getIdentifier());
final Account randomAccount = AccountGenerator.createRandomAccount(randomLedger.getIdentifier());
randomAccount.setIdentifier("5002");
randomAccount.setState(Account.State.OPEN.name());
this.testSubject.createAccount(randomAccount);
this.eventRecorder.wait(EventConstants.POST_ACCOUNT, randomAccount.getIdentifier());
final List <AccountCommand> accountCommands = super.testSubject.fetchActions(randomAccount.getIdentifier());
accountCommands.get(0).setComment("Lock Account");
accountCommands.get(0).setCreatedBy("setna");
accountCommands.get(0).setCreatedOn(LocalDate.now().toString());
accountCommands.get(1).setComment("Close Account");
accountCommands.get(1).setCreatedBy("setna");
accountCommands.get(1).setCreatedOn(LocalDate.now().toString());
Assert.assertEquals(2, accountCommands.size());
this.mockMvc.perform(get("/accounts/" + randomAccount.getIdentifier() + "/actions")
.contentType(MediaType.APPLICATION_JSON_VALUE)
.accept(MediaType.ALL_VALUE))
.andExpect(status().isOk())
.andDo(document("document-fetch-actions", preprocessRequest(prettyPrint()), preprocessResponse(prettyPrint()),
responseFields(
fieldWithPath("[].action").description("Action LOCK " +
" +\n" +
" *enum* _Action_ { +\n" +
" LOCK, +\n" +
" UNLOCK, +\n" +
" CLOSE, +\n" +
" REOPEN +\n" +
" }"),
fieldWithPath("[].comment").description("Reopen comment"),
fieldWithPath("[].createdOn").description("Date when action was carried out"),
fieldWithPath("[].createdBy").description("Employee who acted on account"),
fieldWithPath("[1].action").description("Action CLOSE " +
" +\n" +
" *enum* _Action_ { +\n" +
" LOCK, +\n" +
" UNLOCK, +\n" +
" CLOSE, +\n" +
" REOPEN +\n" +
" }"),
fieldWithPath("[1].comment").description("Reopen comment"),
fieldWithPath("[1].createdOn").description("Date when action was carried out"),
fieldWithPath("[1].createdBy").description("Employee who acted on account"))));
}
@Test
public void documentFetchAccountEntries ( ) throws Exception {
final Ledger ledger = LedgerGenerator.createRandomLedger();
ledger.setIdentifier("1500");
this.testSubject.createLedger(ledger);
this.eventRecorder.wait(EventConstants.POST_LEDGER, ledger.getIdentifier());
final Account accountToDebit = AccountGenerator.createRandomAccount(ledger.getIdentifier());
accountToDebit.setIdentifier("1501");
this.testSubject.createAccount(accountToDebit);
this.eventRecorder.wait(EventConstants.POST_ACCOUNT, accountToDebit.getIdentifier());
final Account accountToCredit = AccountGenerator.createRandomAccount(ledger.getIdentifier());
accountToCredit.setIdentifier("1601");
this.testSubject.createAccount(accountToCredit);
this.eventRecorder.wait(EventConstants.POST_ACCOUNT, accountToCredit.getIdentifier());
final int journalEntryCount = 3;
final List <JournalEntry> journalEntries = Stream.generate(( ) -> JournalEntryGenerator.createRandomJournalEntry(accountToDebit, "5.0", accountToCredit, "5.0"))
.limit(journalEntryCount)
.collect(Collectors.toList());
journalEntries.stream()
.forEach(entry -> {
entry.setMessage("Message " + journalEntries.indexOf(entry));
});
journalEntries.stream()
.map(jEntry -> {
this.testSubject.createJournalEntry(jEntry);
return jEntry.getTransactionIdentifier();
})
.forEach(transactionId -> {
try {
this.eventRecorder.wait(EventConstants.POST_JOURNAL_ENTRY, transactionId);
this.eventRecorder.wait(EventConstants.RELEASE_JOURNAL_ENTRY, transactionId);
} catch (final InterruptedException e) {
throw new RuntimeException(e);
}
});
Thread.sleep(20L); // Short pause to make sure it really is last.
final LocalDate today = LocalDate.now(Clock.systemUTC());
final String todayDateRange = new DateRange(today, today).toString();
final AccountEntryPage accountEntriesPage =
this.testSubject.fetchAccountEntries(accountToCredit.getIdentifier(), todayDateRange, "Entries Fetched", 0,
1, "ASC", Sort.Direction.ASC.name());
Gson gson = new Gson();
this.mockMvc.perform(get("/accounts/" + accountToCredit.getIdentifier() + "/entries")
.contentType(MediaType.APPLICATION_JSON_VALUE)
/*.content(gson.toJson(accountEntriesPage))*/
.accept(MediaType.ALL_VALUE))
.andExpect(status().isOk())
.andDo(document("document-fetch-account-entries", preprocessRequest(prettyPrint()), preprocessResponse(prettyPrint()),
responseFields(
fieldWithPath("accountEntries").type("List<AccountEntry>").description("List of account entries"),
fieldWithPath("accountEntries[].type").description("Type of entry DEBIT or CREDIT "),
fieldWithPath("accountEntries[].transactionDate").description("Date of transaction"),
fieldWithPath("accountEntries[].message").description("Transaction message"),
fieldWithPath("accountEntries[].amount").description("Transaction amount"),
fieldWithPath("accountEntries[].balance").description("Transaction balance"),
fieldWithPath("accountEntries[1].type").description("Type of entry DEBIT or CREDIT "),
fieldWithPath("accountEntries[1].transactionDate").description("Date of transaction"),
fieldWithPath("accountEntries[1].message").description("Transaction message"),
fieldWithPath("accountEntries[1].amount").description("Transaction amount"),
fieldWithPath("accountEntries[1].balance").description("Transaction balance"),
fieldWithPath("accountEntries[2].type").description("Type of entry DEBIT or CREDIT "),
fieldWithPath("accountEntries[2].transactionDate").description("Date of transaction"),
fieldWithPath("accountEntries[2].message").description("Transaction message"),
fieldWithPath("accountEntries[2].amount").description("Transaction amount"),
fieldWithPath("accountEntries[2].balance").description("Transaction balance"),
fieldWithPath("totalPages").type("List<AccountEntry>").description("Reopen comment"),
fieldWithPath("totalElements").type("List<AccountEntry>").description("Reopen comment"))));
}
} | 4,740 |
0 | Create_ds/fineract-cn-accounting/component-test/src/main/java/org/apache/fineract/cn | Create_ds/fineract-cn-accounting/component-test/src/main/java/org/apache/fineract/cn/accounting/StressTestJournalEntry.java | /*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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.apache.fineract.cn.accounting;
import org.apache.fineract.cn.accounting.api.v1.EventConstants;
import org.apache.fineract.cn.accounting.api.v1.domain.Account;
import org.apache.fineract.cn.accounting.api.v1.domain.JournalEntry;
import org.apache.fineract.cn.accounting.api.v1.domain.Ledger;
import org.apache.fineract.cn.accounting.util.AccountGenerator;
import org.apache.fineract.cn.accounting.util.JournalEntryGenerator;
import org.apache.fineract.cn.accounting.util.LedgerGenerator;
import org.apache.commons.lang.math.RandomUtils;
import org.junit.Test;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import java.util.concurrent.atomic.AtomicLong;
public class StressTestJournalEntry extends AbstractAccountingTest {
@Test
public void runStresser() throws Exception {
final int numberOfLedgers = 32;
final int numberOfAccounts = 512;
final int numberOfJournalEntries = 1024;
final Account[] preparedAccountsAsArray = this.prepareData(numberOfLedgers, numberOfAccounts);
this.writeJournalEntries(4, numberOfJournalEntries, preparedAccountsAsArray);
this.writeJournalEntries(8, numberOfJournalEntries, preparedAccountsAsArray);
this.writeJournalEntries(16, numberOfJournalEntries, preparedAccountsAsArray);
this.writeJournalEntries(24, numberOfJournalEntries, preparedAccountsAsArray);
this.writeJournalEntries(32, numberOfJournalEntries, preparedAccountsAsArray);
}
private void writeJournalEntries(final int numberOfThreads, final int numberOfJournalEntries, final Account[] preparedAccountsAsArray) {
final List<Future<?>> futures = new ArrayList<>(numberOfThreads);
final ExecutorService executorService = Executors.newFixedThreadPool(numberOfThreads);
final AtomicLong totalExecutionTime = new AtomicLong(0L);
for (int t = 0; t < numberOfThreads; t++) {
final Future<?> future = executorService.submit(
() -> {
long executionTime = 0L;
int randomBound = preparedAccountsAsArray.length;
for (int i = 0; i < numberOfJournalEntries; i++) {
final Account debtorAccount = preparedAccountsAsArray[RandomUtils.nextInt(randomBound)];
final Account creditorAccount = preparedAccountsAsArray[RandomUtils.nextInt(randomBound)];
final JournalEntry randomJournalEntry =
JournalEntryGenerator.createRandomJournalEntry(debtorAccount, "50.00", creditorAccount, "50.00");
final long start = System.currentTimeMillis();
this.testSubject.createJournalEntry(randomJournalEntry);
executionTime += (System.currentTimeMillis() - start);
}
totalExecutionTime.addAndGet(executionTime);
}
);
futures.add(future);
}
futures.forEach(future -> {
try {
future.get();
} catch (Exception e) {
e.printStackTrace();
}
});
final long numberOfProcessedJournalEntries = numberOfJournalEntries * numberOfThreads;
final long processingTime = totalExecutionTime.get();
this.logger.error("Added {} journal entries in {}s.", numberOfProcessedJournalEntries, (processingTime / 1000L));
this.logger.error("Average processing time for one journal entry: {}ms", processingTime / numberOfProcessedJournalEntries);
}
private Account[] prepareData(int numberOfLedgers, int numberOfAccounts) throws Exception {
final ArrayList<Account> createdAccounts = new ArrayList<>(numberOfLedgers * numberOfAccounts);
final AtomicLong preparationTime = new AtomicLong(0L);
for (int i = 0; i < numberOfLedgers; i++) {
final long start = System.currentTimeMillis();
final Ledger randomLedger = LedgerGenerator.createRandomLedger();
this.testSubject.createLedger(randomLedger);
this.eventRecorder.wait(EventConstants.POST_LEDGER, randomLedger.getIdentifier());
for (int j = 0; j < numberOfAccounts; j++) {
final Account randomAccount = AccountGenerator.createRandomAccount(randomLedger.getIdentifier());
this.testSubject.createAccount(randomAccount);
this.eventRecorder.wait(EventConstants.POST_ACCOUNT, randomAccount.getIdentifier());
createdAccounts.add(randomAccount);
}
final long processingTime = (System.currentTimeMillis() - start);
preparationTime.addAndGet(processingTime);
}
this.logger.error("Created {} ledgers and {} accounts in {}s.", numberOfLedgers, (numberOfAccounts * numberOfLedgers), (preparationTime.get() / 1000L));
this.logger.error("Average processing time for one account: {}ms.", preparationTime.get() / (numberOfAccounts * numberOfLedgers));
final Account[] toReturn = new Account[createdAccounts.size()];
createdAccounts.toArray(toReturn);
return toReturn;
}
}
| 4,741 |
0 | Create_ds/fineract-cn-accounting/component-test/src/main/java/org/apache/fineract/cn | Create_ds/fineract-cn-accounting/component-test/src/main/java/org/apache/fineract/cn/accounting/TestChartOfAccounts.java | /*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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.apache.fineract.cn.accounting;
import org.apache.fineract.cn.accounting.api.v1.EventConstants;
import org.apache.fineract.cn.accounting.api.v1.domain.Account;
import org.apache.fineract.cn.accounting.api.v1.domain.AccountType;
import org.apache.fineract.cn.accounting.api.v1.domain.ChartOfAccountEntry;
import org.apache.fineract.cn.accounting.api.v1.domain.Ledger;
import org.apache.fineract.cn.accounting.util.AccountGenerator;
import org.apache.fineract.cn.accounting.util.LedgerGenerator;
import org.junit.Assert;
import org.junit.Test;
import java.util.List;
public class TestChartOfAccounts extends AbstractAccountingTest {
@Test
public void shouldShowChartOfAccounts() throws Exception {
final Ledger parentRevenueLedger = LedgerGenerator.createLedger("10000", AccountType.REVENUE);
this.testSubject.createLedger(parentRevenueLedger);
this.eventRecorder.wait(EventConstants.POST_LEDGER, parentRevenueLedger.getIdentifier());
final Ledger interestRevenueLedger = LedgerGenerator.createLedger("11000", AccountType.REVENUE);
this.testSubject.addSubLedger(parentRevenueLedger.getIdentifier(), interestRevenueLedger);
this.eventRecorder.wait(EventConstants.POST_LEDGER, interestRevenueLedger.getIdentifier());
final Account consumerInterestRevenueAccount =
AccountGenerator.createAccount(interestRevenueLedger.getIdentifier(), "11100", AccountType.REVENUE);
this.testSubject.createAccount(consumerInterestRevenueAccount);
this.eventRecorder.wait(EventConstants.POST_ACCOUNT, consumerInterestRevenueAccount.getIdentifier());
final Ledger feeRevenueLedger = LedgerGenerator.createLedger("12000", AccountType.REVENUE);
this.testSubject.addSubLedger(parentRevenueLedger.getIdentifier(), feeRevenueLedger);
this.eventRecorder.wait(EventConstants.POST_LEDGER, feeRevenueLedger.getIdentifier());
final Ledger specialFeeRevenueLedger = LedgerGenerator.createLedger("12100", AccountType.REVENUE);
this.testSubject.addSubLedger(feeRevenueLedger.getIdentifier(), specialFeeRevenueLedger);
this.eventRecorder.wait(EventConstants.POST_LEDGER, specialFeeRevenueLedger.getIdentifier());
final Ledger parentAssetLedger = LedgerGenerator.createLedger("70000", AccountType.ASSET);
this.testSubject.createLedger(parentAssetLedger);
this.eventRecorder.wait(EventConstants.POST_LEDGER, parentAssetLedger.getIdentifier());
final Ledger consumerLoanAssetLedger = LedgerGenerator.createLedger("73000", AccountType.ASSET);
consumerLoanAssetLedger.setShowAccountsInChart(Boolean.FALSE);
this.testSubject.addSubLedger(parentAssetLedger.getIdentifier(), consumerLoanAssetLedger);
this.eventRecorder.wait(EventConstants.POST_LEDGER, consumerLoanAssetLedger.getIdentifier());
for (int i = 1; i < 100; i++) {
final String identifier = Integer.valueOf(73000 + i).toString();
final Account consumerLoanAccount =
AccountGenerator.createAccount(consumerLoanAssetLedger.getIdentifier(), identifier, AccountType.ASSET);
this.testSubject.createAccount(consumerLoanAccount);
this.eventRecorder.wait(EventConstants.POST_ACCOUNT, identifier);
}
final List<ChartOfAccountEntry> chartOfAccounts = this.testSubject.getChartOfAccounts();
Assert.assertNotNull(chartOfAccounts);
Assert.assertEquals(7, chartOfAccounts.size());
Assert.assertEquals(Integer.valueOf(0), chartOfAccounts.get(0).getLevel());
Assert.assertEquals(Integer.valueOf(1), chartOfAccounts.get(1).getLevel());
Assert.assertEquals(Integer.valueOf(2), chartOfAccounts.get(2).getLevel());
Assert.assertEquals(Integer.valueOf(1), chartOfAccounts.get(3).getLevel());
Assert.assertEquals(Integer.valueOf(2), chartOfAccounts.get(4).getLevel());
Assert.assertEquals(Integer.valueOf(0), chartOfAccounts.get(5).getLevel());
Assert.assertEquals(Integer.valueOf(1), chartOfAccounts.get(6).getLevel());
}
}
| 4,742 |
0 | Create_ds/fineract-cn-accounting/component-test/src/main/java/org/apache/fineract/cn | Create_ds/fineract-cn-accounting/component-test/src/main/java/org/apache/fineract/cn/accounting/TransactionTypeApiDocumentation.java | /*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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.apache.fineract.cn.accounting;
import com.google.gson.Gson;
import org.apache.fineract.cn.accounting.api.v1.EventConstants;
import org.apache.fineract.cn.accounting.api.v1.domain.*;
import org.apache.fineract.cn.accounting.util.AccountGenerator;
import org.apache.fineract.cn.accounting.util.JournalEntryGenerator;
import org.apache.fineract.cn.accounting.util.LedgerGenerator;
import org.apache.fineract.cn.accounting.util.TransactionTypeGenerator;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Sort;
import org.springframework.http.MediaType;
import org.springframework.restdocs.JUnitRestDocumentation;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
import org.springframework.web.context.WebApplicationContext;
import static org.springframework.restdocs.mockmvc.MockMvcRestDocumentation.document;
import static org.springframework.restdocs.mockmvc.MockMvcRestDocumentation.documentationConfiguration;
import static org.springframework.restdocs.mockmvc.RestDocumentationRequestBuilders.post;
import static org.springframework.restdocs.mockmvc.RestDocumentationRequestBuilders.get;
import static org.springframework.restdocs.mockmvc.RestDocumentationRequestBuilders.put;
import static org.springframework.restdocs.operation.preprocess.Preprocessors.preprocessRequest;
import static org.springframework.restdocs.operation.preprocess.Preprocessors.preprocessResponse;
import static org.springframework.restdocs.operation.preprocess.Preprocessors.prettyPrint;
import static org.springframework.restdocs.payload.PayloadDocumentation.fieldWithPath;
import static org.springframework.restdocs.payload.PayloadDocumentation.requestFields;
import static org.springframework.restdocs.payload.PayloadDocumentation.responseFields;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
public class TransactionTypeApiDocumentation extends AbstractAccountingTest {
@Rule
public final JUnitRestDocumentation restDocumentation = new JUnitRestDocumentation("build/doc/generated-snippets/test-transaction-type");
@Autowired
private WebApplicationContext context;
private MockMvc mockMvc;
@Before
public void setUp ( ) {
this.mockMvc = MockMvcBuilders.webAppContextSetup(this.context)
.apply(documentationConfiguration(this.restDocumentation))
.alwaysDo(document("{method-name}", preprocessRequest(prettyPrint()), preprocessResponse(prettyPrint())))
.build();
}
@Test
public void documentCreateTransactionType ( ) throws Exception {
final TransactionType transactionType = TransactionTypeGenerator.createRandomTransactionType();
transactionType.setCode("ABCD");
transactionType.setName("Account Starter");
transactionType.setDescription("Account Starter");
Gson gson = new Gson();
this.mockMvc.perform(post("/transactiontypes")
.contentType(MediaType.APPLICATION_JSON_VALUE)
.accept(MediaType.APPLICATION_JSON_VALUE)
.content(gson.toJson(transactionType)))
.andExpect(status().isAccepted())
.andDo(document("document-create-transaction-type", preprocessRequest(prettyPrint()), preprocessResponse(prettyPrint()),
requestFields(
fieldWithPath("code").description("Transaction Type's code"),
fieldWithPath("name").description("Name of transaction type"),
fieldWithPath("description").description("Description of transaction type")
)));
}
@Test
public void documentFindTransactionType ( ) throws Exception {
final TransactionType transactionType = TransactionTypeGenerator.createRandomTransactionType();
transactionType.setCode("AXYZ");
transactionType.setName("Account Lock");
transactionType.setDescription("Lock Account");
this.testSubject.createTransactionType(transactionType);
this.eventRecorder.wait(EventConstants.POST_TX_TYPE, transactionType.getCode());
Gson gson = new Gson();
this.mockMvc.perform(get("/transactiontypes/" + transactionType.getCode())
.contentType(MediaType.APPLICATION_JSON_VALUE)
.accept(MediaType.APPLICATION_JSON_VALUE)
.content(gson.toJson(transactionType)))
.andExpect(status().isOk())
.andDo(document("document-find-transaction-type", preprocessRequest(prettyPrint()), preprocessResponse(prettyPrint()),
responseFields(
fieldWithPath("code").description("Transaction Type's code"),
fieldWithPath("name").description("Name of transaction type"),
fieldWithPath("description").description("Description of transaction type")
)));
}
@Test
public void documentFetchTransactionType ( ) throws Exception {
final TransactionTypePage transactionTypePage =
super.testSubject.fetchTransactionTypes(null, 0, 10, "code", Sort.Direction.DESC.name());
this.mockMvc.perform(get("/transactiontypes")
.contentType(MediaType.APPLICATION_JSON_VALUE)
.accept(MediaType.ALL_VALUE))
.andExpect(status().isOk())
.andDo(document("document-fetch-transaction-type", preprocessRequest(prettyPrint()), preprocessResponse(prettyPrint())));
}
@Test
public void documentChangeTransactionType ( ) throws Exception {
final TransactionType transactionType = TransactionTypeGenerator.createRandomTransactionType();
transactionType.setCode("AZYX");
transactionType.setName("Account Locked");
transactionType.setDescription("Locked Account");
this.testSubject.createTransactionType(transactionType);
this.eventRecorder.wait(EventConstants.POST_TX_TYPE, transactionType.getCode());
transactionType.setName("Account UnveilOne");
transactionType.setDescription("Unveiled Account");
Gson gson = new Gson();
this.mockMvc.perform(put("/transactiontypes/" + transactionType.getCode())
.contentType(MediaType.APPLICATION_JSON_VALUE)
.accept(MediaType.APPLICATION_JSON_VALUE)
.content(gson.toJson(transactionType)))
.andExpect(status().isAccepted())
.andDo(document("document-change-transaction-type", preprocessRequest(prettyPrint()), preprocessResponse(prettyPrint()),
requestFields(
fieldWithPath("code").description("Transaction Type's code"),
fieldWithPath("name").description("Name of transaction type"),
fieldWithPath("description").description("Description of transaction type")
)));
}
}
| 4,743 |
0 | Create_ds/fineract-cn-accounting/component-test/src/main/java/org/apache/fineract/cn | Create_ds/fineract-cn-accounting/component-test/src/main/java/org/apache/fineract/cn/accounting/JournalEntryApiDocumentation.java | /*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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.apache.fineract.cn.accounting;
import com.google.gson.Gson;
import org.apache.fineract.cn.accounting.api.v1.EventConstants;
import org.apache.fineract.cn.accounting.api.v1.domain.*;
import org.apache.fineract.cn.accounting.util.AccountGenerator;
import org.apache.fineract.cn.accounting.util.JournalEntryGenerator;
import org.apache.fineract.cn.accounting.util.LedgerGenerator;
import org.apache.fineract.cn.lang.DateConverter;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.restdocs.JUnitRestDocumentation;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
import org.springframework.web.context.WebApplicationContext;
import java.math.BigDecimal;
import java.text.MessageFormat;
import java.time.LocalDate;
import java.time.OffsetDateTime;
import java.time.ZoneOffset;
import java.time.format.DateTimeFormatter;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import static org.springframework.restdocs.mockmvc.MockMvcRestDocumentation.document;
import static org.springframework.restdocs.mockmvc.MockMvcRestDocumentation.documentationConfiguration;
import static org.springframework.restdocs.mockmvc.RestDocumentationRequestBuilders.get;
import static org.springframework.restdocs.mockmvc.RestDocumentationRequestBuilders.post;
import static org.springframework.restdocs.operation.preprocess.Preprocessors.preprocessRequest;
import static org.springframework.restdocs.operation.preprocess.Preprocessors.preprocessResponse;
import static org.springframework.restdocs.operation.preprocess.Preprocessors.prettyPrint;
import static org.springframework.restdocs.payload.PayloadDocumentation.fieldWithPath;
import static org.springframework.restdocs.payload.PayloadDocumentation.requestFields;
import static org.springframework.restdocs.payload.PayloadDocumentation.responseFields;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
public class JournalEntryApiDocumentation extends AbstractAccountingTest {
@Rule
public final JUnitRestDocumentation restDocumentation = new JUnitRestDocumentation("build/doc/generated-snippets/test-journal-entry");
@Autowired
private WebApplicationContext context;
private MockMvc mockMvc;
@Before
public void setUp ( ) {
this.mockMvc = MockMvcBuilders.webAppContextSetup(this.context)
.apply(documentationConfiguration(this.restDocumentation))
.alwaysDo(document("{method-name}", preprocessRequest(prettyPrint()), preprocessResponse(prettyPrint())))
.build();
}
@Test
public void documentCreateJournalEntry ( ) throws Exception {
final Ledger assetLedger = LedgerGenerator.createRandomLedger();
assetLedger.setType(AccountType.ASSET.name());
this.testSubject.createLedger(assetLedger);
this.eventRecorder.wait(EventConstants.POST_LEDGER, assetLedger.getIdentifier());
final Account debtorAccount = AccountGenerator.createRandomAccount(assetLedger.getIdentifier());
debtorAccount.setIdentifier("7100");
debtorAccount.setType(AccountType.ASSET.name());
debtorAccount.setBalance(100.00D);
this.testSubject.createAccount(debtorAccount);
this.eventRecorder.wait(EventConstants.POST_ACCOUNT, debtorAccount.getIdentifier());
final Ledger liabilityLedger = LedgerGenerator.createRandomLedger();
liabilityLedger.setIdentifier("8120");
liabilityLedger.setType(AccountType.LIABILITY.name());
this.testSubject.createLedger(liabilityLedger);
this.eventRecorder.wait(EventConstants.POST_LEDGER, liabilityLedger.getIdentifier());
final Account creditorAccount = AccountGenerator.createRandomAccount(liabilityLedger.getIdentifier());
creditorAccount.setType(AccountType.LIABILITY.name());
creditorAccount.setBalance(100.00D);
this.testSubject.createAccount(creditorAccount);
this.eventRecorder.wait(EventConstants.POST_ACCOUNT, creditorAccount.getIdentifier());
final JournalEntry journalEntry = JournalEntryGenerator.createRandomJournalEntry(debtorAccount, "50.00",
creditorAccount, "50.00");
journalEntry.setTransactionIdentifier("F14062018");
journalEntry.setTransactionDate(LocalDate.now().toString());
journalEntry.setTransactionType("ADBT");
journalEntry.setClerk("Boring Clerk");
journalEntry.setNote("Account Db");
journalEntry.setMessage("Account Has Been Debited");
Set <Debtor> debtorSet = new HashSet <>();
debtorSet.add(new Debtor(debtorAccount.getIdentifier(), debtorAccount.getBalance().toString()));
Set <Creditor> creditorSet = new HashSet <>();
creditorSet.add(new Creditor(creditorAccount.getIdentifier(), creditorAccount.getBalance().toString()));
journalEntry.setDebtors(debtorSet);
journalEntry.setCreditors(creditorSet);
Gson gson = new Gson();
this.mockMvc.perform(post("/journal")
.contentType(MediaType.APPLICATION_JSON_VALUE)
.accept(MediaType.APPLICATION_JSON_VALUE)
.content(gson.toJson(journalEntry)))
.andExpect(status().isAccepted())
.andDo(document("document-create-journal-entry", preprocessRequest(prettyPrint()), preprocessResponse(prettyPrint()),
requestFields(
fieldWithPath("transactionIdentifier").description("Transaction ID"),
fieldWithPath("transactionDate").description("Account identifier"),
fieldWithPath("transactionType").description("Type of transaction"),
fieldWithPath("clerk").type("String").description("Clerk who initiated transaction"),
fieldWithPath("note").type("String").description("Transaction note"),
fieldWithPath("debtors").type("Set<Debtors>").description("Set of debtors"),
fieldWithPath("creditors").type("Set<Creditors>").description("Set of creditors"),
fieldWithPath("message").description("Associated ledger")
)));
}
@Test
public void documentFetchJournalEntries ( ) throws Exception {
final Ledger assetLedgerOne = LedgerGenerator.createRandomLedger();
assetLedgerOne.setIdentifier("7120");
assetLedgerOne.setType(AccountType.ASSET.name());
this.testSubject.createLedger(assetLedgerOne);
this.eventRecorder.wait(EventConstants.POST_LEDGER, assetLedgerOne.getIdentifier());
final Account accountToDebitOne = AccountGenerator.createRandomAccount(assetLedgerOne.getIdentifier());
accountToDebitOne.setIdentifier("7140");
accountToDebitOne.setType(AccountType.ASSET.name());
accountToDebitOne.setBalance(1000.0);
this.testSubject.createAccount(accountToDebitOne);
this.eventRecorder.wait(EventConstants.POST_ACCOUNT, accountToDebitOne.getIdentifier());
final Ledger liabilityLedgerOne = LedgerGenerator.createRandomLedger();
liabilityLedgerOne.setIdentifier("8150");
liabilityLedgerOne.setType(AccountType.LIABILITY.name());
this.testSubject.createLedger(liabilityLedgerOne);
this.eventRecorder.wait(EventConstants.POST_LEDGER, liabilityLedgerOne.getIdentifier());
final Account accountToCreditOne = AccountGenerator.createRandomAccount(liabilityLedgerOne.getIdentifier());
accountToCreditOne.setIdentifier("8160");
accountToCreditOne.setType(AccountType.LIABILITY.name());
this.testSubject.createAccount(accountToCreditOne);
this.eventRecorder.wait(EventConstants.POST_ACCOUNT, accountToCreditOne.getIdentifier());
final JournalEntry journalEntryOne = JournalEntryGenerator.createRandomJournalEntry(accountToDebitOne, "50.00",
accountToCreditOne, "50.00");
final OffsetDateTime startOne = OffsetDateTime.of(2017, 6, 20, 1, 0, 0, 0, ZoneOffset.UTC);
journalEntryOne.setTransactionDate(startOne.format(DateTimeFormatter.ISO_ZONED_DATE_TIME));
journalEntryOne.setTransactionIdentifier("FE1");
journalEntryOne.setTransactionType("ACCT");
journalEntryOne.setClerk("Mr. " + journalEntryOne.getClerk().toUpperCase().charAt(0) + journalEntryOne.getClerk().substring(1, 5));
journalEntryOne.setNote("Noted Transfer");
journalEntryOne.setMessage("First Message Noted");
this.testSubject.createJournalEntry(journalEntryOne);
this.eventRecorder.wait(EventConstants.POST_JOURNAL_ENTRY, journalEntryOne.getTransactionIdentifier());
this.eventRecorder.wait(EventConstants.RELEASE_JOURNAL_ENTRY, journalEntryOne.getTransactionIdentifier());
final Ledger assetLedgerTwo = LedgerGenerator.createRandomLedger();
assetLedgerTwo.setIdentifier("7200");
assetLedgerTwo.setType(AccountType.ASSET.name());
this.testSubject.createLedger(assetLedgerTwo);
this.eventRecorder.wait(EventConstants.POST_LEDGER, assetLedgerTwo.getIdentifier());
final Account accountToDebitTwo = AccountGenerator.createRandomAccount(assetLedgerTwo.getIdentifier());
accountToDebitTwo.setIdentifier("7210");
accountToDebitTwo.setType(AccountType.ASSET.name());
accountToDebitTwo.setBalance(2000.0);
this.testSubject.createAccount(accountToDebitTwo);
this.eventRecorder.wait(EventConstants.POST_ACCOUNT, accountToDebitTwo.getIdentifier());
final Ledger liabilityLedgerTwo = LedgerGenerator.createRandomLedger();
liabilityLedgerTwo.setIdentifier("8200");
liabilityLedgerTwo.setType(AccountType.LIABILITY.name());
this.testSubject.createLedger(liabilityLedgerTwo);
this.eventRecorder.wait(EventConstants.POST_LEDGER, liabilityLedgerTwo.getIdentifier());
final Account accountToCreditTwo = AccountGenerator.createRandomAccount(liabilityLedgerTwo.getIdentifier());
accountToCreditTwo.setIdentifier("8210");
accountToCreditTwo.setType(AccountType.LIABILITY.name());
this.testSubject.createAccount(accountToCreditTwo);
this.eventRecorder.wait(EventConstants.POST_ACCOUNT, accountToCreditTwo.getIdentifier());
final JournalEntry journalEntryTwo = JournalEntryGenerator.createRandomJournalEntry(accountToDebitTwo, "40.00",
accountToCreditTwo, "40.00");
final OffsetDateTime startTwo = OffsetDateTime.of(2017, 6, 24, 1, 0, 0, 0, ZoneOffset.UTC);
journalEntryTwo.setTransactionDate(startTwo.format(DateTimeFormatter.ISO_ZONED_DATE_TIME));
journalEntryTwo.setTransactionIdentifier("FE2");
journalEntryTwo.setTransactionType("ACRT");
journalEntryTwo.setClerk("Mrs. " + journalEntryTwo.getClerk().toUpperCase().charAt(0) + journalEntryTwo.getClerk().substring(1, 5));
journalEntryTwo.setNote("Noted Credit");
journalEntryTwo.setMessage("Message Noted");
this.testSubject.createJournalEntry(journalEntryTwo);
this.eventRecorder.wait(EventConstants.POST_JOURNAL_ENTRY, journalEntryTwo.getTransactionIdentifier());
this.eventRecorder.wait(EventConstants.RELEASE_JOURNAL_ENTRY, journalEntryTwo.getTransactionIdentifier());
final LocalDate beginDate = LocalDate.of(2017, 6, 20);
final LocalDate endDate = LocalDate.of(2017, 6, 24);
final String dateRange = MessageFormat.format("{0}..{1}",
DateConverter.toIsoString(beginDate),
DateConverter.toIsoString(endDate));
final List <JournalEntry> journalEntriesPage =
this.testSubject.fetchJournalEntries(dateRange, accountToDebitOne.getIdentifier(), BigDecimal.valueOf(50.00D));
Gson gson = new Gson();
this.mockMvc.perform(get("/journal")
.contentType(MediaType.APPLICATION_JSON_VALUE)
.accept(MediaType.ALL_VALUE))
.andExpect(status().isOk())
.andDo(document("document-fetch-journal-entries", preprocessRequest(prettyPrint()), preprocessResponse(prettyPrint())));
}
@Test
public void documentFindJournalEntry ( ) throws Exception {
final Ledger assetLedger = LedgerGenerator.createRandomLedger();
assetLedger.setIdentifier("7100");
assetLedger.setType(AccountType.ASSET.name());
this.testSubject.createLedger(assetLedger);
this.eventRecorder.wait(EventConstants.POST_LEDGER, assetLedger.getIdentifier());
final Account accountToDebit = AccountGenerator.createRandomAccount(assetLedger.getIdentifier());
accountToDebit.setIdentifier("7110");
accountToDebit.setType(AccountType.ASSET.name());
accountToDebit.setBalance(1000.0);
this.testSubject.createAccount(accountToDebit);
this.eventRecorder.wait(EventConstants.POST_ACCOUNT, accountToDebit.getIdentifier());
final Ledger liabilityLedger = LedgerGenerator.createRandomLedger();
liabilityLedger.setIdentifier("8100");
liabilityLedger.setType(AccountType.LIABILITY.name());
this.testSubject.createLedger(liabilityLedger);
this.eventRecorder.wait(EventConstants.POST_LEDGER, liabilityLedger.getIdentifier());
final Account accountToCredit = AccountGenerator.createRandomAccount(liabilityLedger.getIdentifier());
accountToCredit.setIdentifier("8110");
accountToCredit.setType(AccountType.LIABILITY.name());
this.testSubject.createAccount(accountToCredit);
this.eventRecorder.wait(EventConstants.POST_ACCOUNT, accountToCredit.getIdentifier());
final JournalEntry journalEntry = JournalEntryGenerator.createRandomJournalEntry(accountToDebit, "50.00",
accountToCredit, "50.00");
final OffsetDateTime start = OffsetDateTime.of(2017, 6, 24, 1, 0, 0, 0, ZoneOffset.UTC);
journalEntry.setTransactionDate(start.format(DateTimeFormatter.ISO_ZONED_DATE_TIME));
journalEntry.setTransactionIdentifier("FE136183");
journalEntry.setTransactionType("ACCO");
journalEntry.setClerk("Mr. " + journalEntry.getClerk().toUpperCase().charAt(0) + journalEntry.getClerk().substring(1, 5));
journalEntry.setNote("Noted");
journalEntry.setMessage("Message Noted");
this.testSubject.createJournalEntry(journalEntry);
this.eventRecorder.wait(EventConstants.POST_JOURNAL_ENTRY, journalEntry.getTransactionIdentifier());
this.eventRecorder.wait(EventConstants.RELEASE_JOURNAL_ENTRY, journalEntry.getTransactionIdentifier());
this.mockMvc.perform(get("/journal/" + journalEntry.getTransactionIdentifier())
.contentType(MediaType.APPLICATION_JSON_VALUE)
.accept(MediaType.ALL_VALUE))
.andExpect(status().isOk())
.andDo(document("document-find-journal-entry", preprocessRequest(prettyPrint()), preprocessResponse(prettyPrint()),
responseFields(
fieldWithPath("transactionIdentifier").description("Transaction ID"),
fieldWithPath("transactionDate").description("Account identifier"),
fieldWithPath("transactionType").description("Type of transaction"),
fieldWithPath("clerk").type("String").description("Clerk who initiated transaction"),
fieldWithPath("note").type("String").description("Transaction note"),
fieldWithPath("debtors").type("Set<Debtors>").description("Set of debtors"),
fieldWithPath("creditors").type("Set<Creditors>").description("Set of creditors"),
fieldWithPath("state").type("State").description("State of journal entry " +
" + \n" +
" *enum* _State_ { + \n" +
" PENDING, + \n" +
" PROCESSED + \n" +
" } +"),
fieldWithPath("message").description("Journal Message ")
)));
}
}
| 4,744 |
0 | Create_ds/fineract-cn-accounting/component-test/src/main/java/org/apache/fineract/cn | Create_ds/fineract-cn-accounting/component-test/src/main/java/org/apache/fineract/cn/accounting/TestIncomeStatement.java | /*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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.apache.fineract.cn.accounting;
import org.apache.fineract.cn.accounting.api.v1.EventConstants;
import org.apache.fineract.cn.accounting.api.v1.domain.Account;
import org.apache.fineract.cn.accounting.api.v1.domain.AccountType;
import org.apache.fineract.cn.accounting.api.v1.domain.JournalEntry;
import org.apache.fineract.cn.accounting.api.v1.domain.Ledger;
import org.apache.fineract.cn.accounting.api.v1.domain.financial.statement.IncomeStatement;
import org.apache.fineract.cn.accounting.util.AccountGenerator;
import org.apache.fineract.cn.accounting.util.JournalEntryGenerator;
import org.apache.fineract.cn.accounting.util.LedgerGenerator;
import org.junit.Assert;
import org.junit.Test;
import java.math.BigDecimal;
public class TestIncomeStatement extends AbstractAccountingTest {
public TestIncomeStatement() {
super();
}
@Test
public void shouldReturnIncomeStatement() throws Exception {
this.fixtures();
this.sampleJournalEntries();
final BigDecimal expectedGrossProfit = BigDecimal.valueOf(350.00D);
final BigDecimal expectedTotalExpenses = BigDecimal.valueOf(125.00D);
final BigDecimal expectedNetIncome = expectedGrossProfit.subtract(expectedTotalExpenses);
final IncomeStatement incomeStatement = super.testSubject.getIncomeStatement();
Assert.assertTrue(incomeStatement.getGrossProfit().compareTo(expectedGrossProfit) == 0);
Assert.assertTrue(incomeStatement.getTotalExpenses().compareTo(expectedTotalExpenses) == 0);
Assert.assertTrue(incomeStatement.getNetIncome().compareTo(expectedNetIncome) == 0);
}
private void fixtures() throws Exception {
final Ledger incomeLedger = LedgerGenerator.createLedger("1000", AccountType.REVENUE);
incomeLedger.setName("Income");
super.testSubject.createLedger(incomeLedger);
Assert.assertTrue(super.eventRecorder.wait(EventConstants.POST_LEDGER, incomeLedger.getIdentifier()));
final Ledger incomeSubLedger1100 = LedgerGenerator.createLedger("1100", AccountType.REVENUE);
incomeSubLedger1100.setParentLedgerIdentifier(incomeLedger.getParentLedgerIdentifier());
incomeSubLedger1100.setName("Income From Loans");
super.testSubject.addSubLedger(incomeLedger.getIdentifier(), incomeSubLedger1100);
Assert.assertTrue(super.eventRecorder.wait(EventConstants.POST_LEDGER, incomeSubLedger1100.getIdentifier()));
final Ledger incomeSubLedger1300 = LedgerGenerator.createLedger("1300", AccountType.REVENUE);
incomeSubLedger1300.setParentLedgerIdentifier(incomeLedger.getParentLedgerIdentifier());
incomeSubLedger1300.setName("Fees and Charges");
super.testSubject.addSubLedger(incomeLedger.getIdentifier(), incomeSubLedger1300);
Assert.assertTrue(super.eventRecorder.wait(EventConstants.POST_LEDGER, incomeSubLedger1300.getIdentifier()));
final Account account1110 =
AccountGenerator.createAccount(incomeSubLedger1100.getIdentifier(), "1110", AccountType.REVENUE);
super.testSubject.createAccount(account1110);
Assert.assertTrue(super.eventRecorder.wait(EventConstants.POST_ACCOUNT, account1110.getIdentifier()));
final Account account1310 =
AccountGenerator.createAccount(incomeSubLedger1300.getIdentifier(), "1310", AccountType.REVENUE);
super.testSubject.createAccount(account1310);
Assert.assertTrue(super.eventRecorder.wait(EventConstants.POST_ACCOUNT, account1310.getIdentifier()));
final Ledger expenseLedger = LedgerGenerator.createLedger("3000", AccountType.EXPENSE);
expenseLedger.setName("Expenses");
super.testSubject.createLedger(expenseLedger);
Assert.assertTrue(super.eventRecorder.wait(EventConstants.POST_LEDGER, expenseLedger.getIdentifier()));
final Ledger expenseSubLedger3500 = LedgerGenerator.createLedger("3500", AccountType.EXPENSE);
expenseSubLedger3500.setParentLedgerIdentifier(expenseLedger.getParentLedgerIdentifier());
expenseSubLedger3500.setName("Annual Meeting Expenses");
super.testSubject.addSubLedger(expenseLedger.getIdentifier(), expenseSubLedger3500);
Assert.assertTrue(super.eventRecorder.wait(EventConstants.POST_LEDGER, expenseSubLedger3500.getIdentifier()));
final Ledger expenseSubLedger3700 = LedgerGenerator.createLedger("3700", AccountType.EXPENSE);
expenseSubLedger3700.setParentLedgerIdentifier(expenseLedger.getParentLedgerIdentifier());
expenseSubLedger3700.setName("Interest (Dividend) Expense");
super.testSubject.addSubLedger(expenseLedger.getIdentifier(), expenseSubLedger3700);
Assert.assertTrue(super.eventRecorder.wait(EventConstants.POST_LEDGER, expenseSubLedger3700.getIdentifier()));
final Account account3510 =
AccountGenerator.createAccount(expenseSubLedger3500.getIdentifier(), "3510", AccountType.EXPENSE);
super.testSubject.createAccount(account3510);
Assert.assertTrue(super.eventRecorder.wait(EventConstants.POST_ACCOUNT, account3510.getIdentifier()));
final Account account3710 =
AccountGenerator.createAccount(expenseSubLedger3700.getIdentifier(), "3710", AccountType.EXPENSE);
super.testSubject.createAccount(account3710);
Assert.assertTrue(super.eventRecorder.wait(EventConstants.POST_ACCOUNT, account3710.getIdentifier()));
final Ledger assetLedger = LedgerGenerator.createLedger("7000", AccountType.ASSET);
super.testSubject.createLedger(assetLedger);
Assert.assertTrue(super.eventRecorder.wait(EventConstants.POST_LEDGER, assetLedger.getIdentifier()));
final Account assetAccount =
AccountGenerator.createAccount(assetLedger.getIdentifier(), "7010", AccountType.ASSET);
super.testSubject.createAccount(assetAccount);
Assert.assertTrue(super.eventRecorder.wait(EventConstants.POST_ACCOUNT, assetAccount.getIdentifier()));
final Ledger liabilityLedger = LedgerGenerator.createLedger("8000", AccountType.LIABILITY);
super.testSubject.createLedger(liabilityLedger);
Assert.assertTrue(super.eventRecorder.wait(EventConstants.POST_LEDGER, liabilityLedger.getIdentifier()));
final Account liabilityAccount =
AccountGenerator.createAccount(liabilityLedger.getIdentifier(), "8010", AccountType.LIABILITY);
super.testSubject.createAccount(liabilityAccount);
Assert.assertTrue(super.eventRecorder.wait(EventConstants.POST_ACCOUNT, liabilityAccount.getIdentifier()));
}
private void sampleJournalEntries() throws Exception {
final JournalEntry firstTransaction =
JournalEntryGenerator
.createRandomJournalEntry("7010", "150.00", "1110", "150.00");
super.testSubject.createJournalEntry(firstTransaction);
Assert.assertTrue(super.eventRecorder.wait(EventConstants.POST_JOURNAL_ENTRY, firstTransaction.getTransactionIdentifier()));
final JournalEntry secondTransaction =
JournalEntryGenerator
.createRandomJournalEntry("7010", "200.00", "1310", "200.00");
super.testSubject.createJournalEntry(secondTransaction);
Assert.assertTrue(super.eventRecorder.wait(EventConstants.POST_JOURNAL_ENTRY, secondTransaction.getTransactionIdentifier()));
final JournalEntry thirdTransaction =
JournalEntryGenerator
.createRandomJournalEntry("3510", "50.00", "8010", "50.00");
super.testSubject.createJournalEntry(thirdTransaction);
Assert.assertTrue(super.eventRecorder.wait(EventConstants.POST_JOURNAL_ENTRY, thirdTransaction.getTransactionIdentifier()));
final JournalEntry fourthTransaction =
JournalEntryGenerator
.createRandomJournalEntry("3710", "75.00", "8010", "75.00");
super.testSubject.createJournalEntry(fourthTransaction);
Assert.assertTrue(super.eventRecorder.wait(EventConstants.POST_JOURNAL_ENTRY, fourthTransaction.getTransactionIdentifier()));
}
}
| 4,745 |
0 | Create_ds/fineract-cn-accounting/component-test/src/main/java/org/apache/fineract/cn | Create_ds/fineract-cn-accounting/component-test/src/main/java/org/apache/fineract/cn/accounting/TestSuite.java | /*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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.apache.fineract.cn.accounting;
import org.junit.runner.RunWith;
import org.junit.runners.Suite;
/**
* @author Myrle Krantz
*/
@RunWith(Suite.class)
@Suite.SuiteClasses({
TestAccount.class,
TestChartOfAccounts.class,
TestFinancialCondition.class,
TestIncomeStatement.class,
TestJournalEntry.class,
TestLedger.class,
TestTransactionType.class,
TestTrialBalance.class,
})
public class TestSuite extends SuiteTestEnvironment {
}
| 4,746 |
0 | Create_ds/fineract-cn-accounting/component-test/src/main/java/org/apache/fineract/cn/accounting | Create_ds/fineract-cn-accounting/component-test/src/main/java/org/apache/fineract/cn/accounting/listener/MigrationEventListener.java | /*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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.apache.fineract.cn.accounting.listener;
import org.apache.fineract.cn.accounting.AbstractAccountingTest;
import org.apache.fineract.cn.accounting.api.v1.EventConstants;
import org.apache.fineract.cn.lang.config.TenantHeaderFilter;
import org.apache.fineract.cn.test.listener.EventRecorder;
import org.slf4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.jms.annotation.JmsListener;
import org.springframework.messaging.handler.annotation.Header;
import org.springframework.stereotype.Component;
@SuppressWarnings("unused")
@Component
public class MigrationEventListener {
private final Logger logger;
private final EventRecorder eventRecorder;
@SuppressWarnings("SpringJavaAutowiringInspection")
@Autowired
public MigrationEventListener(final @Qualifier(AbstractAccountingTest.TEST_LOGGER) Logger logger, final EventRecorder eventRecorder) {
super();
this.logger = logger;
this.eventRecorder = eventRecorder;
}
@JmsListener(
destination = EventConstants.DESTINATION,
selector = EventConstants.SELECTOR_INITIALIZE,
subscription = EventConstants.DESTINATION
)
public void onInitialization(@Header(TenantHeaderFilter.TENANT_HEADER) final String tenant,
final String payload) {
this.logger.debug("Provisioning finished.");
this.eventRecorder.event(tenant, EventConstants.INITIALIZE, payload, String.class);
}
}
| 4,747 |
0 | Create_ds/fineract-cn-accounting/component-test/src/main/java/org/apache/fineract/cn/accounting | Create_ds/fineract-cn-accounting/component-test/src/main/java/org/apache/fineract/cn/accounting/listener/TransactionTypeEventListener.java | /*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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.apache.fineract.cn.accounting.listener;
import org.apache.fineract.cn.accounting.AbstractAccountingTest;
import org.apache.fineract.cn.accounting.api.v1.EventConstants;
import org.apache.fineract.cn.lang.config.TenantHeaderFilter;
import org.apache.fineract.cn.test.listener.EventRecorder;
import org.slf4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.jms.annotation.JmsListener;
import org.springframework.messaging.handler.annotation.Header;
import org.springframework.stereotype.Component;
@SuppressWarnings("unused")
@Component
public class TransactionTypeEventListener {
private final Logger logger;
private final EventRecorder eventRecorder;
@Autowired
public TransactionTypeEventListener(@Qualifier(AbstractAccountingTest.TEST_LOGGER) final Logger logger,
final EventRecorder eventRecorder) {
super();
this.logger = logger;
this.eventRecorder = eventRecorder;
}
@JmsListener(
destination = EventConstants.DESTINATION,
selector = EventConstants.SELECTOR_POST_TX_TYPE,
subscription = EventConstants.DESTINATION
)
public void onPostTransactionType(@Header(TenantHeaderFilter.TENANT_HEADER) final String tenant,
final String payload) {
this.logger.debug("Transaction type created.");
this.eventRecorder.event(tenant, EventConstants.POST_TX_TYPE, payload, String.class);
}
@JmsListener(
destination = EventConstants.DESTINATION,
selector = EventConstants.SELECTOR_PUT_TX_TYPE,
subscription = EventConstants.DESTINATION
)
public void onPutTransactionType(@Header(TenantHeaderFilter.TENANT_HEADER) final String tenant,
final String payload) {
this.logger.debug("Transaction type created.");
this.eventRecorder.event(tenant, EventConstants.PUT_TX_TYPE, payload, String.class);
}
}
| 4,748 |
0 | Create_ds/fineract-cn-accounting/component-test/src/main/java/org/apache/fineract/cn/accounting | Create_ds/fineract-cn-accounting/component-test/src/main/java/org/apache/fineract/cn/accounting/listener/AccountEventListener.java | /*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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.apache.fineract.cn.accounting.listener;
import org.apache.fineract.cn.accounting.AbstractAccountingTest;
import org.apache.fineract.cn.accounting.api.v1.EventConstants;
import org.apache.fineract.cn.lang.config.TenantHeaderFilter;
import org.apache.fineract.cn.test.listener.EventRecorder;
import org.slf4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.jms.annotation.JmsListener;
import org.springframework.messaging.handler.annotation.Header;
import org.springframework.stereotype.Component;
@SuppressWarnings("unused")
@Component
public class AccountEventListener {
private final Logger logger;
private final EventRecorder eventRecorder;
@SuppressWarnings("SpringJavaAutowiringInspection")
@Autowired
public AccountEventListener(final @Qualifier(AbstractAccountingTest.TEST_LOGGER) Logger logger, final EventRecorder eventRecorder) {
super();
this.logger = logger;
this.eventRecorder = eventRecorder;
}
@JmsListener(
destination = EventConstants.DESTINATION,
selector = EventConstants.SELECTOR_POST_ACCOUNT,
subscription = EventConstants.DESTINATION
)
public void onCreateAccount(@Header(TenantHeaderFilter.TENANT_HEADER) final String tenant,
final String payload) {
this.logger.debug("Account created.");
this.eventRecorder.event(tenant, EventConstants.POST_ACCOUNT, payload, String.class);
}
@JmsListener(
destination = EventConstants.DESTINATION,
selector = EventConstants.SELECTOR_PUT_ACCOUNT,
subscription = EventConstants.DESTINATION
)
public void onChangeAccount(@Header(TenantHeaderFilter.TENANT_HEADER) final String tenant,
final String payload) {
this.logger.debug("Account modified.");
this.eventRecorder.event(tenant, EventConstants.PUT_ACCOUNT, payload, String.class);
}
@JmsListener(
destination = EventConstants.DESTINATION,
selector = EventConstants.SELECTOR_CLOSE_ACCOUNT,
subscription = EventConstants.DESTINATION
)
public void onCloseAccount(@Header(TenantHeaderFilter.TENANT_HEADER) final String tenant,
final String payload) {
this.logger.debug("Account closed.");
this.eventRecorder.event(tenant, EventConstants.CLOSE_ACCOUNT, payload, String.class);
}
@JmsListener(
destination = EventConstants.DESTINATION,
selector = EventConstants.SELECTOR_LOCK_ACCOUNT,
subscription = EventConstants.DESTINATION
)
public void onLockAccount(@Header(TenantHeaderFilter.TENANT_HEADER) final String tenant,
final String payload) {
this.logger.debug("Account locked.");
this.eventRecorder.event(tenant, EventConstants.LOCK_ACCOUNT, payload, String.class);
}
@JmsListener(
destination = EventConstants.DESTINATION,
selector = EventConstants.SELECTOR_UNLOCK_ACCOUNT,
subscription = EventConstants.DESTINATION
)
public void onUnlockAccount(@Header(TenantHeaderFilter.TENANT_HEADER) final String tenant,
final String payload) {
this.logger.debug("Account unlocked.");
this.eventRecorder.event(tenant, EventConstants.UNLOCK_ACCOUNT, payload, String.class);
}
@JmsListener(
destination = EventConstants.DESTINATION,
selector = EventConstants.SELECTOR_REOPEN_ACCOUNT,
subscription = EventConstants.DESTINATION
)
public void onReopenAccount(@Header(TenantHeaderFilter.TENANT_HEADER) final String tenant,
final String payload) {
this.logger.debug("Account reopened.");
this.eventRecorder.event(tenant, EventConstants.REOPEN_ACCOUNT, payload, String.class);
}
@JmsListener(
destination = EventConstants.DESTINATION,
selector = EventConstants.SELECTOR_DELETE_ACCOUNT,
subscription = EventConstants.DESTINATION
)
public void onDeleteAccount(@Header(TenantHeaderFilter.TENANT_HEADER) final String tenant,
final String payload) {
this.logger.debug("Account deleted.");
this.eventRecorder.event(tenant, EventConstants.DELETE_ACCOUNT, payload, String.class);
}
}
| 4,749 |
0 | Create_ds/fineract-cn-accounting/component-test/src/main/java/org/apache/fineract/cn/accounting | Create_ds/fineract-cn-accounting/component-test/src/main/java/org/apache/fineract/cn/accounting/listener/LedgerEventListener.java | /*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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.apache.fineract.cn.accounting.listener;
import org.apache.fineract.cn.accounting.AbstractAccountingTest;
import org.apache.fineract.cn.accounting.api.v1.EventConstants;
import org.apache.fineract.cn.lang.config.TenantHeaderFilter;
import org.apache.fineract.cn.test.listener.EventRecorder;
import org.slf4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.jms.annotation.JmsListener;
import org.springframework.messaging.handler.annotation.Header;
import org.springframework.stereotype.Component;
@SuppressWarnings("unused")
@Component
public class LedgerEventListener {
private final Logger logger;
private final EventRecorder eventRecorder;
@SuppressWarnings("SpringJavaAutowiringInspection")
@Autowired
public LedgerEventListener(final @Qualifier(AbstractAccountingTest.TEST_LOGGER) Logger logger, final EventRecorder eventRecorder) {
super();
this.logger = logger;
this.eventRecorder = eventRecorder;
}
@JmsListener(
destination = EventConstants.DESTINATION,
selector = EventConstants.SELECTOR_POST_LEDGER,
subscription = EventConstants.DESTINATION
)
public void onPostLedger(@Header(TenantHeaderFilter.TENANT_HEADER) final String tenant,
final String payload) {
this.logger.debug("Ledger created.");
this.eventRecorder.event(tenant, EventConstants.POST_LEDGER, payload, String.class);
}
@JmsListener(
destination = EventConstants.DESTINATION,
selector = EventConstants.SELECTOR_PUT_LEDGER,
subscription = EventConstants.DESTINATION
)
public void onPutLedger(@Header(TenantHeaderFilter.TENANT_HEADER) final String tenant,
final String payload) {
this.logger.debug("Ledger modified.");
this.eventRecorder.event(tenant, EventConstants.PUT_LEDGER, payload, String.class);
}
@JmsListener(
destination = EventConstants.DESTINATION,
selector = EventConstants.SELECTOR_DELETE_LEDGER,
subscription = EventConstants.DESTINATION
)
public void onDeleteLedger(@Header(TenantHeaderFilter.TENANT_HEADER) final String tenant,
final String payload) {
this.logger.debug("Ledger deleted.");
this.eventRecorder.event(tenant, EventConstants.DELETE_LEDGER, payload, String.class);
}
}
| 4,750 |
0 | Create_ds/fineract-cn-accounting/component-test/src/main/java/org/apache/fineract/cn/accounting | Create_ds/fineract-cn-accounting/component-test/src/main/java/org/apache/fineract/cn/accounting/listener/JournalEntryEventListener.java | /*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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.apache.fineract.cn.accounting.listener;
import org.apache.fineract.cn.accounting.AbstractAccountingTest;
import org.apache.fineract.cn.accounting.api.v1.EventConstants;
import org.apache.fineract.cn.lang.config.TenantHeaderFilter;
import org.apache.fineract.cn.test.listener.EventRecorder;
import org.slf4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.jms.annotation.JmsListener;
import org.springframework.messaging.handler.annotation.Header;
import org.springframework.stereotype.Component;
@SuppressWarnings("unused")
@Component
public class JournalEntryEventListener {
private final Logger logger;
private final EventRecorder eventRecorder;
@SuppressWarnings("SpringJavaAutowiringInspection")
@Autowired
public JournalEntryEventListener(final @Qualifier(AbstractAccountingTest.TEST_LOGGER) Logger logger,
final EventRecorder eventRecorder) {
this.logger = logger;
this.eventRecorder = eventRecorder;
}
@JmsListener(
destination = EventConstants.DESTINATION,
selector = EventConstants.SELECTOR_POST_JOURNAL_ENTRY,
subscription = EventConstants.DESTINATION
)
public void onPostJournalEntry(@Header(TenantHeaderFilter.TENANT_HEADER) final String tenant,
final String transactionIdentifier) {
this.logger.debug("Journal entry created");
this.eventRecorder.event(tenant, EventConstants.POST_JOURNAL_ENTRY, transactionIdentifier, String.class);
}
@JmsListener(
destination = EventConstants.DESTINATION,
selector = EventConstants.SELECTOR_RELEASE_JOURNAL_ENTRY,
subscription = EventConstants.DESTINATION
)
public void onJournalEntryProcessed(@Header(TenantHeaderFilter.TENANT_HEADER) final String tenant,
final String transactionIdentifier) {
this.logger.debug("Journal entry processed");
this.eventRecorder.event(tenant, EventConstants.RELEASE_JOURNAL_ENTRY, transactionIdentifier, String.class);
}
}
| 4,751 |
0 | Create_ds/fineract-cn-accounting/component-test/src/main/java/org/apache/fineract/cn/accounting | Create_ds/fineract-cn-accounting/component-test/src/main/java/org/apache/fineract/cn/accounting/importer/TestImport.java | /*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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.apache.fineract.cn.accounting.importer;
import org.apache.fineract.cn.accounting.AbstractAccountingTest;
import org.apache.fineract.cn.accounting.api.v1.EventConstants;
import org.apache.fineract.cn.accounting.api.v1.domain.Account;
import org.apache.fineract.cn.accounting.api.v1.domain.AccountPage;
import org.apache.fineract.cn.accounting.api.v1.domain.AccountType;
import org.apache.fineract.cn.accounting.api.v1.domain.Ledger;
import org.apache.fineract.cn.accounting.api.v1.domain.LedgerPage;
import org.junit.Assert;
import org.junit.Test;
import java.io.IOException;
import java.net.URL;
import java.util.List;
import java.util.Optional;
/**
* @author Myrle Krantz
*/
public class TestImport extends AbstractAccountingTest {
@Test
public void testAccountImportHappyCase() throws IOException, InterruptedException {
final Ledger assetLedger = new Ledger();
assetLedger.setType(AccountType.ASSET.name());
assetLedger.setIdentifier("assetLedger");
assetLedger.setName("asset Ledger");
assetLedger.setShowAccountsInChart(true);
testSubject.createLedger(assetLedger);
Assert.assertTrue(eventRecorder.wait(EventConstants.POST_LEDGER, assetLedger.getIdentifier()));
final Ledger equityLedger = new Ledger();
equityLedger.setType(AccountType.EQUITY.name());
equityLedger.setIdentifier("equityLedger");
equityLedger.setName("equity Ledger");
equityLedger.setShowAccountsInChart(true);
testSubject.createLedger(equityLedger);
Assert.assertTrue(eventRecorder.wait(EventConstants.POST_LEDGER, equityLedger.getIdentifier()));
final AccountImporter accountImporter = new AccountImporter(testSubject, logger);
final URL uri = ClassLoader.getSystemResource("importdata/account-happy-case.csv");
accountImporter.importCSV(uri);
Assert.assertTrue(eventRecorder.wait(EventConstants.POST_ACCOUNT, "abcd"));
Assert.assertTrue(eventRecorder.wait(EventConstants.POST_ACCOUNT, "xyz"));
//Import a second time.
accountImporter.importCSV(uri);
final AccountPage accountsOfAssetLedger
= testSubject.fetchAccountsOfLedger(assetLedger.getIdentifier(), 0, 10, null, null);
final Account firstAccount = accountsOfAssetLedger.getAccounts().get(0);
Assert.assertEquals("abcd", firstAccount.getIdentifier());
Assert.assertEquals(Double.valueOf(0.0), firstAccount.getBalance());
Assert.assertEquals(AbstractAccountingTest.TEST_USER, firstAccount.getCreatedBy());
final AccountPage accountsOfEquityLedger
= testSubject.fetchAccountsOfLedger(equityLedger.getIdentifier(), 0, 10, null, null);
final Account secondAccount = accountsOfEquityLedger.getAccounts().get(0);
Assert.assertEquals("xyz", secondAccount.getIdentifier());
Assert.assertEquals(Double.valueOf(20.0), secondAccount.getBalance());
Assert.assertEquals(AbstractAccountingTest.TEST_USER, secondAccount.getCreatedBy());
}
@Test
public void testAccountFromARealCase() throws IOException, InterruptedException {
final Ledger ledger1000 = new Ledger();
ledger1000.setType(AccountType.REVENUE.name());
ledger1000.setIdentifier("1000");
ledger1000.setName("Income");
ledger1000.setShowAccountsInChart(true);
testSubject.createLedger(ledger1000);
Assert.assertTrue(eventRecorder.wait(EventConstants.POST_LEDGER, ledger1000.getIdentifier()));
final Ledger ledger1100 = new Ledger();
ledger1100.setType(AccountType.REVENUE.name());
ledger1100.setIdentifier("1100");
ledger1100.setName("Income from Loans");
ledger1100.setParentLedgerIdentifier("1000");
ledger1100.setShowAccountsInChart(true);
testSubject.addSubLedger(ledger1100.getParentLedgerIdentifier(),ledger1100);
Assert.assertTrue(eventRecorder.wait(EventConstants.POST_LEDGER, ledger1100.getIdentifier()));
final AccountImporter accountImporter = new AccountImporter(testSubject, logger);
final URL uri = ClassLoader.getSystemResource("importdata/account-from-a-real-case.csv");
accountImporter.importCSV(uri);
Assert.assertTrue(eventRecorder.wait(EventConstants.POST_ACCOUNT, "1101"));
Assert.assertTrue(eventRecorder.wait(EventConstants.POST_ACCOUNT, "1102"));
Assert.assertTrue(eventRecorder.wait(EventConstants.POST_ACCOUNT, "1103"));
Assert.assertTrue(eventRecorder.wait(EventConstants.POST_ACCOUNT, "1104"));
Assert.assertTrue(eventRecorder.wait(EventConstants.POST_ACCOUNT, "1105"));
Assert.assertTrue(eventRecorder.wait(EventConstants.POST_ACCOUNT, "1120"));
Assert.assertTrue(eventRecorder.wait(EventConstants.POST_ACCOUNT, "1121"));
Assert.assertTrue(eventRecorder.wait(EventConstants.POST_ACCOUNT, "1140"));
Assert.assertTrue(eventRecorder.wait(EventConstants.POST_ACCOUNT, "1190"));
//Import a second time.
accountImporter.importCSV(uri);
final AccountPage accountsOfAssetLedger
= testSubject.fetchAccountsOfLedger(ledger1100.getIdentifier(), 0, 10, null, null);
final Account firstAccount = accountsOfAssetLedger.getAccounts().get(0);
Assert.assertEquals("1101", firstAccount.getIdentifier());
Assert.assertEquals("Interest on Business Loans", firstAccount.getName());
Assert.assertEquals(Double.valueOf(0.0), firstAccount.getBalance());
Assert.assertEquals(AccountType.REVENUE, AccountType.valueOf(firstAccount.getType()));
Assert.assertEquals(AbstractAccountingTest.TEST_USER, firstAccount.getCreatedBy());
final AccountPage accountsOfEquityLedger
= testSubject.fetchAccountsOfLedger(ledger1100.getIdentifier(), 0, 10, null, null);
final Account secondAccount = accountsOfEquityLedger.getAccounts().get(1);
Assert.assertEquals("1102", secondAccount.getIdentifier());
Assert.assertEquals("Interest on Agriculture Loans", secondAccount.getName());
Assert.assertEquals(Double.valueOf(0.0), secondAccount.getBalance());
Assert.assertEquals(AccountType.REVENUE, AccountType.valueOf(secondAccount.getType()));
Assert.assertEquals(AbstractAccountingTest.TEST_USER, secondAccount.getCreatedBy());
}
@Test
public void testLedgerImportHappyCase() throws IOException, InterruptedException {
final LedgerImporter ledgerImporter = new LedgerImporter(testSubject, logger);
final URL uri = ClassLoader.getSystemResource("importdata/ledger-happy-case.csv");
ledgerImporter.importCSV(uri);
//Import a second time.
ledgerImporter.importCSV(uri);
Assert.assertTrue(eventRecorder.wait(EventConstants.POST_LEDGER, "110"));
Assert.assertTrue(eventRecorder.wait(EventConstants.POST_LEDGER, "111"));
Assert.assertTrue(eventRecorder.wait(EventConstants.POST_LEDGER, "111.1"));
final LedgerPage ledgerPage = testSubject.fetchLedgers(true, "11", null, null, null, null, null);
final List<Ledger> ledgers = ledgerPage.getLedgers();
Assert.assertTrue(ledgers.size() >= 3); //3 from this test, but other tests may already have run.
final Optional<Ledger> ledger110 = ledgers.stream().filter(x -> x.getIdentifier().equals("110")).findAny();
Assert.assertTrue(ledger110.isPresent());
Assert.assertEquals("Loan Ledger", ledger110.get().getDescription());
Assert.assertEquals("ASSET", ledger110.get().getType());
Assert.assertEquals(true, ledger110.get().getShowAccountsInChart());
Assert.assertEquals(AbstractAccountingTest.TEST_USER, ledger110.get().getCreatedBy());
final Optional<Ledger> ledger111 = ledgers.stream().filter(x -> x.getIdentifier().equals("111")).findAny();
Assert.assertTrue(ledger111.isPresent());
Assert.assertEquals("Loan Ledger Interest", ledger111.get().getDescription());
Assert.assertEquals("ASSET", ledger111.get().getType());
Assert.assertEquals(false, ledger111.get().getShowAccountsInChart());
Assert.assertEquals(AbstractAccountingTest.TEST_USER, ledger111.get().getCreatedBy());
final Optional<Ledger> ledger111dot1 = ledgers.stream().filter(x -> x.getIdentifier().equals("111.1")).findAny();
Assert.assertTrue(ledger111dot1.isPresent());
Assert.assertEquals("blub blah", ledger111dot1.get().getDescription());
Assert.assertEquals("ASSET", ledger111dot1.get().getType());
Assert.assertEquals(true, ledger111dot1.get().getShowAccountsInChart());
Assert.assertEquals(AbstractAccountingTest.TEST_USER, ledger111dot1.get().getCreatedBy());
}
@Test
public void testLedgerImportMissingNameCase() throws IOException, InterruptedException {
final LedgerImporter ledgerImporter = new LedgerImporter(testSubject, logger);
final URL uri = ClassLoader.getSystemResource("importdata/ledger-missing-name-case.csv");
ledgerImporter.importCSV(uri);
//Import a second time.
ledgerImporter.importCSV(uri);
Assert.assertTrue(eventRecorder.wait(EventConstants.POST_LEDGER, "210"));
Assert.assertTrue(eventRecorder.wait(EventConstants.POST_LEDGER, "211"));
Assert.assertTrue(eventRecorder.wait(EventConstants.POST_LEDGER, "211.1"));
final LedgerPage ledgerPage = testSubject.fetchLedgers(true, "21", null, null, null, null, null);
final List<Ledger> ledgers = ledgerPage.getLedgers();
Assert.assertEquals(3,ledgers.size());
ledgers.forEach(x -> Assert.assertEquals(x.getIdentifier(), x.getName()));
}
}
| 4,752 |
0 | Create_ds/fineract-cn-accounting/component-test/src/main/java/org/apache/fineract/cn/accounting | Create_ds/fineract-cn-accounting/component-test/src/main/java/org/apache/fineract/cn/accounting/util/LedgerGenerator.java | /*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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.apache.fineract.cn.accounting.util;
import org.apache.fineract.cn.accounting.api.v1.domain.AccountType;
import org.apache.fineract.cn.accounting.api.v1.domain.Ledger;
import org.apache.commons.lang3.RandomStringUtils;
public class LedgerGenerator {
private LedgerGenerator() {
super();
}
public static Ledger createRandomLedger() {
final Ledger ledger = new Ledger();
ledger.setType(AccountType.ASSET.name());
ledger.setIdentifier(RandomStringUtils.randomAlphanumeric(8));
ledger.setName(RandomStringUtils.randomAlphanumeric(256));
ledger.setDescription(RandomStringUtils.randomAlphanumeric(2048));
ledger.setShowAccountsInChart(Boolean.FALSE);
return ledger;
}
public static Ledger createLedger(final String identifier, final AccountType accountType) {
final Ledger ledger = new Ledger();
ledger.setType(accountType.name());
ledger.setIdentifier(identifier);
ledger.setName(RandomStringUtils.randomAlphanumeric(256));
ledger.setDescription(RandomStringUtils.randomAlphanumeric(2048));
ledger.setShowAccountsInChart(Boolean.TRUE);
return ledger;
}
}
| 4,753 |
0 | Create_ds/fineract-cn-accounting/component-test/src/main/java/org/apache/fineract/cn/accounting | Create_ds/fineract-cn-accounting/component-test/src/main/java/org/apache/fineract/cn/accounting/util/AccountGenerator.java | /*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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.apache.fineract.cn.accounting.util;
import org.apache.fineract.cn.accounting.api.v1.domain.Account;
import org.apache.fineract.cn.accounting.api.v1.domain.AccountType;
import org.apache.commons.lang3.RandomStringUtils;
import java.util.Collections;
import java.util.HashSet;
public class AccountGenerator {
private AccountGenerator() {
super();
}
public static Account createRandomAccount(final String ledgerIdentifier) {
final Account account = new Account();
account.setIdentifier(RandomStringUtils.randomAlphanumeric(32));
account.setName(RandomStringUtils.randomAlphanumeric(256));
account.setType(AccountType.ASSET.name());
account.setLedger(ledgerIdentifier);
account.setHolders(new HashSet<>(Collections.singletonList(RandomStringUtils.randomAlphanumeric(32))));
account.setSignatureAuthorities(new HashSet<>(Collections.singletonList(RandomStringUtils.randomAlphanumeric(32))));
account.setBalance(0.00D);
return account;
}
public static Account createAccount(final String ledgerIdentifier, final String accountIdentifier, final AccountType accountType) {
final Account account = new Account();
account.setIdentifier(accountIdentifier);
account.setName(RandomStringUtils.randomAlphanumeric(256));
account.setType(accountType.name());
account.setLedger(ledgerIdentifier);
account.setHolders(new HashSet<>(Collections.singletonList(RandomStringUtils.randomAlphanumeric(32))));
account.setSignatureAuthorities(new HashSet<>(Collections.singletonList(RandomStringUtils.randomAlphanumeric(32))));
account.setBalance(0.00D);
return account;
}
}
| 4,754 |
0 | Create_ds/fineract-cn-accounting/component-test/src/main/java/org/apache/fineract/cn/accounting | Create_ds/fineract-cn-accounting/component-test/src/main/java/org/apache/fineract/cn/accounting/util/TransactionTypeGenerator.java | /*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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.apache.fineract.cn.accounting.util;
import org.apache.fineract.cn.accounting.api.v1.domain.TransactionType;
import org.apache.commons.lang3.RandomStringUtils;
public class TransactionTypeGenerator {
private TransactionTypeGenerator() {
super();
}
public static TransactionType createRandomTransactionType() {
final TransactionType transactionType = new TransactionType();
transactionType.setCode(RandomStringUtils.randomAlphabetic(4));
transactionType.setName(RandomStringUtils.randomAlphanumeric(256));
transactionType.setDescription(RandomStringUtils.randomAlphanumeric(2048));
return transactionType;
}
}
| 4,755 |
0 | Create_ds/fineract-cn-accounting/component-test/src/main/java/org/apache/fineract/cn/accounting | Create_ds/fineract-cn-accounting/component-test/src/main/java/org/apache/fineract/cn/accounting/util/JournalEntryGenerator.java | /*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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.apache.fineract.cn.accounting.util;
import com.google.common.collect.Sets;
import org.apache.fineract.cn.accounting.api.v1.domain.Account;
import org.apache.fineract.cn.accounting.api.v1.domain.Creditor;
import org.apache.fineract.cn.accounting.api.v1.domain.Debtor;
import org.apache.fineract.cn.accounting.api.v1.domain.JournalEntry;
import org.apache.commons.lang3.RandomStringUtils;
import java.time.Clock;
import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Collections;
import java.util.HashSet;
public class JournalEntryGenerator {
private JournalEntryGenerator() {
super();
}
public static JournalEntry createRandomJournalEntry(final Account debtorAccount,
final String debtorAmount,
final Account creditorAccount,
final String creditorAmount) {
return JournalEntryGenerator
.createRandomJournalEntry(
debtorAccount != null ? debtorAccount.getIdentifier() : "randomDebtor",
debtorAmount,
creditorAccount != null ? creditorAccount.getIdentifier() : "randomCreditor",
creditorAmount);
}
public static JournalEntry createRandomJournalEntry(final String debtorAccount,
final String debtorAmount,
final String creditorAccount,
final String creditorAmount) {
final JournalEntry journalEntry = new JournalEntry();
journalEntry.setTransactionIdentifier(RandomStringUtils.randomAlphanumeric(8));
journalEntry.setTransactionDate(ZonedDateTime.now(Clock.systemUTC()).format(DateTimeFormatter.ISO_ZONED_DATE_TIME));
journalEntry.setTransactionType(RandomStringUtils.randomAlphabetic(4));
journalEntry.setClerk("clark");
if (debtorAccount != null) {
final Debtor debtor = new Debtor();
debtor.setAccountNumber(debtorAccount);
debtor.setAmount(debtorAmount);
journalEntry.setDebtors(new HashSet<>(Collections.singletonList(debtor)));
} else {
journalEntry.setDebtors(Sets.newHashSet());
}
if (creditorAccount != null) {
final Creditor creditor = new Creditor();
creditor.setAccountNumber(creditorAccount);
creditor.setAmount(creditorAmount);
journalEntry.setCreditors(new HashSet<>(Collections.singletonList(creditor)));
} else {
journalEntry.setCreditors(Sets.newHashSet());
}
journalEntry.setNote(RandomStringUtils.randomAlphanumeric(512));
journalEntry.setMessage(RandomStringUtils.randomAlphanumeric(512));
return journalEntry;
}
}
| 4,756 |
0 | Create_ds/fineract-cn-accounting/api/src/test/java/org/apache/fineract/cn/accounting/api/v1 | Create_ds/fineract-cn-accounting/api/src/test/java/org/apache/fineract/cn/accounting/api/v1/domain/AccountTest.java | /*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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.apache.fineract.cn.accounting.api.v1.domain;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import org.apache.commons.lang3.RandomStringUtils;
import org.apache.fineract.cn.test.domain.ValidationTest;
import org.apache.fineract.cn.test.domain.ValidationTestCase;
import org.junit.runners.Parameterized;
/**
* @author Myrle Krantz
*/
public class AccountTest extends ValidationTest<Account> {
@Parameterized.Parameters
public static Collection testCases() {
final Collection<ValidationTestCase> ret = new ArrayList<>();
ret.add(new ValidationTestCase<Account>("valid")
.adjustment(x -> {})
.valid(true));
ret.add(new ValidationTestCase<Account>("nullBalance")
.adjustment(x -> x.setBalance(null))
.valid(false));
ret.add(new ValidationTestCase<Account>("nameTooLong")
.adjustment(x -> x.setName(RandomStringUtils.randomAlphanumeric(257)))
.valid(false));
ret.add(new ValidationTestCase<Account>("validState")
.adjustment(x -> x.setState("OPEN"))
.valid(true));
ret.add(new ValidationTestCase<Account>("validNullState")
.adjustment(x -> x.setState(null))
.valid(true));
return ret;
}
public AccountTest(final ValidationTestCase<Account> testCase) { super(testCase); }
protected Account createValidTestSubject() {
final Account ret = new Account();
ret.setBalance(0d);
ret.setName(RandomStringUtils.randomAlphanumeric(256));
ret.setIdentifier("validAccountIdentifier");
ret.setState(Account.State.OPEN.name());
ret.setType(AccountType.ASSET.name());
ret.setHolders(Collections.singleton("freddieMercury"));
ret.setLedger("validLedgerIdentifier");
ret.setReferenceAccount("validReferenceAccountIdentifier");
ret.setSignatureAuthorities(Collections.singleton("shesAKiller"));
return ret;
}
} | 4,757 |
0 | Create_ds/fineract-cn-accounting/api/src/test/java/org/apache/fineract/cn/accounting/api/v1 | Create_ds/fineract-cn-accounting/api/src/test/java/org/apache/fineract/cn/accounting/api/v1/domain/JournalEntryTest.java | /*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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.apache.fineract.cn.accounting.api.v1.domain;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashSet;
import java.util.Set;
import org.apache.commons.lang.RandomStringUtils;
import org.apache.fineract.cn.lang.DateConverter;
import org.apache.fineract.cn.test.domain.ValidationTest;
import org.apache.fineract.cn.test.domain.ValidationTestCase;
import org.junit.runners.Parameterized;
/**
* @author Myrle Krantz
*/
public class JournalEntryTest extends ValidationTest<JournalEntry> {
@Parameterized.Parameters
public static Collection testCases() {
final Collection<ValidationTestCase> ret = new ArrayList<>();
ret.add(new ValidationTestCase<JournalEntry>("valid"));
ret.add(new ValidationTestCase<JournalEntry>("invalidCreditor")
.adjustment(x -> x.getCreditors().add(new Creditor(null, "20.00")))
.valid(false));
ret.add(new ValidationTestCase<JournalEntry>("invalidDebtor")
.adjustment(x -> x.getDebtors().add(new Debtor(null, "20.00")))
.valid(false));
ret.add(new ValidationTestCase<JournalEntry>("invalidBalance")
.adjustment(x -> x.getDebtors().add(new Debtor("marvin", "-120.00")))
.valid(false));
ret.add(new ValidationTestCase<JournalEntry>("tooLongTransactionIdentifier")
.adjustment(x -> x.setTransactionIdentifier(RandomStringUtils.randomAlphanumeric(2201)))
.valid(false));
ret.add(new ValidationTestCase<JournalEntry>("tooLongTransactionType")
.adjustment(x -> x.setTransactionType(RandomStringUtils.randomAlphanumeric(33)))
.valid(false));
ret.add(new ValidationTestCase<JournalEntry>("tooLongMessage")
.adjustment(x -> x.setMessage(RandomStringUtils.randomAlphanumeric(2049)))
.valid(false));
ret.add(new ValidationTestCase<JournalEntry>("nullMessage")
.adjustment(x -> x.setMessage(null))
.valid(true));
return ret;
}
public JournalEntryTest(ValidationTestCase<JournalEntry> testCase) {
super(testCase);
}
@Override
protected JournalEntry createValidTestSubject() {
final JournalEntry ret = new JournalEntry();
final Set<Creditor> creditors = new HashSet<>();
creditors.add(new Creditor("beevis", "20.00"));
ret.setCreditors(creditors);
final Set<Debtor> debtors = new HashSet<>();
debtors.add(new Debtor("butthead", "20.00"));
ret.setDebtors(debtors);
ret.setClerk("Mike");
ret.setState(JournalEntry.State.PENDING.name());
ret.setNote("ha ha");
ret.setTransactionIdentifier("generated");
ret.setTransactionType("invented");
ret.setTransactionDate(DateConverter.toIsoString(LocalDateTime.now()));
return ret;
}
}
| 4,758 |
0 | Create_ds/fineract-cn-accounting/api/src/main/java/org/apache/fineract/cn/accounting/api | Create_ds/fineract-cn-accounting/api/src/main/java/org/apache/fineract/cn/accounting/api/v1/PermittableGroupIds.java | /*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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.apache.fineract.cn.accounting.api.v1;
@SuppressWarnings("unused")
public interface PermittableGroupIds {
String THOTH_LEDGER = "accounting__v1__ledger";
String THOTH_ACCOUNT = "accounting__v1__account";
String THOTH_JOURNAL = "accounting__v1__journal";
String THOTH_TX_TYPES = "accounting__v1__tx_types";
String THOTH_INCOME_STMT = "accounting__v1__income_stmt";
String THOTH_FIN_CONDITION = "accounting__v1__fin_condition";
}
| 4,759 |
0 | Create_ds/fineract-cn-accounting/api/src/main/java/org/apache/fineract/cn/accounting/api | Create_ds/fineract-cn-accounting/api/src/main/java/org/apache/fineract/cn/accounting/api/v1/EventConstants.java | /*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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.apache.fineract.cn.accounting.api.v1;
@SuppressWarnings({"unused"})
public interface EventConstants {
String DESTINATION = "accounting-v1";
String SELECTOR_NAME = "action";
// system events
String INITIALIZE = "initialize";
String SELECTOR_INITIALIZE = SELECTOR_NAME + " = '" + INITIALIZE + "'";
// ledger events
String POST_LEDGER = "post-ledger";
String PUT_LEDGER = "put-ledger";
String DELETE_LEDGER = "delete-ledger";
String POST_SUB_LEDGER = "post-sub-ledger";
String SELECTOR_POST_LEDGER = SELECTOR_NAME + " = '" + POST_LEDGER + "'";
String SELECTOR_PUT_LEDGER = SELECTOR_NAME + " = '" + PUT_LEDGER + "'";
String SELECTOR_DELETE_LEDGER = SELECTOR_NAME + " = '" + DELETE_LEDGER + "'";
String SELECTOR_POST_SUB_LEDGER = SELECTOR_NAME + " = '" + POST_SUB_LEDGER + "'";
// account events
String POST_ACCOUNT = "post-account";
String PUT_ACCOUNT = "put-account";
String DELETE_ACCOUNT = "delete-account";
String LOCK_ACCOUNT = "lock-account";
String UNLOCK_ACCOUNT = "unlock-account";
String CLOSE_ACCOUNT = "close-account";
String REOPEN_ACCOUNT = "reopen-account";
String SELECTOR_POST_ACCOUNT = SELECTOR_NAME + " = '" + POST_ACCOUNT + "'";
String SELECTOR_PUT_ACCOUNT = SELECTOR_NAME + " = '" + PUT_ACCOUNT + "'";
String SELECTOR_DELETE_ACCOUNT = SELECTOR_NAME + " = '" + DELETE_ACCOUNT + "'";
String SELECTOR_LOCK_ACCOUNT = SELECTOR_NAME + " = '" + LOCK_ACCOUNT + "'";
String SELECTOR_UNLOCK_ACCOUNT = SELECTOR_NAME + " = '" + UNLOCK_ACCOUNT + "'";
String SELECTOR_CLOSE_ACCOUNT = SELECTOR_NAME + " = '" + CLOSE_ACCOUNT + "'";
String SELECTOR_REOPEN_ACCOUNT = SELECTOR_NAME + " = '" + REOPEN_ACCOUNT + "'";
// journal events
String POST_JOURNAL_ENTRY = "post-journal-entry";
String RELEASE_JOURNAL_ENTRY = "release-journal-entry";
String SELECTOR_POST_JOURNAL_ENTRY = SELECTOR_NAME + " = '" + POST_JOURNAL_ENTRY + "'";
String SELECTOR_RELEASE_JOURNAL_ENTRY = SELECTOR_NAME + " = '" + RELEASE_JOURNAL_ENTRY + "'";
String POST_TX_TYPE = "post-tx-type";
String SELECTOR_POST_TX_TYPE = SELECTOR_NAME + " = '" + POST_TX_TYPE + "'";
String PUT_TX_TYPE = "put-tx-type";
String SELECTOR_PUT_TX_TYPE = SELECTOR_NAME + " = '" + PUT_TX_TYPE + "'";
}
| 4,760 |
0 | Create_ds/fineract-cn-accounting/api/src/main/java/org/apache/fineract/cn/accounting/api/v1 | Create_ds/fineract-cn-accounting/api/src/main/java/org/apache/fineract/cn/accounting/api/v1/domain/TransactionTypePage.java | /*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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.apache.fineract.cn.accounting.api.v1.domain;
import javax.validation.Valid;
import java.util.ArrayList;
import java.util.List;
@SuppressWarnings("unused")
public class TransactionTypePage {
@Valid
private List<TransactionType> transactionTypes;
private Integer totalPages;
private Long totalElements;
public TransactionTypePage() {
super();
}
public List<TransactionType> getTransactionTypes() {
return this.transactionTypes;
}
public void setTransactionTypes(final List<TransactionType> transactionTypes) {
this.transactionTypes = transactionTypes;
}
public Integer getTotalPages() {
return this.totalPages;
}
public void setTotalPages(final Integer totalPages) {
this.totalPages = totalPages;
}
public Long getTotalElements() {
return this.totalElements;
}
public void setTotalElements(final Long totalElements) {
this.totalElements = totalElements;
}
public void add(final TransactionType transactionType) {
if (this.transactionTypes == null) {
this.transactionTypes = new ArrayList<>();
}
this.transactionTypes.add(transactionType);
}
}
| 4,761 |
0 | Create_ds/fineract-cn-accounting/api/src/main/java/org/apache/fineract/cn/accounting/api/v1 | Create_ds/fineract-cn-accounting/api/src/main/java/org/apache/fineract/cn/accounting/api/v1/domain/Ledger.java | /*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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.apache.fineract.cn.accounting.api.v1.domain;
import java.math.BigDecimal;
import java.util.List;
import javax.validation.Valid;
import javax.validation.constraints.NotNull;
import org.apache.fineract.cn.lang.validation.constraints.ValidIdentifier;
import org.hibernate.validator.constraints.NotEmpty;
@SuppressWarnings({"unused"})
public final class Ledger {
@NotNull
private AccountType type;
@ValidIdentifier
private String identifier;
@NotEmpty
private String name;
private String description;
private String parentLedgerIdentifier;
@Valid
private List<Ledger> subLedgers;
private BigDecimal totalValue;
private String createdOn;
private String createdBy;
private String lastModifiedOn;
private String lastModifiedBy;
@NotNull
private Boolean showAccountsInChart;
public Ledger() {
super();
}
public String getType() {
return this.type.name();
}
public void setType(final String type) {
this.type = AccountType.valueOf(type);
}
public String getIdentifier() {
return this.identifier;
}
public void setIdentifier(final String identifier) {
this.identifier = identifier;
}
public String getName() {
return this.name;
}
public void setName(final String name) {
this.name = name;
}
public String getDescription() {
return this.description;
}
public String getParentLedgerIdentifier() {
return this.parentLedgerIdentifier;
}
public void setParentLedgerIdentifier(final String parentLedgerIdentifier) {
this.parentLedgerIdentifier = parentLedgerIdentifier;
}
public void setDescription(final String description) {
this.description = description;
}
public List<Ledger> getSubLedgers() {
return this.subLedgers;
}
public void setSubLedgers(final List<Ledger> subLedgers) {
this.subLedgers = subLedgers;
}
public BigDecimal getTotalValue() {
return this.totalValue;
}
public void setTotalValue(final BigDecimal totalValue) {
this.totalValue = totalValue;
}
public String getCreatedOn() {
return this.createdOn;
}
public void setCreatedOn(final String createdOn) {
this.createdOn = createdOn;
}
public String getCreatedBy() {
return this.createdBy;
}
public void setCreatedBy(final String createdBy) {
this.createdBy = createdBy;
}
public String getLastModifiedOn() {
return this.lastModifiedOn;
}
public void setLastModifiedOn(final String lastModifiedOn) {
this.lastModifiedOn = lastModifiedOn;
}
public String getLastModifiedBy() {
return this.lastModifiedBy;
}
public void setLastModifiedBy(final String lastModifiedBy) {
this.lastModifiedBy = lastModifiedBy;
}
public Boolean getShowAccountsInChart() {
return this.showAccountsInChart;
}
public void setShowAccountsInChart(final Boolean showAccountsInChart) {
this.showAccountsInChart = showAccountsInChart;
}
}
| 4,762 |
0 | Create_ds/fineract-cn-accounting/api/src/main/java/org/apache/fineract/cn/accounting/api/v1 | Create_ds/fineract-cn-accounting/api/src/main/java/org/apache/fineract/cn/accounting/api/v1/domain/AccountEntry.java | /*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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.apache.fineract.cn.accounting.api.v1.domain;
import java.util.Objects;
@SuppressWarnings({"unused", "WeakerAccess"})
public final class AccountEntry {
private Type type;
private String transactionDate;
private String message;
private Double amount;
private Double balance;
public String getType() {
return this.type.name();
}
public void setType(final String type) {
this.type = Type.valueOf(type);
}
public String getTransactionDate() {
return this.transactionDate;
}
public void setTransactionDate(final String transactionDate) {
this.transactionDate = transactionDate;
}
public String getMessage() {
return this.message;
}
public void setMessage(final String message) {
this.message = message;
}
public Double getAmount() {
return this.amount;
}
public void setAmount(final Double amount) {
this.amount = amount;
}
public Double getBalance() {
return this.balance;
}
public void setBalance(final Double balance) {
this.balance = balance;
}
public enum Type {
DEBIT,
CREDIT
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
AccountEntry that = (AccountEntry) o;
return type == that.type &&
Objects.equals(transactionDate, that.transactionDate) &&
Objects.equals(message, that.message) &&
Objects.equals(amount, that.amount) &&
Objects.equals(balance, that.balance);
}
@Override
public int hashCode() {
return Objects.hash(type, transactionDate, message, amount, balance);
}
}
| 4,763 |
0 | Create_ds/fineract-cn-accounting/api/src/main/java/org/apache/fineract/cn/accounting/api/v1 | Create_ds/fineract-cn-accounting/api/src/main/java/org/apache/fineract/cn/accounting/api/v1/domain/Debtor.java | /*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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.apache.fineract.cn.accounting.api.v1.domain;
import java.util.Objects;
import javax.validation.constraints.DecimalMin;
import javax.validation.constraints.NotNull;
import org.apache.fineract.cn.lang.validation.constraints.ValidIdentifier;
@SuppressWarnings({"unused", "WeakerAccess"})
public final class Debtor {
@ValidIdentifier(maxLength = 34)
private String accountNumber;
@NotNull
@DecimalMin(value = "0.00", inclusive = false)
private String amount;
public Debtor() {
super();
}
public Debtor(String accountNumber, String amount) {
this.accountNumber = accountNumber;
this.amount = amount;
}
public String getAccountNumber() {
return this.accountNumber;
}
public void setAccountNumber(final String accountNumber) {
this.accountNumber = accountNumber;
}
public String getAmount() {
return this.amount;
}
public void setAmount(final String amount) {
this.amount = amount;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
Debtor debtor = (Debtor) o;
return Objects.equals(accountNumber, debtor.accountNumber) &&
Objects.equals(amount, debtor.amount);
}
@Override
public int hashCode() {
return Objects.hash(accountNumber, amount);
}
@Override
public String toString() {
return "Debtor{" +
"accountNumber='" + accountNumber + '\'' +
", amount='" + amount + '\'' +
'}';
}
}
| 4,764 |
0 | Create_ds/fineract-cn-accounting/api/src/main/java/org/apache/fineract/cn/accounting/api/v1 | Create_ds/fineract-cn-accounting/api/src/main/java/org/apache/fineract/cn/accounting/api/v1/domain/LedgerPage.java | /*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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.apache.fineract.cn.accounting.api.v1.domain;
import java.util.List;
@SuppressWarnings("unused")
public class LedgerPage {
private List<Ledger> ledgers;
private Integer totalPages;
private Long totalElements;
public LedgerPage() {
super();
}
public List<Ledger> getLedgers() {
return ledgers;
}
public void setLedgers(List<Ledger> ledgers) {
this.ledgers = ledgers;
}
public Integer getTotalPages() {
return totalPages;
}
public void setTotalPages(Integer totalPages) {
this.totalPages = totalPages;
}
public Long getTotalElements() {
return totalElements;
}
public void setTotalElements(Long totalElements) {
this.totalElements = totalElements;
}
}
| 4,765 |
0 | Create_ds/fineract-cn-accounting/api/src/main/java/org/apache/fineract/cn/accounting/api/v1 | Create_ds/fineract-cn-accounting/api/src/main/java/org/apache/fineract/cn/accounting/api/v1/domain/Account.java | /*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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.apache.fineract.cn.accounting.api.v1.domain;
import java.util.Objects;
import java.util.Set;
import javax.validation.constraints.NotNull;
import org.apache.fineract.cn.lang.validation.constraints.ValidIdentifier;
import org.hibernate.validator.constraints.Length;
import org.hibernate.validator.constraints.NotEmpty;
@SuppressWarnings({"unused", "WeakerAccess"})
public final class Account {
private AccountType type;
@ValidIdentifier(maxLength = 34)
private String identifier;
@NotEmpty
@Length(max = 256)
private String name;
private Set<String> holders;
private Set<String> signatureAuthorities;
@NotNull
private Double balance;
private String referenceAccount;
@ValidIdentifier
private String ledger;
private State state;
private String alternativeAccountNumber;
private String createdOn;
private String createdBy;
private String lastModifiedOn;
private String lastModifiedBy;
public Account() {
super();
}
public String getType() {
return this.type.name();
}
public void setType(final String type) {
this.type = AccountType.valueOf(type);
}
public String getIdentifier() {
return this.identifier;
}
public void setIdentifier(final String identifier) {
this.identifier = identifier;
}
public String getName() {
return this.name;
}
public void setName(final String name) {
this.name = name;
}
public Set<String> getHolders() {
return this.holders;
}
public void setHolders(final Set<String> holders) {
this.holders = holders;
}
public Set<String> getSignatureAuthorities() {
return this.signatureAuthorities;
}
public void setSignatureAuthorities(final Set<String> signatureAuthorities) {
this.signatureAuthorities = signatureAuthorities;
}
public Double getBalance() {
return this.balance;
}
public void setBalance(final Double balance) {
this.balance = balance;
}
public String getReferenceAccount() {
return this.referenceAccount;
}
public void setReferenceAccount(final String referenceAccount) {
this.referenceAccount = referenceAccount;
}
public String getLedger() {
return this.ledger;
}
public void setLedger(final String ledger) {
this.ledger = ledger;
}
public String getState() {
return this.state.name();
}
public void setState(final String state) {
if (state == null)
this.state = null;
else
this.state = State.valueOf(state);
}
public String getAlternativeAccountNumber() {
return this.alternativeAccountNumber;
}
public void setAlternativeAccountNumber(final String alternativeAccountNumber) {
this.alternativeAccountNumber = alternativeAccountNumber;
}
public String getCreatedOn() {
return this.createdOn;
}
public void setCreatedOn(final String createdOn) {
this.createdOn = createdOn;
}
public String getCreatedBy() {
return this.createdBy;
}
public void setCreatedBy(final String createdBy) {
this.createdBy = createdBy;
}
public String getLastModifiedOn() {
return this.lastModifiedOn;
}
public void setLastModifiedOn(final String lastModifiedOn) {
this.lastModifiedOn = lastModifiedOn;
}
public String getLastModifiedBy() {
return this.lastModifiedBy;
}
public void setLastModifiedBy(final String lastModifiedBy) {
this.lastModifiedBy = lastModifiedBy;
}
@SuppressWarnings("WeakerAccess")
public enum State {
OPEN,
LOCKED,
CLOSED
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
Account account = (Account) o;
return type == account.type &&
Objects.equals(identifier, account.identifier) &&
Objects.equals(name, account.name) &&
Objects.equals(holders, account.holders) &&
Objects.equals(signatureAuthorities, account.signatureAuthorities) &&
Objects.equals(balance, account.balance) &&
Objects.equals(referenceAccount, account.referenceAccount) &&
Objects.equals(ledger, account.ledger) &&
state == account.state;
}
@Override
public int hashCode() {
return Objects.hash(type, identifier, name, holders, signatureAuthorities, balance, referenceAccount, ledger, state);
}
@Override
public String toString() {
return "Account{" +
"type=" + type +
", identifier='" + identifier + '\'' +
", name='" + name + '\'' +
", holders=" + holders +
", signatureAuthorities=" + signatureAuthorities +
", balance=" + balance +
", referenceAccount='" + referenceAccount + '\'' +
", ledger='" + ledger + '\'' +
", state=" + state +
", createdOn='" + createdOn + '\'' +
", createdBy='" + createdBy + '\'' +
", lastModifiedOn='" + lastModifiedOn + '\'' +
", lastModifiedBy='" + lastModifiedBy + '\'' +
'}';
}
}
| 4,766 |
0 | Create_ds/fineract-cn-accounting/api/src/main/java/org/apache/fineract/cn/accounting/api/v1 | Create_ds/fineract-cn-accounting/api/src/main/java/org/apache/fineract/cn/accounting/api/v1/domain/JournalEntryCommand.java | /*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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.apache.fineract.cn.accounting.api.v1.domain;
@SuppressWarnings({"unused"})
public final class JournalEntryCommand {
private Action action;
private String comment;
private String createdOn;
private String createdBy;
public JournalEntryCommand() {
super();
}
public String getAction() {
return this.action.name();
}
public void setAction(final String action) {
this.action = Action.valueOf(action);
}
public String getComment() {
return this.comment;
}
public void setComment(final String comment) {
this.comment = comment;
}
public String getCreatedOn() {
return this.createdOn;
}
public void setCreatedOn(final String createdOn) {
this.createdOn = createdOn;
}
public String getCreatedBy() {
return this.createdBy;
}
public void setCreatedBy(final String createdBy) {
this.createdBy = createdBy;
}
@SuppressWarnings("WeakerAccess")
public enum Action {
RELEASE
}
}
| 4,767 |
0 | Create_ds/fineract-cn-accounting/api/src/main/java/org/apache/fineract/cn/accounting/api/v1 | Create_ds/fineract-cn-accounting/api/src/main/java/org/apache/fineract/cn/accounting/api/v1/domain/AccountType.java | /*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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.apache.fineract.cn.accounting.api.v1.domain;
@SuppressWarnings({"unused"})
public enum AccountType {
ASSET,
LIABILITY,
EQUITY,
REVENUE,
EXPENSE
}
| 4,768 |
0 | Create_ds/fineract-cn-accounting/api/src/main/java/org/apache/fineract/cn/accounting/api/v1 | Create_ds/fineract-cn-accounting/api/src/main/java/org/apache/fineract/cn/accounting/api/v1/domain/JournalEntry.java | /*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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.apache.fineract.cn.accounting.api.v1.domain;
import java.util.Objects;
import java.util.Set;
import javax.validation.Valid;
import javax.validation.constraints.NotNull;
import org.apache.fineract.cn.lang.validation.constraints.ValidIdentifier;
import org.hibernate.validator.constraints.Length;
import org.hibernate.validator.constraints.NotEmpty;
@SuppressWarnings({"unused", "WeakerAccess"})
public final class JournalEntry {
//This maxLength is the maximum message length plus a buffer. portfolio places
// the message here, plus the service name, and a random suffix. This makes
// it possible to match the transaction id on activemq messages used in integration
// tests.
@ValidIdentifier(maxLength = 2200)
private String transactionIdentifier;
@NotNull
private String transactionDate;
@ValidIdentifier
private String transactionType;
@NotEmpty
private String clerk;
private String note;
@NotNull
@Valid
private Set<Debtor> debtors;
@NotNull
@Valid
private Set<Creditor> creditors;
private State state;
@Length(max=2048)
private String message;
public JournalEntry() {
super();
}
public String getTransactionIdentifier() {
return this.transactionIdentifier;
}
public void setTransactionIdentifier(final String transactionIdentifier) {
this.transactionIdentifier = transactionIdentifier;
}
public String getTransactionDate() {
return this.transactionDate;
}
public void setTransactionDate(final String transactionDate) {
this.transactionDate = transactionDate;
}
public String getTransactionType() {
return this.transactionType;
}
public void setTransactionType(final String transactionType) {
this.transactionType = transactionType;
}
public String getClerk() {
return this.clerk;
}
public void setClerk(final String clerk) {
this.clerk = clerk;
}
public String getNote() {
return this.note;
}
public void setNote(final String note) {
this.note = note;
}
public Set<Debtor> getDebtors() {
return this.debtors;
}
public void setDebtors(final Set<Debtor> debtors) {
this.debtors = debtors;
}
public Set<Creditor> getCreditors() {
return this.creditors;
}
public void setCreditors(final Set<Creditor> creditors) {
this.creditors = creditors;
}
public String getState() {
return this.state.name();
}
public void setState(final String state) {
this.state = State.valueOf(state);
}
public String getMessage() {
return this.message;
}
public void setMessage(final String message) {
this.message = message;
}
@SuppressWarnings("WeakerAccess")
public enum State {
PENDING,
PROCESSED
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
JournalEntry that = (JournalEntry) o;
return Objects.equals(transactionIdentifier, that.transactionIdentifier) &&
Objects.equals(transactionDate, that.transactionDate) &&
Objects.equals(transactionType, that.transactionType) &&
Objects.equals(clerk, that.clerk) &&
Objects.equals(note, that.note) &&
Objects.equals(debtors, that.debtors) &&
Objects.equals(creditors, that.creditors) &&
state == that.state &&
Objects.equals(message, that.message);
}
@Override
public int hashCode() {
return Objects.hash(transactionIdentifier, transactionDate, transactionType, clerk, note, debtors, creditors, state, message);
}
@Override
public String toString() {
return "JournalEntry{" +
"transactionIdentifier='" + transactionIdentifier + '\'' +
", transactionDate='" + transactionDate + '\'' +
", transactionType='" + transactionType + '\'' +
", clerk='" + clerk + '\'' +
", note='" + note + '\'' +
", debtors=" + debtors +
", creditors=" + creditors +
", state=" + state +
", message='" + message + '\'' +
'}';
}
}
| 4,769 |
0 | Create_ds/fineract-cn-accounting/api/src/main/java/org/apache/fineract/cn/accounting/api/v1 | Create_ds/fineract-cn-accounting/api/src/main/java/org/apache/fineract/cn/accounting/api/v1/domain/Creditor.java | /*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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.apache.fineract.cn.accounting.api.v1.domain;
import java.util.Objects;
import javax.validation.constraints.DecimalMin;
import javax.validation.constraints.NotNull;
import org.apache.fineract.cn.lang.validation.constraints.ValidIdentifier;
@SuppressWarnings({"unused", "WeakerAccess"})
public final class Creditor {
@ValidIdentifier(maxLength = 34)
private String accountNumber;
@NotNull
@DecimalMin(value = "0.00", inclusive = false)
private String amount;
public Creditor() {
super();
}
public Creditor(String accountNumber, String amount) {
this.accountNumber = accountNumber;
this.amount = amount;
}
public String getAccountNumber() {
return this.accountNumber;
}
public void setAccountNumber(final String accountNumber) {
this.accountNumber = accountNumber;
}
public String getAmount() {
return this.amount;
}
public void setAmount(final String amount) {
this.amount = amount;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
Creditor creditor = (Creditor) o;
return Objects.equals(accountNumber, creditor.accountNumber) &&
Objects.equals(amount, creditor.amount);
}
@Override
public int hashCode() {
return Objects.hash(accountNumber, amount);
}
@Override
public String toString() {
return "Creditor{" +
"accountNumber='" + accountNumber + '\'' +
", amount='" + amount + '\'' +
'}';
}
}
| 4,770 |
0 | Create_ds/fineract-cn-accounting/api/src/main/java/org/apache/fineract/cn/accounting/api/v1 | Create_ds/fineract-cn-accounting/api/src/main/java/org/apache/fineract/cn/accounting/api/v1/domain/AccountPage.java | /*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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.apache.fineract.cn.accounting.api.v1.domain;
import java.util.List;
@SuppressWarnings("unused")
public class AccountPage {
private List<Account> accounts;
private Integer totalPages;
private Long totalElements;
public AccountPage() {
super();
}
public List<Account> getAccounts() {
return accounts;
}
public void setAccounts(List<Account> accounts) {
this.accounts = accounts;
}
public Integer getTotalPages() {
return totalPages;
}
public void setTotalPages(Integer totalPages) {
this.totalPages = totalPages;
}
public Long getTotalElements() {
return totalElements;
}
public void setTotalElements(Long totalElements) {
this.totalElements = totalElements;
}
}
| 4,771 |
0 | Create_ds/fineract-cn-accounting/api/src/main/java/org/apache/fineract/cn/accounting/api/v1 | Create_ds/fineract-cn-accounting/api/src/main/java/org/apache/fineract/cn/accounting/api/v1/domain/TransactionType.java | /*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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.apache.fineract.cn.accounting.api.v1.domain;
import org.apache.fineract.cn.lang.validation.constraints.ValidIdentifier;
import org.hibernate.validator.constraints.NotEmpty;
public class TransactionType {
@ValidIdentifier
private String code;
@NotEmpty
private String name;
private String description;
public TransactionType() {
super();
}
public String getCode() {
return this.code;
}
public void setCode(final String code) {
this.code = code;
}
public String getName() {
return this.name;
}
public void setName(final String name) {
this.name = name;
}
public String getDescription() {
return this.description;
}
public void setDescription(final String description) {
this.description = description;
}
}
| 4,772 |
0 | Create_ds/fineract-cn-accounting/api/src/main/java/org/apache/fineract/cn/accounting/api/v1 | Create_ds/fineract-cn-accounting/api/src/main/java/org/apache/fineract/cn/accounting/api/v1/domain/ChartOfAccountEntry.java | /*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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.apache.fineract.cn.accounting.api.v1.domain;
@SuppressWarnings("unused")
public class ChartOfAccountEntry {
private String code;
private String name;
private String description;
private String type;
private Integer level;
public ChartOfAccountEntry() {
super();
}
public String getCode() {
return this.code;
}
public void setCode(final String code) {
this.code = code;
}
public String getName() {
return this.name;
}
public void setName(final String name) {
this.name = name;
}
public String getDescription() {
return this.description;
}
public void setDescription(final String description) {
this.description = description;
}
public String getType() {
return this.type;
}
public void setType(final String type) {
this.type = type;
}
public Integer getLevel() {
return this.level;
}
public void setLevel(final Integer level) {
this.level = level;
}
}
| 4,773 |
0 | Create_ds/fineract-cn-accounting/api/src/main/java/org/apache/fineract/cn/accounting/api/v1 | Create_ds/fineract-cn-accounting/api/src/main/java/org/apache/fineract/cn/accounting/api/v1/domain/AccountEntryPage.java | /*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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.apache.fineract.cn.accounting.api.v1.domain;
import java.util.List;
@SuppressWarnings("unused")
public class AccountEntryPage {
private List<AccountEntry> accountEntries;
private Integer totalPages;
private Long totalElements;
public AccountEntryPage() {
super();
}
public List<AccountEntry> getAccountEntries() {
return accountEntries;
}
public void setAccountEntries(List<AccountEntry> accountEntries) {
this.accountEntries = accountEntries;
}
public Integer getTotalPages() {
return totalPages;
}
public void setTotalPages(Integer totalPages) {
this.totalPages = totalPages;
}
public Long getTotalElements() {
return totalElements;
}
public void setTotalElements(Long totalElements) {
this.totalElements = totalElements;
}
}
| 4,774 |
0 | Create_ds/fineract-cn-accounting/api/src/main/java/org/apache/fineract/cn/accounting/api/v1 | Create_ds/fineract-cn-accounting/api/src/main/java/org/apache/fineract/cn/accounting/api/v1/domain/AccountCommand.java | /*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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.apache.fineract.cn.accounting.api.v1.domain;
import javax.validation.constraints.NotNull;
@SuppressWarnings({"unused"})
public final class AccountCommand {
@NotNull
private Action action;
private String comment;
private String createdOn;
private String createdBy;
public AccountCommand() {
super();
}
public String getAction() {
return this.action.name();
}
public void setAction(final String action) {
this.action = Action.valueOf(action);
}
public String getComment() {
return this.comment;
}
public void setComment(final String comment) {
this.comment = comment;
}
public String getCreatedOn() {
return this.createdOn;
}
public void setCreatedOn(final String createdOn) {
this.createdOn = createdOn;
}
public String getCreatedBy() {
return this.createdBy;
}
public void setCreatedBy(final String createdBy) {
this.createdBy = createdBy;
}
@SuppressWarnings("WeakerAccess")
public enum Action {
LOCK,
UNLOCK,
CLOSE,
REOPEN
}
}
| 4,775 |
0 | Create_ds/fineract-cn-accounting/api/src/main/java/org/apache/fineract/cn/accounting/api/v1/domain/financial | Create_ds/fineract-cn-accounting/api/src/main/java/org/apache/fineract/cn/accounting/api/v1/domain/financial/statement/FinancialConditionSection.java | /*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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.apache.fineract.cn.accounting.api.v1.domain.financial.statement;
import org.hibernate.validator.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;
public class FinancialConditionSection {
public enum Type {
ASSET,
EQUITY,
LIABILITY
}
@NotEmpty
private Type type;
@NotEmpty
private String description;
@NotEmpty
private List<FinancialConditionEntry> financialConditionEntries = new ArrayList<>();
@NotNull
private BigDecimal subtotal = BigDecimal.ZERO;
public FinancialConditionSection() {
super();
}
public String getType() {
return this.type.name();
}
public void setType(final String type) {
this.type = Type.valueOf(type);
}
public String getDescription() {
return this.description;
}
public void setDescription(final String description) {
this.description = description;
}
public List<FinancialConditionEntry> getFinancialConditionEntries() {
return this.financialConditionEntries;
}
public BigDecimal getSubtotal() {
return this.subtotal;
}
public void add(final FinancialConditionEntry financialConditionEntry) {
this.financialConditionEntries.add(financialConditionEntry);
this.subtotal = this.subtotal.add(financialConditionEntry.getValue());
}
}
| 4,776 |
0 | Create_ds/fineract-cn-accounting/api/src/main/java/org/apache/fineract/cn/accounting/api/v1/domain/financial | Create_ds/fineract-cn-accounting/api/src/main/java/org/apache/fineract/cn/accounting/api/v1/domain/financial/statement/IncomeStatementEntry.java | /*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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.apache.fineract.cn.accounting.api.v1.domain.financial.statement;
import org.hibernate.validator.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import java.math.BigDecimal;
public class IncomeStatementEntry {
@NotEmpty
private String description;
@NotNull
private BigDecimal value;
public IncomeStatementEntry() {
super();
}
public String getDescription() {
return this.description;
}
public void setDescription(final String description) {
this.description = description;
}
public BigDecimal getValue() {
return this.value;
}
public void setValue(final BigDecimal value) {
this.value = value;
}
}
| 4,777 |
0 | Create_ds/fineract-cn-accounting/api/src/main/java/org/apache/fineract/cn/accounting/api/v1/domain/financial | Create_ds/fineract-cn-accounting/api/src/main/java/org/apache/fineract/cn/accounting/api/v1/domain/financial/statement/FinancialConditionEntry.java | /*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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.apache.fineract.cn.accounting.api.v1.domain.financial.statement;
import org.hibernate.validator.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import java.math.BigDecimal;
public class FinancialConditionEntry {
@NotEmpty
private String description;
@NotNull
private BigDecimal value;
public FinancialConditionEntry() {
super();
}
public String getDescription() {
return this.description;
}
public void setDescription(final String description) {
this.description = description;
}
public BigDecimal getValue() {
return this.value;
}
public void setValue(final BigDecimal value) {
this.value = value;
}
}
| 4,778 |
0 | Create_ds/fineract-cn-accounting/api/src/main/java/org/apache/fineract/cn/accounting/api/v1/domain/financial | Create_ds/fineract-cn-accounting/api/src/main/java/org/apache/fineract/cn/accounting/api/v1/domain/financial/statement/IncomeStatement.java | /*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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.apache.fineract.cn.accounting.api.v1.domain.financial.statement;
import org.hibernate.validator.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;
public class IncomeStatement {
@NotEmpty
private String date;
@NotEmpty
private List<IncomeStatementSection> incomeStatementSections = new ArrayList<>();
@NotNull
private BigDecimal grossProfit;
@NotNull
private BigDecimal totalExpenses;
@NotNull
private BigDecimal netIncome;
public IncomeStatement() {
super();
}
public String getDate() {
return this.date;
}
public void setDate(final String date) {
this.date = date;
}
public List<IncomeStatementSection> getIncomeStatementSections() {
return this.incomeStatementSections;
}
public BigDecimal getGrossProfit() {
return this.grossProfit;
}
public void setGrossProfit(final BigDecimal grossProfit) {
this.grossProfit = grossProfit;
}
public BigDecimal getTotalExpenses() {
return this.totalExpenses;
}
public void setTotalExpenses(final BigDecimal totalExpenses) {
this.totalExpenses = totalExpenses;
}
public BigDecimal getNetIncome() {
return this.netIncome;
}
public void setNetIncome(final BigDecimal netIncome) {
this.netIncome = netIncome;
}
public void add(final IncomeStatementSection incomeStatementSection) {
this.incomeStatementSections.add(incomeStatementSection);
}
}
| 4,779 |
0 | Create_ds/fineract-cn-accounting/api/src/main/java/org/apache/fineract/cn/accounting/api/v1/domain/financial | Create_ds/fineract-cn-accounting/api/src/main/java/org/apache/fineract/cn/accounting/api/v1/domain/financial/statement/TrialBalance.java | /*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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.apache.fineract.cn.accounting.api.v1.domain.financial.statement;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;
@SuppressWarnings("unused")
public class TrialBalance {
private List<TrialBalanceEntry> trialBalanceEntries;
private BigDecimal debitTotal;
private BigDecimal creditTotal;
public TrialBalance() {
super();
}
public List<TrialBalanceEntry> getTrialBalanceEntries() {
if (this.trialBalanceEntries == null) {
this.trialBalanceEntries = new ArrayList<>();
}
return this.trialBalanceEntries;
}
public void setTrialBalanceEntries(final List<TrialBalanceEntry> trialBalanceEntries) {
this.trialBalanceEntries = trialBalanceEntries;
}
public BigDecimal getDebitTotal() {
return this.debitTotal;
}
public void setDebitTotal(final BigDecimal debitTotal) {
this.debitTotal = debitTotal;
}
public BigDecimal getCreditTotal() {
return this.creditTotal;
}
public void setCreditTotal(final BigDecimal creditTotal) {
this.creditTotal = creditTotal;
}
}
| 4,780 |
0 | Create_ds/fineract-cn-accounting/api/src/main/java/org/apache/fineract/cn/accounting/api/v1/domain/financial | Create_ds/fineract-cn-accounting/api/src/main/java/org/apache/fineract/cn/accounting/api/v1/domain/financial/statement/FinancialCondition.java | /*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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.apache.fineract.cn.accounting.api.v1.domain.financial.statement;
import org.hibernate.validator.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;
public class FinancialCondition {
@NotEmpty
private String date;
@NotEmpty
private List<FinancialConditionSection> financialConditionSections = new ArrayList<>();
@NotNull
private BigDecimal totalAssets;
@NotNull
private BigDecimal totalEquitiesAndLiabilities;
public FinancialCondition() {
super();
}
public String getDate() {
return this.date;
}
public void setDate(final String date) {
this.date = date;
}
public List<FinancialConditionSection> getFinancialConditionSections() {
return this.financialConditionSections;
}
public BigDecimal getTotalAssets() {
return this.totalAssets;
}
public void setTotalAssets(final BigDecimal totalAssets) {
this.totalAssets = totalAssets;
}
public BigDecimal getTotalEquitiesAndLiabilities() {
return this.totalEquitiesAndLiabilities;
}
public void setTotalEquitiesAndLiabilities(final BigDecimal totalEquitiesAndLiabilities) {
this.totalEquitiesAndLiabilities = totalEquitiesAndLiabilities;
}
public void add(final FinancialConditionSection financialConditionSection) {
this.financialConditionSections.add(financialConditionSection);
}
}
| 4,781 |
0 | Create_ds/fineract-cn-accounting/api/src/main/java/org/apache/fineract/cn/accounting/api/v1/domain/financial | Create_ds/fineract-cn-accounting/api/src/main/java/org/apache/fineract/cn/accounting/api/v1/domain/financial/statement/IncomeStatementSection.java | /*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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.apache.fineract.cn.accounting.api.v1.domain.financial.statement;
import org.hibernate.validator.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;
public class IncomeStatementSection {
public enum Type {
INCOME,
EXPENSES
}
@NotEmpty
private Type type;
@NotEmpty
private String description;
@NotEmpty
private List<IncomeStatementEntry> incomeStatementEntries = new ArrayList<>();
@NotNull
private BigDecimal subtotal = BigDecimal.ZERO;
public IncomeStatementSection() {
super();
}
public String getType() {
return this.type.name();
}
public void setType(final String type) {
this.type = Type.valueOf(type);
}
public String getDescription() {
return this.description;
}
public void setDescription(final String description) {
this.description = description;
}
public List<IncomeStatementEntry> getIncomeStatementEntries() {
return this.incomeStatementEntries;
}
public BigDecimal getSubtotal() {
return this.subtotal;
}
public void add(final IncomeStatementEntry incomeStatementEntry) {
this.incomeStatementEntries.add(incomeStatementEntry);
this.subtotal = this.subtotal.add(incomeStatementEntry.getValue());
}
}
| 4,782 |
0 | Create_ds/fineract-cn-accounting/api/src/main/java/org/apache/fineract/cn/accounting/api/v1/domain/financial | Create_ds/fineract-cn-accounting/api/src/main/java/org/apache/fineract/cn/accounting/api/v1/domain/financial/statement/TrialBalanceEntry.java | /*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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.apache.fineract.cn.accounting.api.v1.domain.financial.statement;
import org.apache.fineract.cn.accounting.api.v1.domain.Ledger;
import java.math.BigDecimal;
@SuppressWarnings("WeakerAccess")
public class TrialBalanceEntry {
private Ledger ledger;
private Type type;
private BigDecimal amount;
public TrialBalanceEntry() {
super();
}
public Ledger getLedger() {
return this.ledger;
}
public void setLedger(final Ledger ledger) {
this.ledger = ledger;
}
public String getType() {
return this.type.name();
}
public void setType(final String type) {
this.type = Type.valueOf(type);
}
public BigDecimal getAmount() {
return this.amount;
}
public void setAmount(final BigDecimal amount) {
this.amount = amount;
}
public enum Type {
DEBIT,
CREDIT
}
}
| 4,783 |
0 | Create_ds/fineract-cn-accounting/api/src/main/java/org/apache/fineract/cn/accounting/api/v1 | Create_ds/fineract-cn-accounting/api/src/main/java/org/apache/fineract/cn/accounting/api/v1/client/LedgerAlreadyExistsException.java | /*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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.apache.fineract.cn.accounting.api.v1.client;
@SuppressWarnings("WeakerAccess")
public final class LedgerAlreadyExistsException extends RuntimeException {
}
| 4,784 |
0 | Create_ds/fineract-cn-accounting/api/src/main/java/org/apache/fineract/cn/accounting/api/v1 | Create_ds/fineract-cn-accounting/api/src/main/java/org/apache/fineract/cn/accounting/api/v1/client/TransactionTypeNotFoundException.java | /*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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.apache.fineract.cn.accounting.api.v1.client;
public class TransactionTypeNotFoundException extends RuntimeException {
}
| 4,785 |
0 | Create_ds/fineract-cn-accounting/api/src/main/java/org/apache/fineract/cn/accounting/api/v1 | Create_ds/fineract-cn-accounting/api/src/main/java/org/apache/fineract/cn/accounting/api/v1/client/TransactionTypeAlreadyExists.java | /*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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.apache.fineract.cn.accounting.api.v1.client;
public class TransactionTypeAlreadyExists extends RuntimeException {
}
| 4,786 |
0 | Create_ds/fineract-cn-accounting/api/src/main/java/org/apache/fineract/cn/accounting/api/v1 | Create_ds/fineract-cn-accounting/api/src/main/java/org/apache/fineract/cn/accounting/api/v1/client/LedgerReferenceExistsException.java | /*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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.apache.fineract.cn.accounting.api.v1.client;
@SuppressWarnings("WeakerAccess")
public final class LedgerReferenceExistsException extends RuntimeException {
}
| 4,787 |
0 | Create_ds/fineract-cn-accounting/api/src/main/java/org/apache/fineract/cn/accounting/api/v1 | Create_ds/fineract-cn-accounting/api/src/main/java/org/apache/fineract/cn/accounting/api/v1/client/JournalEntryValidationException.java | /*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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.apache.fineract.cn.accounting.api.v1.client;
@SuppressWarnings("WeakerAccess")
public final class JournalEntryValidationException extends RuntimeException {
}
| 4,788 |
0 | Create_ds/fineract-cn-accounting/api/src/main/java/org/apache/fineract/cn/accounting/api/v1 | Create_ds/fineract-cn-accounting/api/src/main/java/org/apache/fineract/cn/accounting/api/v1/client/AccountReferenceException.java | /*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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.apache.fineract.cn.accounting.api.v1.client;
@SuppressWarnings("WeakerAccess")
public class AccountReferenceException extends RuntimeException {
}
| 4,789 |
0 | Create_ds/fineract-cn-accounting/api/src/main/java/org/apache/fineract/cn/accounting/api/v1 | Create_ds/fineract-cn-accounting/api/src/main/java/org/apache/fineract/cn/accounting/api/v1/client/LedgerManager.java | /*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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.apache.fineract.cn.accounting.api.v1.client;
import org.apache.fineract.cn.accounting.api.v1.domain.Account;
import org.apache.fineract.cn.accounting.api.v1.domain.AccountCommand;
import org.apache.fineract.cn.accounting.api.v1.domain.AccountEntry;
import org.apache.fineract.cn.accounting.api.v1.domain.AccountEntryPage;
import org.apache.fineract.cn.accounting.api.v1.domain.AccountPage;
import org.apache.fineract.cn.accounting.api.v1.domain.ChartOfAccountEntry;
import org.apache.fineract.cn.accounting.api.v1.domain.JournalEntry;
import org.apache.fineract.cn.accounting.api.v1.domain.Ledger;
import org.apache.fineract.cn.accounting.api.v1.domain.LedgerPage;
import org.apache.fineract.cn.accounting.api.v1.domain.TransactionType;
import org.apache.fineract.cn.accounting.api.v1.domain.TransactionTypePage;
import org.apache.fineract.cn.accounting.api.v1.domain.financial.statement.FinancialCondition;
import org.apache.fineract.cn.accounting.api.v1.domain.financial.statement.IncomeStatement;
import org.apache.fineract.cn.accounting.api.v1.domain.financial.statement.TrialBalance;
import java.math.BigDecimal;
import java.util.Collections;
import java.util.List;
import java.util.stream.Stream;
import javax.validation.Valid;
import org.apache.fineract.cn.api.annotation.ThrowsException;
import org.apache.fineract.cn.api.annotation.ThrowsExceptions;
import org.apache.fineract.cn.api.util.CustomFeignClientsConfiguration;
import org.springframework.cloud.netflix.feign.FeignClient;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
@SuppressWarnings("unused")
@FeignClient(value = "${kubernetes.accounting.service.name}", path = "/accounting/v1", url = "http://${kubernetes.accounting.service.name}:${kubernetes.accounting.server.port}", configuration = CustomFeignClientsConfiguration.class)
public interface LedgerManager {
@RequestMapping(
value = "/ledgers",
method = RequestMethod.POST,
produces = {MediaType.APPLICATION_JSON_VALUE},
consumes = {MediaType.APPLICATION_JSON_VALUE}
)
@ThrowsExceptions({
@ThrowsException(status = HttpStatus.CONFLICT, exception = LedgerAlreadyExistsException.class)
})
void createLedger(@RequestBody final Ledger ledger);
@RequestMapping(
value = "/ledgers",
method = RequestMethod.GET,
produces = {MediaType.ALL_VALUE},
consumes = {MediaType.APPLICATION_JSON_VALUE}
)
LedgerPage fetchLedgers(@RequestParam(value = "includeSubLedgers", required = false, defaultValue = "false") final boolean includeSubLedgers,
@RequestParam(value = "term", required = false) final String term,
@RequestParam(value = "type", required = false) final String type,
@RequestParam(value = "pageIndex", required = false) final Integer pageIndex,
@RequestParam(value = "size", required = false) final Integer size,
@RequestParam(value = "sortColumn", required = false) final String sortColumn,
@RequestParam(value = "sortDirection", required = false) final String sortDirection);
@RequestMapping(
value = "/ledgers/{identifier}",
method = RequestMethod.GET,
produces = {MediaType.ALL_VALUE},
consumes = {MediaType.APPLICATION_JSON_VALUE}
)
@ThrowsException(status = HttpStatus.NOT_FOUND, exception = LedgerNotFoundException.class)
Ledger findLedger(@PathVariable("identifier") final String identifier);
@RequestMapping(
value = "/ledgers/{identifier}",
method = RequestMethod.POST,
produces = {MediaType.APPLICATION_JSON_VALUE},
consumes = {MediaType.APPLICATION_JSON_VALUE}
)
@ThrowsExceptions({
@ThrowsException(status = HttpStatus.NOT_FOUND, exception = LedgerNotFoundException.class),
@ThrowsException(status = HttpStatus.CONFLICT, exception = LedgerAlreadyExistsException.class)
})
void addSubLedger(@PathVariable("identifier") final String identifier, @RequestBody final Ledger subLedger);
@RequestMapping(
value = "/ledgers/{identifier}",
method = RequestMethod.PUT,
produces = {MediaType.APPLICATION_JSON_VALUE},
consumes = {MediaType.APPLICATION_JSON_VALUE}
)
@ThrowsExceptions({
@ThrowsException(status = HttpStatus.NOT_FOUND, exception = LedgerNotFoundException.class)
})
void modifyLedger(@PathVariable("identifier") final String identifier, @RequestBody final Ledger subLedger);
@RequestMapping(
value = "/ledgers/{identifier}",
method = RequestMethod.DELETE,
produces = {MediaType.ALL_VALUE},
consumes = {MediaType.APPLICATION_JSON_VALUE}
)
@ThrowsExceptions({
@ThrowsException(status = HttpStatus.NOT_FOUND, exception = LedgerNotFoundException.class),
@ThrowsException(status = HttpStatus.CONFLICT, exception = LedgerReferenceExistsException.class)
})
void deleteLedger(@PathVariable("identifier") final String identifier);
@RequestMapping(
value = "/ledgers/{identifier}/accounts",
method = RequestMethod.GET,
produces = {MediaType.ALL_VALUE},
consumes = {MediaType.APPLICATION_JSON_VALUE}
)
@ThrowsException(status = HttpStatus.NOT_FOUND, exception = LedgerNotFoundException.class)
AccountPage fetchAccountsOfLedger(@PathVariable("identifier") final String identifier,
@RequestParam(value = "pageIndex", required = false) final Integer pageIndex,
@RequestParam(value = "size", required = false) final Integer size,
@RequestParam(value = "sortColumn", required = false) final String sortColumn,
@RequestParam(value = "sortDirection", required = false) final String sortDirection);
@RequestMapping(
value = "/accounts",
method = RequestMethod.POST,
produces = {MediaType.APPLICATION_JSON_VALUE},
consumes = {MediaType.APPLICATION_JSON_VALUE}
)
@ThrowsExceptions({
@ThrowsException(status = HttpStatus.CONFLICT, exception = AccountAlreadyExistsException.class)
})
void createAccount(@RequestBody final Account account);
@RequestMapping(
value = "/accounts",
method = RequestMethod.GET,
produces = {MediaType.ALL_VALUE},
consumes = {MediaType.APPLICATION_JSON_VALUE}
)
AccountPage fetchAccounts(@RequestParam(value = "includeClosed", required = false, defaultValue = "false") final boolean includeClosed,
@RequestParam(value = "term", required = false) final String term,
@RequestParam(value = "type", required = false) final String type,
@RequestParam(value = "includeCustomerAccounts", required = false, defaultValue = "false") final boolean includeCustomerAccounts,
@RequestParam(value = "pageIndex", required = false) final Integer pageIndex,
@RequestParam(value = "size", required = false) final Integer size,
@RequestParam(value = "sortColumn", required = false) final String sortColumn,
@RequestParam(value = "sortDirection", required = false) final String sortDirection);
@RequestMapping(
value = "/accounts/{identifier}",
method = RequestMethod.GET,
produces = {MediaType.ALL_VALUE},
consumes = {MediaType.APPLICATION_JSON_VALUE}
)
@ThrowsException(status = HttpStatus.NOT_FOUND, exception = AccountNotFoundException.class)
Account findAccount(@PathVariable("identifier") final String identifier);
@RequestMapping(
value = "/accounts/{identifier}",
method = RequestMethod.PUT,
produces = {MediaType.APPLICATION_JSON_VALUE},
consumes = {MediaType.APPLICATION_JSON_VALUE}
)
@ThrowsExceptions({
@ThrowsException(status = HttpStatus.NOT_FOUND, exception = AccountNotFoundException.class)
})
void modifyAccount(@PathVariable("identifier") final String identifier,
@RequestBody final Account account);
@RequestMapping(
value = "/accounts/{identifier}",
method = RequestMethod.DELETE,
produces = {MediaType.ALL_VALUE},
consumes = {MediaType.APPLICATION_JSON_VALUE}
)
@ThrowsExceptions({
@ThrowsException(status = HttpStatus.NOT_FOUND, exception = AccountNotFoundException.class),
@ThrowsException(status = HttpStatus.CONFLICT, exception = AccountReferenceException.class)
})
void deleteAccount(@PathVariable("identifier") final String identifier);
@RequestMapping(
value = "/accounts/{identifier}/entries",
method = RequestMethod.GET,
produces = {MediaType.ALL_VALUE},
consumes = {MediaType.APPLICATION_JSON_VALUE}
)
@ThrowsException(status = HttpStatus.NOT_FOUND, exception = AccountNotFoundException.class)
AccountEntryPage fetchAccountEntries(@PathVariable("identifier") final String identifier,
@RequestParam(value = "dateRange", required = false) final String dateRange,
@RequestParam(value = "message", required = false) final String message,
@RequestParam(value = "pageIndex", required = false) final Integer pageIndex,
@RequestParam(value = "size", required = false) final Integer size,
@RequestParam(value = "sortColumn", required = false) final String sortColumn,
@RequestParam(value = "sortDirection", required = false) final String sortDirection);
// These helper functions are implemented here rather than in the client because it is easier to test
// and mock if it's part of the accounting interface, rather than part of the client calling it.
default Stream<Account> streamAccountsOfLedger(
final String ledgerIdentifer,
final String sortDirection) {
final AccountPage firstPage = this.fetchAccountsOfLedger(
ledgerIdentifer,
0,
10,
null,
null);
final Integer pageCount = firstPage.getTotalPages();
switch (sortDirection) {
case "ASC":
// Sort column is always date and order always ascending so that the order and adjacency of account
// entries is always stable. This has the advantage that the set of account entries included in the
// stream is set the moment the first call to fetchAccountEntries (above) is made.
return Stream.iterate(0, (i) -> i + 1).limit(pageCount)
.map(i -> this.fetchAccountsOfLedger(ledgerIdentifer, i, 10, "lastModifiedOn", "ASC"))
.flatMap(pageI -> pageI.getAccounts().stream());
case "DESC":
return Stream.iterate(pageCount - 1, (i) -> i - 1).limit(pageCount)
.map(i -> this.fetchAccountsOfLedger(ledgerIdentifer, i, 10, "lastModifiedOn", "DESC"))
.flatMap(pageI -> {
Collections.reverse(pageI.getAccounts());
return pageI.getAccounts().stream();
});
default:
throw new IllegalArgumentException();
}
}
default Stream<AccountEntry> fetchAccountEntriesStream(
final String accountIdentifier,
final String dateRange,
final String message,
final String sortDirection) {
final AccountEntryPage firstPage = this.fetchAccountEntries(
accountIdentifier,
dateRange,
message,
0,
10,
null,
null);
final Integer pageCount = firstPage.getTotalPages();
switch (sortDirection) {
case "ASC":
// Sort column is always date and order always ascending so that the order and adjacency of account
// entries is always stable. This has the advantage that the set of account entries included in the
// stream is set the moment the first call to fetchAccountEntries (above) is made.
return Stream.iterate(0, (i) -> i + 1).limit(pageCount)
.map(i -> this.fetchAccountEntries(accountIdentifier, dateRange, message, i, 10, "transactionDate", "ASC"))
.flatMap(pageI -> pageI.getAccountEntries().stream());
case "DESC":
return Stream.iterate(pageCount - 1, (i) -> i - 1).limit(pageCount)
.map(i -> this.fetchAccountEntries(accountIdentifier, dateRange, message, i, 10, "transactionDate", "ASC"))
.flatMap(pageI -> {
Collections.reverse(pageI.getAccountEntries());
return pageI.getAccountEntries().stream();
});
default:
throw new IllegalArgumentException();
}
}
@RequestMapping(
value = "/accounts/{identifier}/commands",
method = RequestMethod.GET,
produces = MediaType.ALL_VALUE,
consumes = MediaType.APPLICATION_JSON_VALUE
)
@ThrowsException(status = HttpStatus.NOT_FOUND, exception = AccountNotFoundException.class)
List<AccountCommand> fetchAccountCommands(@PathVariable("identifier") final String identifier);
@RequestMapping(
value = "/accounts/{identifier}/commands",
method = RequestMethod.POST,
produces = {MediaType.APPLICATION_JSON_VALUE},
consumes = {MediaType.APPLICATION_JSON_VALUE}
)
@ThrowsException(status = HttpStatus.NOT_FOUND, exception = AccountNotFoundException.class)
void accountCommand(@PathVariable("identifier") final String identifier, @RequestBody final AccountCommand accountCommand);
@RequestMapping(
value = "/journal",
method = RequestMethod.POST,
produces = {MediaType.APPLICATION_JSON_VALUE},
consumes = {MediaType.APPLICATION_JSON_VALUE}
)
@ThrowsExceptions({
@ThrowsException(status = HttpStatus.BAD_REQUEST, exception = JournalEntryValidationException.class),
@ThrowsException(status = HttpStatus.CONFLICT, exception = JournalEntryAlreadyExistsException.class)
})
void createJournalEntry(@RequestBody final JournalEntry journalEntry);
@RequestMapping(
value = "/journal",
method = RequestMethod.GET,
produces = {MediaType.ALL_VALUE},
consumes = {MediaType.APPLICATION_JSON_VALUE}
)
List<JournalEntry> fetchJournalEntries(@RequestParam(value = "dateRange", required = false) final String dateRange,
@RequestParam(value = "account", required = false) final String accountNumber,
@RequestParam(value = "amount", required = false) final BigDecimal amount);
@RequestMapping(
value = "/journal/{transactionIdentifier}",
method = RequestMethod.GET,
produces = {MediaType.ALL_VALUE},
consumes = {MediaType.APPLICATION_JSON_VALUE}
)
@ThrowsException(status = HttpStatus.NOT_FOUND, exception = JournalEntryNotFoundException.class)
JournalEntry findJournalEntry(@PathVariable("transactionIdentifier") final String transactionIdentifier);
@RequestMapping(
value = "/trialbalance",
method = RequestMethod.GET,
produces = {MediaType.ALL_VALUE},
consumes = {MediaType.APPLICATION_JSON_VALUE}
)
TrialBalance getTrialBalance(
@RequestParam(value = "includeEmptyEntries", required = false) final boolean includeEmptyEntries);
@RequestMapping(
value = "/chartofaccounts",
method = RequestMethod.GET,
produces = {MediaType.ALL_VALUE},
consumes = {MediaType.APPLICATION_JSON_VALUE}
)
List<ChartOfAccountEntry> getChartOfAccounts();
@RequestMapping(
value = "/transactiontypes",
method = RequestMethod.POST,
produces = {MediaType.APPLICATION_JSON_VALUE},
consumes = {MediaType.APPLICATION_JSON_VALUE}
)
@ThrowsExceptions({
@ThrowsException(status = HttpStatus.CONFLICT, exception = TransactionTypeAlreadyExists.class),
@ThrowsException(status = HttpStatus.BAD_REQUEST, exception = TransactionTypeValidationException.class)
})
void createTransactionType(@RequestBody @Valid final TransactionType transactionType);
@RequestMapping(
value = "/transactiontypes",
method = RequestMethod.GET,
produces = {MediaType.ALL_VALUE},
consumes = {MediaType.APPLICATION_JSON_VALUE}
)
TransactionTypePage fetchTransactionTypes(@RequestParam(value = "term", required = false) final String term,
@RequestParam(value = "pageIndex", required = false) final Integer pageIndex,
@RequestParam(value = "size", required = false) final Integer size,
@RequestParam(value = "sortColumn", required = false) final String sortColumn,
@RequestParam(value = "sortDirection", required = false) final String sortDirection);
@RequestMapping(
value = "/transactiontypes/{code}",
method = RequestMethod.PUT,
produces = {MediaType.APPLICATION_JSON_VALUE},
consumes = {MediaType.APPLICATION_JSON_VALUE}
)
@ThrowsExceptions({
@ThrowsException(status = HttpStatus.NOT_FOUND, exception = TransactionTypeNotFoundException.class),
@ThrowsException(status = HttpStatus.BAD_REQUEST, exception = TransactionTypeValidationException.class)
})
void changeTransactionType(@PathVariable("code") final String code,
@RequestBody @Valid final TransactionType transactionType);
@RequestMapping(
value = "/transactiontypes/{code}",
method = RequestMethod.GET,
produces = {MediaType.ALL_VALUE},
consumes = {MediaType.APPLICATION_JSON_VALUE}
)
@ThrowsExceptions({
@ThrowsException(status = HttpStatus.NOT_FOUND, exception = TransactionTypeNotFoundException.class)
})
TransactionType findTransactionType(@PathVariable("code") final String code);
@RequestMapping(
value = "/accounts/{identifier}/actions",
method = RequestMethod.GET,
produces = MediaType.APPLICATION_JSON_VALUE,
consumes = MediaType.APPLICATION_JSON_VALUE
)
@ThrowsExceptions({
@ThrowsException(status = HttpStatus.NOT_FOUND, exception = AccountNotFoundException.class)
})
List<AccountCommand> fetchActions(@PathVariable(value = "identifier") final String identifier);
@RequestMapping(
value = "/incomestatement",
method = RequestMethod.GET,
produces = {MediaType.ALL_VALUE},
consumes = {MediaType.APPLICATION_JSON_VALUE}
)
IncomeStatement getIncomeStatement();
@RequestMapping(
value = "/financialcondition",
method = RequestMethod.GET,
produces = {MediaType.ALL_VALUE},
consumes = {MediaType.APPLICATION_JSON_VALUE}
)
FinancialCondition getFinancialCondition();
}
| 4,790 |
0 | Create_ds/fineract-cn-accounting/api/src/main/java/org/apache/fineract/cn/accounting/api/v1 | Create_ds/fineract-cn-accounting/api/src/main/java/org/apache/fineract/cn/accounting/api/v1/client/AccountAlreadyExistsException.java | /*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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.apache.fineract.cn.accounting.api.v1.client;
@SuppressWarnings("WeakerAccess")
public final class AccountAlreadyExistsException extends RuntimeException {
}
| 4,791 |
0 | Create_ds/fineract-cn-accounting/api/src/main/java/org/apache/fineract/cn/accounting/api/v1 | Create_ds/fineract-cn-accounting/api/src/main/java/org/apache/fineract/cn/accounting/api/v1/client/AccountNotFoundException.java | /*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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.apache.fineract.cn.accounting.api.v1.client;
@SuppressWarnings("WeakerAccess")
public final class AccountNotFoundException extends RuntimeException {
}
| 4,792 |
0 | Create_ds/fineract-cn-accounting/api/src/main/java/org/apache/fineract/cn/accounting/api/v1 | Create_ds/fineract-cn-accounting/api/src/main/java/org/apache/fineract/cn/accounting/api/v1/client/JournalEntryNotFoundException.java | /*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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.apache.fineract.cn.accounting.api.v1.client;
@SuppressWarnings("WeakerAccess")
public final class JournalEntryNotFoundException extends RuntimeException {
}
| 4,793 |
0 | Create_ds/fineract-cn-accounting/api/src/main/java/org/apache/fineract/cn/accounting/api/v1 | Create_ds/fineract-cn-accounting/api/src/main/java/org/apache/fineract/cn/accounting/api/v1/client/LedgerNotFoundException.java | /*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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.apache.fineract.cn.accounting.api.v1.client;
@SuppressWarnings("WeakerAccess")
public final class LedgerNotFoundException extends RuntimeException {
}
| 4,794 |
0 | Create_ds/fineract-cn-accounting/api/src/main/java/org/apache/fineract/cn/accounting/api/v1 | Create_ds/fineract-cn-accounting/api/src/main/java/org/apache/fineract/cn/accounting/api/v1/client/JournalEntryAlreadyExistsException.java | /*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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.apache.fineract.cn.accounting.api.v1.client;
public class JournalEntryAlreadyExistsException extends RuntimeException {
}
| 4,795 |
0 | Create_ds/fineract-cn-accounting/api/src/main/java/org/apache/fineract/cn/accounting/api/v1 | Create_ds/fineract-cn-accounting/api/src/main/java/org/apache/fineract/cn/accounting/api/v1/client/TransactionTypeValidationException.java | /*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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.apache.fineract.cn.accounting.api.v1.client;
public class TransactionTypeValidationException extends RuntimeException {
}
| 4,796 |
0 | Create_ds/fineract-cn-accounting/service/src/main/java/org/apache/fineract/cn/accounting | Create_ds/fineract-cn-accounting/service/src/main/java/org/apache/fineract/cn/accounting/service/AccountingServiceConfiguration.java | /*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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.apache.fineract.cn.accounting.service;
import org.apache.fineract.cn.anubis.config.EnableAnubis;
import org.apache.fineract.cn.async.config.EnableAsync;
import org.apache.fineract.cn.cassandra.config.EnableCassandra;
import org.apache.fineract.cn.command.config.EnableCommandProcessing;
import org.apache.fineract.cn.customer.api.v1.client.CustomerManager;
import org.apache.fineract.cn.lang.config.EnableServiceException;
import org.apache.fineract.cn.lang.config.EnableTenantContext;
import org.apache.fineract.cn.postgresql.config.EnablePostgreSQL;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.cloud.netflix.feign.EnableFeignClients;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.PathMatchConfigurer;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
@Configuration
@EnableAutoConfiguration
@EnableAsync
@EnableTenantContext
@EnablePostgreSQL
@EnableCassandra
@EnableCommandProcessing
@EnableAnubis
@EnableServiceException
@ComponentScan({
"org.apache.fineract.cn.accounting.service.rest",
"org.apache.fineract.cn.accounting.service.internal"
})
@EnableFeignClients(
clients = {
CustomerManager.class
}
)
public class AccountingServiceConfiguration extends WebMvcConfigurerAdapter {
public AccountingServiceConfiguration() {
super();
}
@Bean(name = ServiceConstants.LOGGER_NAME)
public Logger logger() {
return LoggerFactory.getLogger(ServiceConstants.LOGGER_NAME);
}
@Override
public void configurePathMatch(final PathMatchConfigurer configurer) {
configurer.setUseSuffixPatternMatch(Boolean.FALSE);
}
}
| 4,797 |
0 | Create_ds/fineract-cn-accounting/service/src/main/java/org/apache/fineract/cn/accounting | Create_ds/fineract-cn-accounting/service/src/main/java/org/apache/fineract/cn/accounting/service/AccountingApplication.java | /*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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.apache.fineract.cn.accounting.service;
import org.springframework.boot.SpringApplication;
public class AccountingApplication {
public AccountingApplication() {
super();
}
public static void main(String[] args) {
SpringApplication.run(AccountingServiceConfiguration.class, args);
}
}
| 4,798 |
0 | Create_ds/fineract-cn-accounting/service/src/main/java/org/apache/fineract/cn/accounting | Create_ds/fineract-cn-accounting/service/src/main/java/org/apache/fineract/cn/accounting/service/ServiceConstants.java | /*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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.apache.fineract.cn.accounting.service;
public interface ServiceConstants {
String LOGGER_NAME = "accounting-logger";
}
| 4,799 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.