Skip to content

Commit

Permalink
Refactor PersistentTokenRepository
Browse files Browse the repository at this point in the history
  • Loading branch information
gkysaad committed Aug 23, 2021
1 parent 561e5f3 commit f02de93
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 0 deletions.
16 changes: 16 additions & 0 deletions generators/server/files.js
Expand Up @@ -484,12 +484,28 @@ const serverFiles = {
file: 'package/domain/PersistentToken.java',
renameTo: generator => `${generator.javaDir}domain/PersistentToken.java`,
},
],
},
{
condition: generator => !shouldSkipUserManagement(generator) && generator.authenticationType === SESSION && !generator.reactive && generator.databaseType != COUCHBASE,
path: SERVER_MAIN_SRC_DIR,
templates: [
{
file: 'package/repository/PersistentTokenRepository.java',
renameTo: generator => `${generator.javaDir}repository/PersistentTokenRepository.java`,
},
],
},
{
condition: generator => !shouldSkipUserManagement(generator) && generator.authenticationType === SESSION && !generator.reactive && generator.databaseType === COUCHBASE,
path: SERVER_MAIN_SRC_DIR,
templates: [
{
file: `package/repository/PersistentTokenRepository_couchbase.java`,
renameTo: generator => `${generator.javaDir}repository/PersistentTokenRepository.java`,
},
],
},
{
condition: generator => generator.authenticationType === OAUTH2,
path: SERVER_MAIN_SRC_DIR,
Expand Down
@@ -0,0 +1,49 @@
<%#
Copyright 2013-2021 the original author or authors from the JHipster project.

This file is part of the JHipster project, see https://www.jhipster.tech/
for more information.

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
https://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 <%= packageName %>.repository;

import <%= packageName %>.domain.PersistentToken;
import <%= packageName %>.domain.<%= asEntity('User') %>;
import org.springframework.data.couchbase.repository.CouchbaseRepository;
import java.util.List;
import java.util.Optional;
import static <%= packageName %>.config.Constants.ID_DELIMITER;

/**
* Spring Data Couchbase repository for the {@link PersistentToken} entity.
*/
public interface PersistentTokenRepository extends CouchbaseRepository<PersistentToken, String> {

default Optional<PersistentToken> findBySeries(String series) {
return findById(PersistentToken.PREFIX + ID_DELIMITER + series);
}

default void deleteBySeries(String series) {
deleteById(PersistentToken.PREFIX + ID_DELIMITER + series);
}

default List<PersistentToken> findByUser(<%= asEntity('User') %> user) {
return findByLogin(user.getLogin());
}

List<PersistentToken> findByLogin(String login);

List<PersistentToken> findByTokenDateBefore(LocalDate localDate);

}

0 comments on commit f02de93

Please sign in to comment.