2020-11-07 11:56:38 -08:00
|
|
|
/*
|
|
|
|
* Copyright [2015] [wisemapping]
|
|
|
|
*
|
|
|
|
* Licensed under WiseMapping Public License, Version 1.0 (the "License").
|
|
|
|
* It is basically the Apache License, Version 2.0 (the "License") plus the
|
|
|
|
* "powered by wisemapping" text requirement on every single page;
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the license at
|
|
|
|
*
|
|
|
|
* http://www.wisemapping.org/license
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
2014-01-25 23:21:17 -03:00
|
|
|
package com.wisemapping.dao;
|
|
|
|
|
|
|
|
import com.wisemapping.model.Label;
|
2014-01-26 18:21:01 -03:00
|
|
|
import com.wisemapping.model.User;
|
2014-01-25 23:21:17 -03:00
|
|
|
import org.jetbrains.annotations.NotNull;
|
2014-01-28 02:28:16 -03:00
|
|
|
import org.jetbrains.annotations.Nullable;
|
2020-11-07 11:56:38 -08:00
|
|
|
import org.springframework.orm.hibernate5.support.HibernateDaoSupport;
|
2014-01-25 23:21:17 -03:00
|
|
|
|
2014-01-26 18:21:01 -03:00
|
|
|
import java.util.List;
|
|
|
|
|
2014-01-25 23:21:17 -03:00
|
|
|
public class LabelManagerImpl extends HibernateDaoSupport
|
|
|
|
implements LabelManager {
|
|
|
|
|
|
|
|
@Override
|
2014-01-26 18:18:49 -03:00
|
|
|
public void addLabel(@NotNull final Label label) {
|
2014-01-25 23:21:17 -03:00
|
|
|
saveLabel(label);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2014-01-26 18:18:49 -03:00
|
|
|
public void saveLabel(@NotNull final Label label) {
|
2020-11-07 11:56:38 -08:00
|
|
|
currentSession().save(label);
|
2014-01-25 23:21:17 -03:00
|
|
|
}
|
2014-01-26 18:21:01 -03:00
|
|
|
|
|
|
|
@NotNull
|
|
|
|
@Override
|
2020-11-07 11:56:38 -08:00
|
|
|
@SuppressWarnings("unchecked")
|
2014-01-26 18:21:01 -03:00
|
|
|
public List<Label> getAllLabels(@NotNull final User user) {
|
2020-11-07 11:56:38 -08:00
|
|
|
var query = currentSession().createQuery("from com.wisemapping.model.Label wisemapping where creator_id=:creatorId");
|
|
|
|
query.setParameter("creatorId", user.getId());
|
|
|
|
return query.list();
|
2014-01-26 18:21:01 -03:00
|
|
|
}
|
2014-01-28 02:28:16 -03:00
|
|
|
|
|
|
|
@Nullable
|
|
|
|
@Override
|
2014-02-11 02:04:09 -03:00
|
|
|
public Label getLabelById(int id, @NotNull final User user) {
|
2020-11-07 11:56:38 -08:00
|
|
|
var query = currentSession().createQuery("from com.wisemapping.model.Label wisemapping where id=:id and creator=:creator");
|
|
|
|
query.setParameter("id", id);
|
|
|
|
query.setParameter("creator", user);
|
|
|
|
return getFirst(query.list());
|
2014-01-28 02:28:16 -03:00
|
|
|
}
|
|
|
|
|
2014-01-28 02:21:14 -03:00
|
|
|
@Nullable
|
|
|
|
@Override
|
|
|
|
public Label getLabelByTitle(@NotNull String title, @NotNull final User user) {
|
2020-11-07 11:56:38 -08:00
|
|
|
var query = currentSession().createQuery("from com.wisemapping.model.Label wisemapping where title=:title and creator=:creator");
|
|
|
|
query.setParameter("title", title);
|
|
|
|
query.setParameter("creator", user);
|
|
|
|
return getFirst(query.list());
|
2014-01-28 02:21:14 -03:00
|
|
|
}
|
2014-01-28 02:28:16 -03:00
|
|
|
|
2014-01-30 04:35:48 -03:00
|
|
|
@Override
|
|
|
|
public void removeLabel(@NotNull Label label) {
|
|
|
|
getHibernateTemplate().delete(label);
|
|
|
|
}
|
|
|
|
|
2014-02-11 02:04:09 -03:00
|
|
|
@Nullable private Label getFirst(List<Label> labels) {
|
|
|
|
Label result = null;
|
|
|
|
if (labels != null && !labels.isEmpty()) {
|
|
|
|
result = labels.get(0);
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
2014-01-28 02:28:16 -03:00
|
|
|
|
2014-01-25 23:21:17 -03:00
|
|
|
}
|