use of javax.persistence.NoResultException in project Asqatasun by Asqatasun.
the class StatisticsDAOImpl method findResultCountByResultTypeAndTheme.
/**
* Native sql query :
* SELECT ts.$testSolution FROM THEME_STATISTICS as ts,
* WEB_RESOURCE_STATISTICS as wrs
* WHERE ts.Id_Web_Resource_Statistics=wrs.Id_Web_Resource_Statistics
* AND wrs.Id_Web_Resource=:idWebResource
* AND wrs.Id_Audit=:idAudit
* AND ts.Id_Theme=:idTheme";
*
* where $testSolution is computed on the fly for the given the testSolution
* passed in argument.
*
* @param webResource
* @param audit
* @param testSolution
* @param theme
* @param manualAudit
* @return
* the number of elements for a given result type and theme
*/
@Override
public Long findResultCountByResultTypeAndTheme(WebResource webResource, Audit audit, TestSolution testSolution, Theme theme, boolean manualAudit) {
StringBuilder queryString = new StringBuilder();
queryString.append(SELECT_STR);
queryString.append(THEME_STATISTICS_TABLE_STR);
queryString = selectNbField(queryString, testSolution);
queryString.append(RETRIEVE_COUNT_BY_RESULT_TYPE_AND_THEME_QUERY);
queryString.append(" and wrs.manual_audit = ");
queryString.append(manualAudit ? "1" : "0");
Query query = entityManager.createNativeQuery(queryString.toString());
query.setParameter("idWebResource", webResource.getId());
query.setParameter("idAudit", audit.getId());
query.setParameter("idTheme", theme.getId());
try {
return ((Integer) query.getSingleResult()).longValue();
} catch (NoResultException e) {
return (long) 0;
}
}
use of javax.persistence.NoResultException in project Asqatasun by Asqatasun.
the class OptionElementDAOImpl method findOptionElementFromUser.
@Override
public Collection<OptionElement> findOptionElementFromUser(User user) {
Query query = entityManager.createQuery("SELECT u.optionElementSet FROM " + getUserEntityClass().getName() + " u" + " WHERE u=:user");
query.setParameter("user", user);
try {
return (Collection<OptionElement>) query.getResultList();
} catch (NoResultException | NonUniqueResultException nre) {
return null;
}
}
use of javax.persistence.NoResultException in project Asqatasun by Asqatasun.
the class OptionElementDAOImpl method findOptionElementFromValueAndOption.
/**
*
* @param value
* @param option
* @return
*/
@Override
public OptionElement findOptionElementFromValueAndOption(String value, Option option) {
Query query = entityManager.createQuery("SELECT oe FROM " + getEntityClass().getName() + " oe" + " WHERE oe.value=:value" + " AND oe.option=:option");
query.setParameter("value", value);
query.setParameter("option", option);
try {
return (OptionElement) query.getSingleResult();
} catch (NoResultException | NonUniqueResultException nre) {
return null;
}
}
use of javax.persistence.NoResultException in project ORCID-Source by ORCID.
the class OrcidSecurityManagerImpl method checkProfile.
/**
* Checks a record status and throw an exception indicating if the profile
* have any of the following conditions: - The record is not claimed and is
* not old enough nor being accessed by its creator - It is locked - It is
* deprecated - It is deactivated
*
* @throws OrcidDeprecatedException
* in case the account is deprecated
* @throws OrcidNotClaimedException
* in case the account is not claimed
* @throws LockedException
* in the case the account is locked
*/
@Override
public void checkProfile(String orcid) throws NoResultException, OrcidDeprecatedException, OrcidNotClaimedException, LockedException {
ProfileEntity profile = null;
try {
profile = profileEntityCacheManager.retrieve(orcid);
} catch (IllegalArgumentException e) {
throw new NoResultException();
}
// Check if the user record is deprecated
if (profile.getPrimaryRecord() != null) {
StringBuffer primary = new StringBuffer(baseUrl).append("/").append(profile.getPrimaryRecord().getId());
Map<String, String> params = new HashMap<String, String>();
params.put(OrcidDeprecatedException.ORCID, primary.toString());
if (profile.getDeprecatedDate() != null) {
XMLGregorianCalendar calendar = DateUtils.convertToXMLGregorianCalendar(profile.getDeprecatedDate());
params.put(OrcidDeprecatedException.DEPRECATED_DATE, calendar.toString());
}
throw new OrcidDeprecatedException(params);
}
// Check if the profile is not claimed and not old enough
if ((profile.getClaimed() == null || Boolean.FALSE.equals(profile.getClaimed())) && !isOldEnough(profile)) {
// Let the creator access the profile even if it is not claimed and
// not old enough
SourceEntity currentSourceEntity = sourceManager.retrieveSourceEntity();
String profileSource = profile.getSource() == null ? null : profile.getSource().getSourceId();
String currentSource = currentSourceEntity == null ? null : currentSourceEntity.getSourceId();
// the profile source, throw an exception
if (profileSource == null || !Objects.equals(profileSource, currentSource)) {
throw new OrcidNotClaimedException();
}
}
// Check if the record is locked
if (!profile.isAccountNonLocked()) {
LockedException lockedException = new LockedException();
lockedException.setOrcid(profile.getId());
throw lockedException;
}
}
use of javax.persistence.NoResultException in project ORCID-Source by ORCID.
the class OrcidRefreshTokenTokenGranterTest method tryToCreateRefreshTokenWithInvalidParentTokenValueTest.
@Test
public void tryToCreateRefreshTokenWithInvalidParentTokenValueTest() {
// Create token, try to create refresh token with invalid parent token
// value, fail
long time = System.currentTimeMillis();
String parentScope = "/person/update";
String tokenValue = "parent-token-" + time;
String refreshTokenValue = "refresh-token-" + time;
Boolean revokeOld = true;
Date parentTokenExpiration = new Date(time + 10000);
Long expireIn = null;
OrcidOauth2TokenDetail parent = createToken(CLIENT_ID_1, USER_ORCID, tokenValue, refreshTokenValue, parentTokenExpiration, parentScope);
try {
//Change the value we are going to use for the refresh token
parent.setTokenValue("invalid-value");
generateRefreshToken(parent, null, revokeOld, expireIn, parentScope);
fail();
} catch (NoResultException e) {
} catch (Exception e) {
fail();
}
}
Aggregations