Author: jbernhardt
Date: Thu Jan 24 16:58:07 2013
New Revision: 1438071
URL: http://svn.apache.org/viewvc?rev=1438071&view=rev
Log:
[SYNCOPE-231]
* Adding LoggerServiceImpl (was missing in last commit)
* Simplified getObject helper method from jax-ws.response object
Added:
syncope/trunk/core/src/main/java/org/apache/syncope/core/services/LoggerServiceImpl.java
Modified:
syncope/trunk/core/src/test/java/org/apache/syncope/core/rest/AbstractTest.java
syncope/trunk/core/src/test/java/org/apache/syncope/core/rest/AuthenticationTestITCase.java
syncope/trunk/core/src/test/java/org/apache/syncope/core/rest/ConfigurationTestITCase.java
syncope/trunk/core/src/test/java/org/apache/syncope/core/rest/ConnInstanceTestITCase.java
syncope/trunk/core/src/test/java/org/apache/syncope/core/rest/DerivedSchemaTestITCase.java
syncope/trunk/core/src/test/java/org/apache/syncope/core/rest/PolicyTestITCase.java
syncope/trunk/core/src/test/java/org/apache/syncope/core/rest/SchemaTestITCase.java
syncope/trunk/core/src/test/java/org/apache/syncope/core/rest/UserRequestTestITCase.java
syncope/trunk/core/src/test/java/org/apache/syncope/core/rest/UserTestITCase.java
syncope/trunk/core/src/test/java/org/apache/syncope/core/rest/VirtualSchemaTestITCase.java
Added:
syncope/trunk/core/src/main/java/org/apache/syncope/core/services/LoggerServiceImpl.java
URL:
http://svn.apache.org/viewvc/syncope/trunk/core/src/main/java/org/apache/syncope/core/services/LoggerServiceImpl.java?rev=1438071&view=auto
==============================================================================
---
syncope/trunk/core/src/main/java/org/apache/syncope/core/services/LoggerServiceImpl.java
(added)
+++
syncope/trunk/core/src/main/java/org/apache/syncope/core/services/LoggerServiceImpl.java
Thu Jan 24 16:58:07 2013
@@ -0,0 +1,110 @@
+/*
+ * 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.syncope.core.services;
+
+import java.util.List;
+
+import javax.ws.rs.BadRequestException;
+import javax.ws.rs.NotFoundException;
+
+import org.apache.syncope.common.services.LoggerService;
+import org.apache.syncope.common.to.LoggerTO;
+import org.apache.syncope.common.types.AuditLoggerName;
+import org.apache.syncope.common.types.LoggerType;
+import org.apache.syncope.common.util.CollectionWrapper;
+import org.apache.syncope.core.rest.controller.LoggerController;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+@Service
+public class LoggerServiceImpl implements LoggerService {
+
+ @Autowired
+ private LoggerController loggerController;
+
+ @Override
+ public List<LoggerTO> list(final LoggerType type) {
+ switch (type) {
+ case NORMAL:
+ return loggerController.listLogs();
+
+ case AUDIT:
+ List<AuditLoggerName> auditLogger =
loggerController.listAudits();
+ return CollectionWrapper.unwrapLogger(auditLogger);
+
+ default:
+ throw new BadRequestException();
+ }
+ }
+
+ @Override
+ public LoggerTO read(final LoggerType type, final String name) {
+ List<LoggerTO> logger = list(type);
+ for (LoggerTO l : logger) {
+ if (l.getName().equals(name)) {
+ return l;
+ }
+ }
+ throw new NotFoundException();
+ }
+
+ @Override
+ public void update(final LoggerType type, final String name, final
LoggerTO logger) {
+ switch (type) {
+ case NORMAL:
+ loggerController.setLogLevel(name,
logger.getLevel().getLevel());
+ break;
+
+ case AUDIT:
+ try {
+
loggerController.enableAudit(AuditLoggerName.fromLoggerName(name));
+ } catch (Exception e) {
+ throw new BadRequestException(e);
+ }
+ break;
+
+ default:
+ throw new BadRequestException();
+ }
+ }
+
+ @Override
+ public void delete(final LoggerType type, final String name) {
+ switch (type) {
+ case NORMAL:
+ try {
+ loggerController.deleteLog(name);
+ } catch (org.apache.syncope.core.util.NotFoundException e) {
+ throw new NotFoundException(e);
+ }
+ break;
+ case AUDIT:
+ try {
+
loggerController.disableAudit(AuditLoggerName.fromLoggerName(name));
+ } catch (Exception e) {
+ throw new BadRequestException(e);
+ }
+
+ default:
+ throw new BadRequestException();
+ }
+
+ }
+
+}
Modified:
syncope/trunk/core/src/test/java/org/apache/syncope/core/rest/AbstractTest.java
URL:
http://svn.apache.org/viewvc/syncope/trunk/core/src/test/java/org/apache/syncope/core/rest/AbstractTest.java?rev=1438071&r1=1438070&r2=1438071&view=diff
==============================================================================
---
syncope/trunk/core/src/test/java/org/apache/syncope/core/rest/AbstractTest.java
(original)
+++
syncope/trunk/core/src/test/java/org/apache/syncope/core/rest/AbstractTest.java
Thu Jan 24 16:58:07 2013
@@ -29,6 +29,7 @@ import java.util.UUID;
import javax.sql.DataSource;
import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
import org.apache.cxf.jaxrs.client.Client;
import org.apache.cxf.jaxrs.client.JAXRSClientFactoryBean;
@@ -253,22 +254,24 @@ public abstract class AbstractTest {
}
// END CXF Initialization
- public <T> T getObject(final URI location, final Class<T> type, final
Object serviceProxy) {
+ public <T> T getObject(final Response response, final Class<T> type, final
Object serviceProxy) {
+ assertNotNull(response);
+ assertNotNull(response.getLocation());
if (!activatedCXF) {
- return getObjectSpring(location, type);
+ return getObjectSpring(response, type);
} else {
- return resolveObjectCXF(location, type, serviceProxy);
+ return getObjectCXF(response, type, serviceProxy);
}
}
- public <T> T getObjectSpring(final URI location, final Class<T> type) {
- assertNotNull(location);
- return restTemplate.getForEntity(location, type).getBody();
+ private <T> T getObjectSpring(final Response response, final Class<T>
type) {
+ return restTemplate.getForEntity(response.getLocation(),
type).getBody();
}
- public static <T> T resolveObjectCXF(final URI location, final Class<T>
type, final Object serviceProxy) {
+ private static <T> T getObjectCXF(final Response response, final Class<T>
type, final Object serviceProxy) {
+ String location = response.getLocation().toString();
WebClient webClient =
WebClient.fromClient(WebClient.client(serviceProxy));
- webClient.to(location.toString(), false);
+ webClient.to(location, false);
return webClient.get(type);
}
Modified:
syncope/trunk/core/src/test/java/org/apache/syncope/core/rest/AuthenticationTestITCase.java
URL:
http://svn.apache.org/viewvc/syncope/trunk/core/src/test/java/org/apache/syncope/core/rest/AuthenticationTestITCase.java?rev=1438071&r1=1438070&r2=1438071&view=diff
==============================================================================
---
syncope/trunk/core/src/test/java/org/apache/syncope/core/rest/AuthenticationTestITCase.java
(original)
+++
syncope/trunk/core/src/test/java/org/apache/syncope/core/rest/AuthenticationTestITCase.java
Thu Jan 24 16:58:07 2013
@@ -91,8 +91,7 @@ public class AuthenticationTestITCase ex
schemaTO.setType(SchemaType.String);
Response response = schemaService.create(AttributableType.USER,
SchemaService.SchemaType.NORMAL, schemaTO);
- assertNotNull(response);
- SchemaTO newSchemaTO = getObject(response.getLocation(),
SchemaTO.class, entitlementService);
+ SchemaTO newSchemaTO = getObject(response, SchemaTO.class,
entitlementService);
assertEquals(schemaTO, newSchemaTO);
// 2. create an user with the role created above (as admin)
Modified:
syncope/trunk/core/src/test/java/org/apache/syncope/core/rest/ConfigurationTestITCase.java
URL:
http://svn.apache.org/viewvc/syncope/trunk/core/src/test/java/org/apache/syncope/core/rest/ConfigurationTestITCase.java?rev=1438071&r1=1438070&r2=1438071&view=diff
==============================================================================
---
syncope/trunk/core/src/test/java/org/apache/syncope/core/rest/ConfigurationTestITCase.java
(original)
+++
syncope/trunk/core/src/test/java/org/apache/syncope/core/rest/ConfigurationTestITCase.java
Thu Jan 24 16:58:07 2013
@@ -50,7 +50,7 @@ public class ConfigurationTestITCase ext
Response response = configurationService.create(configurationTO);
assertNotNull(response);
assertEquals(org.apache.http.HttpStatus.SC_CREATED,
response.getStatus());
- ConfigurationTO newConfigurationTO = getObject(response.getLocation(),
ConfigurationTO.class, configurationService);
+ ConfigurationTO newConfigurationTO = getObject(response,
ConfigurationTO.class, configurationService);
assertEquals(configurationTO, newConfigurationTO);
}
@@ -73,9 +73,9 @@ public class ConfigurationTestITCase ext
}
Response response = configurationService.create(tokenLengthTO);
- assertEquals(org.apache.http.HttpStatus.SC_CREATED,
response.getStatus());
assertNotNull(response);
- ConfigurationTO newConfigurationTO = getObject(response.getLocation(),
ConfigurationTO.class, configurationService);
+ assertEquals(org.apache.http.HttpStatus.SC_CREATED,
response.getStatus());
+ ConfigurationTO newConfigurationTO = getObject(response,
ConfigurationTO.class, configurationService);
assertEquals(tokenLengthTO, newConfigurationTO);
}
Modified:
syncope/trunk/core/src/test/java/org/apache/syncope/core/rest/ConnInstanceTestITCase.java
URL:
http://svn.apache.org/viewvc/syncope/trunk/core/src/test/java/org/apache/syncope/core/rest/ConnInstanceTestITCase.java?rev=1438071&r1=1438070&r2=1438071&view=diff
==============================================================================
---
syncope/trunk/core/src/test/java/org/apache/syncope/core/rest/ConnInstanceTestITCase.java
(original)
+++
syncope/trunk/core/src/test/java/org/apache/syncope/core/rest/ConnInstanceTestITCase.java
Thu Jan 24 16:58:07 2013
@@ -139,8 +139,7 @@ public class ConnInstanceTestITCase exte
connectorTO.addCapability(ConnectorCapability.TWO_PHASES_UPDATE);
Response response = connectorService.create(connectorTO);
- assertNotNull(response);
- ConnInstanceTO actual = getObject(response.getLocation(),
ConnInstanceTO.class, connectorService);
+ ConnInstanceTO actual = getObject(response, ConnInstanceTO.class,
connectorService);
assertNotNull(actual);
@@ -203,7 +202,7 @@ public class ConnInstanceTestITCase exte
// set bundle name
connectorTO.setBundleName("org.connid.bundles.soap");
-
+
connectorTO.setConnRequestTimeout(20);
// set the connector configuration using PropertyTO
@@ -275,8 +274,7 @@ public class ConnInstanceTestITCase exte
// Create a new connector instance.
// ----------------------------------
Response response = connectorService.create(connInstanceTO);
- assertNotNull(response);
- connInstanceTO = getObject(response.getLocation(),
ConnInstanceTO.class, connectorService);
+ connInstanceTO = getObject(response, ConnInstanceTO.class,
connectorService);
assertNotNull(connInstanceTO);
assertTrue(connInstanceTO.getCapabilities().isEmpty());
@@ -585,8 +583,7 @@ public class ConnInstanceTestITCase exte
assertFalse(connectorService.validate(connectorTO));
Response response = connectorService.create(connectorTO);
- assertNotNull(response);
- connectorTO = getObject(response.getLocation(),
ConnInstanceTO.class, configurationService);
+ connectorTO = getObject(response, ConnInstanceTO.class,
configurationService);
assertNotNull(connectorTO);
// ----------------------------------------
Modified:
syncope/trunk/core/src/test/java/org/apache/syncope/core/rest/DerivedSchemaTestITCase.java
URL:
http://svn.apache.org/viewvc/syncope/trunk/core/src/test/java/org/apache/syncope/core/rest/DerivedSchemaTestITCase.java?rev=1438071&r1=1438070&r2=1438071&view=diff
==============================================================================
---
syncope/trunk/core/src/test/java/org/apache/syncope/core/rest/DerivedSchemaTestITCase.java
(original)
+++
syncope/trunk/core/src/test/java/org/apache/syncope/core/rest/DerivedSchemaTestITCase.java
Thu Jan 24 16:58:07 2013
@@ -69,8 +69,7 @@ public class DerivedSchemaTestITCase ext
schema.setExpression("derived_sx + '_' + derived_dx");
Response response = schemaService.create(AttributableType.USER,
SchemaService.SchemaType.DERIVED, schema);
- assertNotNull(response);
- DerivedSchemaTO actual = getObject(response.getLocation(),
DerivedSchemaTO.class, schemaService);
+ DerivedSchemaTO actual = getObject(response, DerivedSchemaTO.class,
schemaService);
assertNotNull(actual);
actual = schemaService.read(AttributableType.USER,
SchemaService.SchemaType.DERIVED, actual.getName());
Modified:
syncope/trunk/core/src/test/java/org/apache/syncope/core/rest/PolicyTestITCase.java
URL:
http://svn.apache.org/viewvc/syncope/trunk/core/src/test/java/org/apache/syncope/core/rest/PolicyTestITCase.java?rev=1438071&r1=1438070&r2=1438071&view=diff
==============================================================================
---
syncope/trunk/core/src/test/java/org/apache/syncope/core/rest/PolicyTestITCase.java
(original)
+++
syncope/trunk/core/src/test/java/org/apache/syncope/core/rest/PolicyTestITCase.java
Thu Jan 24 16:58:07 2013
@@ -116,8 +116,7 @@ public class PolicyTestITCase extends Ab
SyncPolicyTO policy = buildSyncPolicyTO();
Response response = policyService.create(PolicyType.SYNC, policy);
- assertNotNull(response);
- SyncPolicyTO policyTO = getObject(response.getLocation(),
SyncPolicyTO.class, policyService);
+ SyncPolicyTO policyTO = getObject(response, SyncPolicyTO.class,
policyService);
assertNotNull(policyTO);
assertEquals(PolicyType.SYNC, policyTO.getType());
@@ -134,8 +133,7 @@ public class PolicyTestITCase extends Ab
// create a new password policy using global password as a template
Response response = policyService.create(PolicyType.PASSWORD, policy);
- assertNotNull(response);
- policy = getObject(response.getLocation(), PasswordPolicyTO.class,
policyService);
+ policy = getObject(response, PasswordPolicyTO.class, policyService);
// read new password policy
policy = policyService.read(PolicyType.PASSWORD, policy.getId());
@@ -160,8 +158,7 @@ public class PolicyTestITCase extends Ab
public void delete() {
SyncPolicyTO policy = buildSyncPolicyTO();
Response response = policyService.create(PolicyType.SYNC, policy);
- assertNotNull(response);
- SyncPolicyTO policyTO = getObject(response.getLocation(),
SyncPolicyTO.class, policyService);
+ SyncPolicyTO policyTO = getObject(response, SyncPolicyTO.class,
policyService);
assertNotNull(policyTO);
policyService.delete(PolicyType.SYNC, policyTO.getId());
Modified:
syncope/trunk/core/src/test/java/org/apache/syncope/core/rest/SchemaTestITCase.java
URL:
http://svn.apache.org/viewvc/syncope/trunk/core/src/test/java/org/apache/syncope/core/rest/SchemaTestITCase.java?rev=1438071&r1=1438070&r2=1438071&view=diff
==============================================================================
---
syncope/trunk/core/src/test/java/org/apache/syncope/core/rest/SchemaTestITCase.java
(original)
+++
syncope/trunk/core/src/test/java/org/apache/syncope/core/rest/SchemaTestITCase.java
Thu Jan 24 16:58:07 2013
@@ -61,17 +61,11 @@ public class SchemaTestITCase extends Ab
schemaTO.setMandatoryCondition("false");
Response response = schemaService.create(AttributableType.USER,
SchemaService.SchemaType.NORMAL, schemaTO);
- assertNotNull(response);
- assertNotNull(response.getLocation());
-
- SchemaTO newSchemaTO = getObject(response.getLocation(),
SchemaTO.class, schemaService);
+ SchemaTO newSchemaTO = getObject(response, SchemaTO.class,
schemaService);
assertEquals(schemaTO, newSchemaTO);
response = schemaService.create(AttributableType.MEMBERSHIP,
SchemaService.SchemaType.NORMAL, schemaTO);
- assertNotNull(response);
- assertNotNull(response.getLocation());
-
- newSchemaTO = getObject(response.getLocation(), SchemaTO.class,
schemaService);
+ newSchemaTO = getObject(response, SchemaTO.class, schemaService);
assertEquals(schemaTO, newSchemaTO);
}
@@ -197,9 +191,7 @@ public class SchemaTestITCase extends Ab
schemaTO.setType(SchemaType.Double);
Response response = schemaService.create(AttributableType.USER,
SchemaService.SchemaType.NORMAL, schemaTO);
- assertNotNull(response);
- assertNotNull(response.getLocation());
- schemaTO = getObject(response.getLocation(), SchemaTO.class,
schemaService);
+ schemaTO = getObject(response, SchemaTO.class, schemaService);
assertNotNull(schemaTO);
UserTO userTO =
UserTestITCase.getUniqueSampleTO("[email protected]");
@@ -224,9 +216,7 @@ public class SchemaTestITCase extends Ab
schemaTO.setUniqueConstraint(true);
Response response = schemaService.create(AttributableType.USER,
SchemaService.SchemaType.NORMAL, schemaTO);
- assertNotNull(response);
- assertNotNull(response.getLocation());
- schemaTO = getObject(response.getLocation(), SchemaTO.class,
schemaService);
+ schemaTO = getObject(response, SchemaTO.class, schemaService);
assertNotNull(schemaTO);
UserTO userTO =
UserTestITCase.getUniqueSampleTO("[email protected]");
@@ -251,9 +241,7 @@ public class SchemaTestITCase extends Ab
schemaTO.setUniqueConstraint(true);
Response response = schemaService.create(AttributableType.USER,
SchemaService.SchemaType.NORMAL, schemaTO);
- assertNotNull(response);
- assertNotNull(response.getLocation());
- schemaTO = getObject(response.getLocation(), SchemaTO.class,
schemaService);
+ schemaTO = getObject(response, SchemaTO.class, schemaService);
assertNotNull(schemaTO);
UserTO userTO =
UserTestITCase.getUniqueSampleTO("[email protected]");
Modified:
syncope/trunk/core/src/test/java/org/apache/syncope/core/rest/UserRequestTestITCase.java
URL:
http://svn.apache.org/viewvc/syncope/trunk/core/src/test/java/org/apache/syncope/core/rest/UserRequestTestITCase.java?rev=1438071&r1=1438070&r2=1438071&view=diff
==============================================================================
---
syncope/trunk/core/src/test/java/org/apache/syncope/core/rest/UserRequestTestITCase.java
(original)
+++
syncope/trunk/core/src/test/java/org/apache/syncope/core/rest/UserRequestTestITCase.java
Thu Jan 24 16:58:07 2013
@@ -61,7 +61,7 @@ public class UserRequestTestITCase exten
Response response = configurationService.create(configurationTO);
assertNotNull(response);
assertEquals(org.apache.http.HttpStatus.SC_CREATED,
response.getStatus());
- configurationTO = getObject(response.getLocation(),
ConfigurationTO.class, configurationService);
+ configurationTO = getObject(response, ConfigurationTO.class,
configurationService);
assertNotNull(configurationTO);
UserTO userTO =
UserTestITCase.getUniqueSampleTO("[email protected]");
@@ -82,7 +82,7 @@ public class UserRequestTestITCase exten
response = configurationService.create(configurationTO);
assertNotNull(response);
assertEquals(org.apache.http.HttpStatus.SC_CREATED,
response.getStatus());
- configurationTO = getObject(response.getLocation(),
ConfigurationTO.class, configurationService);
+ configurationTO = getObject(response, ConfigurationTO.class,
configurationService);
assertNotNull(configurationTO);
// 4. as anonymous, request user create works
Modified:
syncope/trunk/core/src/test/java/org/apache/syncope/core/rest/UserTestITCase.java
URL:
http://svn.apache.org/viewvc/syncope/trunk/core/src/test/java/org/apache/syncope/core/rest/UserTestITCase.java?rev=1438071&r1=1438070&r2=1438071&view=diff
==============================================================================
---
syncope/trunk/core/src/test/java/org/apache/syncope/core/rest/UserTestITCase.java
(original)
+++
syncope/trunk/core/src/test/java/org/apache/syncope/core/rest/UserTestITCase.java
Thu Jan 24 16:58:07 2013
@@ -121,6 +121,7 @@ public class UserTestITCase extends Abst
assertEquals("user1", userTO.getUsername());
}
+ @SuppressWarnings("unchecked")
@Test
public void createUserWithNoPropagation() {
// get task list
@@ -186,8 +187,7 @@ public class UserTestITCase extends Abst
} finally {
for (PasswordPolicyTO policyTO : policies) {
Response response =
policyService.create(PolicyType.GLOBAL_PASSWORD, policyTO);
- assertNotNull(response);
- PolicyTO cPolicyTO = getObject(response.getLocation(),
PasswordPolicyTO.class, policyService);
+ PolicyTO cPolicyTO = getObject(response,
PasswordPolicyTO.class, policyService);
assertNotNull(cPolicyTO);
}
}
@@ -404,6 +404,7 @@ public class UserTestITCase extends Abst
userService.create(newUserTO);
}
+ @SuppressWarnings("unchecked")
@Test
public void create() {
// get task list
Modified:
syncope/trunk/core/src/test/java/org/apache/syncope/core/rest/VirtualSchemaTestITCase.java
URL:
http://svn.apache.org/viewvc/syncope/trunk/core/src/test/java/org/apache/syncope/core/rest/VirtualSchemaTestITCase.java?rev=1438071&r1=1438070&r2=1438071&view=diff
==============================================================================
---
syncope/trunk/core/src/test/java/org/apache/syncope/core/rest/VirtualSchemaTestITCase.java
(original)
+++
syncope/trunk/core/src/test/java/org/apache/syncope/core/rest/VirtualSchemaTestITCase.java
Thu Jan 24 16:58:07 2013
@@ -65,9 +65,7 @@ public class VirtualSchemaTestITCase ext
schema.setName("virtual");
Response response = schemaService.create(AttributableType.USER,
SchemaService.SchemaType.VIRTUAL, schema);
- assertNotNull(response);
- assertNotNull(response.getLocation());
- VirtualSchemaTO actual = getObject(response.getLocation(),
VirtualSchemaTO.class, schemaService);
+ VirtualSchemaTO actual = getObject(response, VirtualSchemaTO.class,
schemaService);
assertNotNull(actual);
actual = schemaService.read(AttributableType.USER,
SchemaService.SchemaType.VIRTUAL, actual.getName());