-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#37 pictureFolder implementation - saving during import
- Loading branch information
1 parent
b1e0874
commit ce54620
Showing
12 changed files
with
355 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
78 changes: 78 additions & 0 deletions
78
core/beans/src/main/java/gallerymine/model/PictureFolder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
package gallerymine.model; | ||
|
||
import lombok.Data; | ||
import org.joda.time.DateTime; | ||
import org.springframework.data.annotation.CreatedDate; | ||
import org.springframework.data.annotation.Id; | ||
import org.springframework.data.annotation.LastModifiedDate; | ||
import org.springframework.data.annotation.Version; | ||
import org.springframework.data.mongodb.core.index.Indexed; | ||
import org.springframework.data.mongodb.core.mapping.Document; | ||
|
||
import java.util.*; | ||
import java.util.stream.Collectors; | ||
|
||
/** | ||
* This bean holds information about request for indexing | ||
* Created by sergii_puliaiev on 7/30/18. | ||
*/ | ||
@Document(collection = "pictureFolder") | ||
@Data | ||
public class PictureFolder { | ||
|
||
@Id | ||
private String id; | ||
|
||
@Indexed | ||
private String name; | ||
@Indexed | ||
private String namel; | ||
@Indexed | ||
private String parentId; | ||
|
||
long filesCount; | ||
long foldersCount; | ||
|
||
/** Current folder path with name */ | ||
private String path; | ||
|
||
/** Current folder path with name, lowercased to support all filesystems */ | ||
@Indexed(unique = true) | ||
private String pathl; | ||
|
||
private List<String> notes = new ArrayList<>(); | ||
|
||
@CreatedDate | ||
private DateTime created; | ||
@LastModifiedDate | ||
private DateTime updated; | ||
|
||
@Version | ||
private Long version; | ||
|
||
public PictureFolder() { | ||
} | ||
|
||
public String addNote(String note, Object... params) { | ||
if (params!= null && params.length > 0) { | ||
note = String.format(note, params); | ||
} | ||
notes.add(note); | ||
return note; | ||
} | ||
|
||
public String notesText() { | ||
return notes.stream().collect(Collectors.joining("\n")); | ||
} | ||
|
||
public void setName(String name) { | ||
this.name = name; | ||
namel = name == null ? null : name.toLowerCase().replaceAll("^[_$/\\\\]*", ""); | ||
} | ||
|
||
public void setPath(String path) { | ||
this.path = path; | ||
pathl = path == null ? null : path.toLowerCase(); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
core/dao/src/main/java/gallerymine/backend/beans/repository/PictureFolderRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/* | ||
* Copyright 2012-2013 the original author or authors. | ||
* | ||
* 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 | ||
* | ||
* 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 gallerymine.backend.beans.repository; | ||
|
||
import gallerymine.model.PictureFolder; | ||
import org.springframework.data.mongodb.repository.MongoRepository; | ||
import org.springframework.data.repository.query.Param; | ||
import org.springframework.stereotype.Repository; | ||
|
||
import java.util.Collection; | ||
|
||
@Repository | ||
public interface PictureFolderRepository extends MongoRepository<PictureFolder, String>, PictureFolderRepositoryCustom { | ||
|
||
Collection<PictureFolder> findByName(@Param("name") String name); | ||
Collection<PictureFolder> findByNamel(@Param("namel") String namel); | ||
|
||
PictureFolder findByPath(@Param("path") String path); | ||
PictureFolder findByPathl(@Param("pathl") String pathl); | ||
|
||
} |
27 changes: 27 additions & 0 deletions
27
...dao/src/main/java/gallerymine/backend/beans/repository/PictureFolderRepositoryCustom.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
/* | ||
* Copyright 2012-2013 the original author or authors. | ||
* | ||
* 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 | ||
* | ||
* 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 gallerymine.backend.beans.repository; | ||
|
||
import org.springframework.stereotype.Repository; | ||
|
||
@Repository | ||
public interface PictureFolderRepositoryCustom { | ||
|
||
long incrementFilesCount(String picFolderId); | ||
long incrementFoldersCount(String picFolderId); | ||
|
||
} |
43 changes: 43 additions & 0 deletions
43
core/dao/src/main/java/gallerymine/backend/beans/repository/PictureFolderRepositoryImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package gallerymine.backend.beans.repository; | ||
|
||
import gallerymine.backend.data.RetryVersion; | ||
import gallerymine.model.PictureFolder; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.data.mongodb.core.MongoTemplate; | ||
import org.springframework.stereotype.Repository; | ||
|
||
/** | ||
* Source repository with custom methods | ||
* Created by sergii_puliaiev on 6/19/17. | ||
*/ | ||
@Repository | ||
public class PictureFolderRepositoryImpl implements PictureFolderRepositoryCustom { | ||
|
||
private static Logger log = LoggerFactory.getLogger(PictureFolderRepositoryImpl.class); | ||
|
||
@Autowired | ||
protected MongoTemplate template = null; | ||
|
||
@Override | ||
@RetryVersion(times = 10, on = org.springframework.dao.OptimisticLockingFailureException.class) | ||
public long incrementFilesCount(String picFolderId) { | ||
PictureFolder picFolder = template.findById(picFolderId, PictureFolder.class); | ||
picFolder.setFilesCount(picFolder.getFilesCount()+1); | ||
template.save(picFolder); | ||
log.info(" incFiles for folder new={} path={}", picFolder.getFilesCount(), picFolder.getPath()); | ||
return picFolder.getFilesCount(); | ||
} | ||
|
||
@Override | ||
@RetryVersion(times = 10, on = org.springframework.dao.OptimisticLockingFailureException.class) | ||
public long incrementFoldersCount(String picFolderId) { | ||
PictureFolder picFolder = template.findById(picFolderId, PictureFolder.class); | ||
picFolder.setFoldersCount(picFolder.getFoldersCount()+1); | ||
template.save(picFolder); | ||
log.info(" incFolders for folder new={} path={}", picFolder.getFilesCount(), picFolder.getPath()); | ||
return picFolder.getFoldersCount(); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.