Search in sources :

Example 6 with Transactional

use of com.peterphi.std.guice.database.annotation.Transactional in project stdlib by petergeneric.

the class AzureInstanceActionDaemon method handle.

@Transactional
public void handle(final int id) {
    ResourceInstanceEntity instance = dao.getById(id);
    handle(instance);
    dao.update(instance);
}
Also used : ResourceInstanceEntity(com.peterphi.servicemanager.service.db.entity.ResourceInstanceEntity) Transactional(com.peterphi.std.guice.database.annotation.Transactional)

Example 7 with Transactional

use of com.peterphi.std.guice.database.annotation.Transactional in project stdlib by petergeneric.

the class ServiceManagerResourceUIServiceImpl method getResource.

/**
 * N.B. transaction may be read-write because this read operation may result in reading a new template (or discovering an
 * update was made to the template)
 *
 * @param id
 *
 * @return
 */
@Override
@Transactional
public String getResource(String id) {
    final TemplateCall call = templater.template("resource_template");
    final ResourceTemplateEntity entity = resourceProvisionService.getOrCreateTemplate(id);
    if (entity == null)
        throw new RestException(404, "No such resource with id: " + id);
    call.set("entity", entity);
    call.set("nonce", nonceStore.getValue());
    return call.process();
}
Also used : RestException(com.peterphi.std.guice.restclient.exception.RestException) ResourceTemplateEntity(com.peterphi.servicemanager.service.db.entity.ResourceTemplateEntity) TemplateCall(com.peterphi.std.guice.web.rest.templating.TemplateCall) Transactional(com.peterphi.std.guice.database.annotation.Transactional)

Example 8 with Transactional

use of com.peterphi.std.guice.database.annotation.Transactional in project stdlib by petergeneric.

the class LetsEncryptCertificateDaoImpl method getEligibleForRenewal.

@Transactional(readOnly = true)
public List<String> getEligibleForRenewal(int renewDays) {
    final Criteria criteria = createCriteria();
    criteria.add(Restrictions.lt("expires", DateTime.now().plusDays(renewDays)));
    criteria.addOrder(Order.asc("expires"));
    return getIdList(criteria);
}
Also used : Criteria(org.hibernate.Criteria) Transactional(com.peterphi.std.guice.database.annotation.Transactional)

Example 9 with Transactional

use of com.peterphi.std.guice.database.annotation.Transactional in project stdlib by petergeneric.

the class OAuthSessionDaoImpl method exchangeCodeForToken.

@Transactional
public OAuthSessionEntity exchangeCodeForToken(final OAuthServiceEntity service, final String authorisationCode) {
    final OAuthSessionEntity session = uniqueResult(new WebQuery().eq("authorisationCode", authorisationCode).isNull("token").eq("alive", true).eq("context.service.id", service.getId()));
    if (session == null)
        return null;
    session.setToken(SimpleId.alphanumeric("tok-", 36));
    session.setAuthorisationCode(null);
    update(session);
    return session;
}
Also used : OAuthSessionEntity(com.peterphi.usermanager.db.entity.OAuthSessionEntity) WebQuery(com.peterphi.std.guice.restclient.jaxb.webquery.WebQuery) Transactional(com.peterphi.std.guice.database.annotation.Transactional)

Example 10 with Transactional

use of com.peterphi.std.guice.database.annotation.Transactional in project stdlib by petergeneric.

the class OAuthSessionDaoImpl method exchangeRefreshTokenForNewToken.

@Transactional
public OAuthSessionEntity exchangeRefreshTokenForNewToken(final OAuthServiceEntity service, final String refreshToken, final DateTime newExpires) {
    final OAuthSessionEntity session = uniqueResult(new WebQuery().eq("id", refreshToken).isNotNull("token").eq("alive", true).eq("context.service.id", service.getId()));
    if (session == null)
        return null;
    session.setToken(SimpleId.alphanumeric("tok-", 36));
    session.setExpires(newExpires);
    update(session);
    return session;
}
Also used : OAuthSessionEntity(com.peterphi.usermanager.db.entity.OAuthSessionEntity) WebQuery(com.peterphi.std.guice.restclient.jaxb.webquery.WebQuery) Transactional(com.peterphi.std.guice.database.annotation.Transactional)

Aggregations

Transactional (com.peterphi.std.guice.database.annotation.Transactional)46 UserEntity (com.peterphi.usermanager.db.entity.UserEntity)13 WebQuery (com.peterphi.std.guice.restclient.jaxb.webquery.WebQuery)11 TemplateCall (com.peterphi.std.guice.web.rest.templating.TemplateCall)9 RoleEntity (com.peterphi.usermanager.db.entity.RoleEntity)9 AuthConstraint (com.peterphi.std.guice.common.auth.annotations.AuthConstraint)8 OAuthServiceEntity (com.peterphi.usermanager.db.entity.OAuthServiceEntity)5 AuthenticationFailureException (com.peterphi.usermanager.guice.authentication.AuthenticationFailureException)5 OAuthSessionEntity (com.peterphi.usermanager.db.entity.OAuthSessionEntity)4 Test (org.junit.Test)4 ResourceInstanceEntity (com.peterphi.servicemanager.service.db.entity.ResourceInstanceEntity)3 ResourceTemplateEntity (com.peterphi.servicemanager.service.db.entity.ResourceTemplateEntity)3 Criteria (org.hibernate.Criteria)3 List (java.util.List)2 DateTime (org.joda.time.DateTime)2 Timer (com.codahale.metrics.Timer)1 Inject (com.google.inject.Inject)1 Singleton (com.google.inject.Singleton)1 ServiceInstanceEntity (com.peterphi.servicemanager.service.db.entity.ServiceInstanceEntity)1 ResourceNetworkConfig (com.peterphi.servicemanager.service.guice.ResourceNetworkConfig)1