com.formkiq.server.api.SystemController Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of formkiq-server Show documentation
Show all versions of formkiq-server Show documentation
Server-side integration for the FormKiQ ios application
package com.formkiq.server.api;
import javax.transaction.Transactional;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import com.formkiq.server.domain.type.UserRole;
import com.formkiq.server.domain.type.UserStatus;
import com.formkiq.server.service.AuthenticationFailureException;
import com.formkiq.server.service.OAuthService;
import com.formkiq.server.service.UserService;
/**
* System Services.
*
*/
@RestController
public class SystemController extends AbstractRestController {
/** System Setup URL. */
public static final String API_SYSTEM_SETUP = "/api/setup";
/** System Ping URL. */
public static final String API_SYSTEM_PING = "/api/ping";
/** OAuthService. */
@Autowired
private OAuthService oauthservice;
/** UserService. */
@Autowired
private UserService userservice;
/**
* System Ping Response.
* @return {@link String}
*/
@RequestMapping(API_SYSTEM_PING)
public String ping() {
return "ok";
}
/**
* Setup System, this can be only called once per system.
* @param clientname String
* @param client String
* @param clientSecret String
* @param email String
* @param password String
* @return ApiMessageResponse
*/
@Transactional
@RequestMapping(API_SYSTEM_SETUP)
public ApiMessageResponse setup(
@RequestParam(value = "clientname", required = true)
final String clientname,
@RequestParam(value = "client", required = true)
final String client,
@RequestParam(value = "clientsecret", required = true)
final String clientSecret,
@RequestParam(value = "email", required = true)
final String email,
@RequestParam(value = "pass", required = true)
final String password) {
if (this.oauthservice.clientCount() > 0) {
throw new AuthenticationFailureException();
}
this.oauthservice.addClientDetails(clientname, client,
clientSecret);
this.userservice.createUser(client, email, password,
UserStatus.ACTIVE, UserRole.ROLE_ADMIN);
return new ApiMessageResponse("setup complete");
}
}