Skip to content

Commit

Permalink
#8 rulesEngine test
Browse files Browse the repository at this point in the history
  • Loading branch information
pethers committed Feb 26, 2018
1 parent 197d879 commit 233826b
Show file tree
Hide file tree
Showing 19 changed files with 457 additions and 127 deletions.
86 changes: 43 additions & 43 deletions citizen-intelligence-agency/.classpath

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/*
* Copyright 2010 James Pether Sörling
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* $Id$
* $HeadURL$
*/
package com.hack23.cia.service.api.action.kpi;

import com.hack23.cia.service.api.action.common.AbstractRequest;


/**
* The Class ComplianceCheckRequest.
*/
public final class ComplianceCheckRequest extends AbstractRequest {

/** The Constant serialVersionUID. */
private static final long serialVersionUID = 1L;

/** The session id. */
private String sessionId;

/**
* Instantiates a new compliance check request.
*/
public ComplianceCheckRequest() {
super();
}

/**
* Gets the session id.
*
* @return the session id
*/
public String getSessionId() {
return sessionId;
}

/**
* Sets the session id.
*
* @param sessionId
* the new session id
*/
public void setSessionId(final String sessionId) {
this.sessionId = sessionId;
}


}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
* Copyright 2010 James Pether Sörling
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* $Id$
* $HeadURL$
*/
package com.hack23.cia.service.api.action.kpi;

import com.hack23.cia.service.api.action.common.AbstractResponse;


/**
* The Class ComplianceCheckResponse.
*/
public final class ComplianceCheckResponse extends AbstractResponse {


/** The Constant serialVersionUID. */
private static final long serialVersionUID = 1L;

/**
* Instantiates a new compliance check response.
*
* @param result
* the result
*/
public ComplianceCheckResponse(final ServiceResult result) {
super(result);
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public static TestSuite suite() {
assertTrue(EXPECT_CLASSES_IN_PACKAGE,checkAllClassesInPackage(testSuiteProvider,"com.hack23.cia.service.api.action.application"));
assertTrue(EXPECT_CLASSES_IN_PACKAGE,checkAllClassesInPackage(testSuiteProvider,"com.hack23.cia.service.api.action.admin"));
assertTrue(EXPECT_CLASSES_IN_PACKAGE,checkAllClassesInPackage(testSuiteProvider,"com.hack23.cia.service.api.action.user"));

assertTrue(EXPECT_CLASSES_IN_PACKAGE,checkAllClassesInPackage(testSuiteProvider,"com.hack23.cia.service.api.action.kpi"));

testSuiteProvider.addClassChecker(ToStringNotNullChecker.class);
testSuiteProvider.addClassChecker(BijectiveCompareToChecker.class);
Expand Down
2 changes: 0 additions & 2 deletions service.impl/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
<groupId>org.drools</groupId>
<artifactId>drools-core</artifactId>
<version>7.6.0.Final</version>
<scope>test</scope>
<exclusions>
<exclusion>
<artifactId>mvel2</artifactId>
Expand All @@ -53,7 +52,6 @@
<groupId>org.kie</groupId>
<artifactId>kie-spring</artifactId>
<version>7.6.0.Final</version>
<scope>test</scope>
<exclusions>
<exclusion>
<artifactId>spring-tx</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
*/
package com.hack23.cia.service.impl;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
Expand Down Expand Up @@ -132,7 +133,7 @@ public void createDefaultLanguagesIfEmpty() {
private static List<LanguageData> getSupportedLocalesLanguageData() {
final List<LanguageData> languages = new ArrayList<>();

for (final Locale locale : SimpleDateFormat.getAvailableLocales()) {
for (final Locale locale : DateFormat.getAvailableLocales()) {
final String localeString = locale.toString().trim();
if (locale.getDisplayCountry(Locale.ENGLISH).length() == 0 && !StringUtils.isEmpty(localeString)
&& localeString.length() == EXPECTED_LOCALE_LENGTH) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
/*
* Copyright 2010 James Pether Sörling
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* $Id$
* $HeadURL$
*/
package com.hack23.cia.service.impl.action.kpi;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.annotation.Secured;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import com.hack23.cia.model.internal.application.system.impl.ApplicationEventGroup;
import com.hack23.cia.model.internal.application.system.impl.ApplicationOperationType;
import com.hack23.cia.model.internal.application.user.impl.UserAccount;
import com.hack23.cia.service.api.action.application.CreateApplicationEventRequest;
import com.hack23.cia.service.api.action.application.CreateApplicationEventResponse;
import com.hack23.cia.service.api.action.common.ServiceResponse.ServiceResult;
import com.hack23.cia.service.api.action.kpi.ComplianceCheckRequest;
import com.hack23.cia.service.api.action.kpi.ComplianceCheckResponse;
import com.hack23.cia.service.impl.action.common.AbstractBusinessServiceImpl;
import com.hack23.cia.service.impl.action.common.BusinessService;

/**
* The Class ComplianceCheckService.
*/
@Service
@Transactional(propagation = Propagation.REQUIRED,timeout=600)
public final class ComplianceCheckService extends
AbstractBusinessServiceImpl<ComplianceCheckRequest, ComplianceCheckResponse>
implements BusinessService<ComplianceCheckRequest, ComplianceCheckResponse> {

/** The Constant LOGGER. */
private static final Logger LOGGER = LoggerFactory
.getLogger(ComplianceCheckService.class);

/** The create application event service. */
@Autowired
private BusinessService<CreateApplicationEventRequest, CreateApplicationEventResponse> createApplicationEventService;

/**
* Instantiates a new compliance check service.
*/
public ComplianceCheckService() {
super(ComplianceCheckRequest.class);
}


@Secured({ "ROLE_USER", "ROLE_ADMIN", "ROLE_ANONYMOUS" })
@Override
public ComplianceCheckResponse processService(
final ComplianceCheckRequest serviceRequest) {

LOGGER.info("{}",serviceRequest.getClass().getSimpleName());

final CreateApplicationEventRequest eventRequest = new CreateApplicationEventRequest();
eventRequest.setEventGroup(ApplicationEventGroup.USER);
eventRequest.setApplicationOperation(ApplicationOperationType.READ);
eventRequest.setActionName(ComplianceCheckRequest.class.getSimpleName());
eventRequest.setSessionId(serviceRequest.getSessionId());

final UserAccount userAccount = getUserAccountFromSecurityContext();


if (userAccount != null) {

eventRequest.setUserId(userAccount.getUserId());
}

final ComplianceCheckResponse response = new ComplianceCheckResponse(ServiceResult.SUCCESS);

eventRequest.setApplicationMessage(response.getResult().toString());
createApplicationEventService.processService(eventRequest);

return response;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ public AbstractComplianceCheckImpl(final ResourceType resourceType) {
this.resourceType = resourceType;
}

@Override
public String getRuleName() {
return ruleName;
}
Expand All @@ -64,6 +65,7 @@ public void setRuleName(String ruleName) {
this.ruleName = ruleName;
}

@Override
public String getRuleDescription() {
return ruleDescription;
}
Expand All @@ -88,10 +90,12 @@ public void setStatus(Status status) {
this.status = status;
}

@Override
public ResourceType getResourceType() {
return resourceType;
}

@Override
public Status getStatus() {
return status;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
* Copyright 2010 James Pether Sörling
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* $Id$
* $HeadURL$
*/
package com.hack23.cia.service.impl.rules;

import java.util.List;

import com.hack23.cia.service.api.action.kpi.ComplianceCheck;

/**
* The Interface RulesEngine.
*/
public interface RulesEngine {

/**
* Check rules compliance.
*
* @return the list
*/
List<ComplianceCheck> checkRulesCompliance();

}
Loading

0 comments on commit 233826b

Please sign in to comment.