Example usage for org.springframework.data.mongodb.core.query Update Update

List of usage examples for org.springframework.data.mongodb.core.query Update Update

Introduction

In this page you can find the example usage for org.springframework.data.mongodb.core.query Update Update.

Prototype

Update

Source Link

Usage

From source file:com.epam.ta.reportportal.database.search.UpdateStatisticsQueryBuilder.java

/**
 * Complex update operator for MongoDB with positive or negative increment
 * for all defined issue sub-types of specified test item.
 * //from w ww.j a v a 2 s. c  o  m
 * @param item
 * @param isReset
 * @return Update
 */
/* DELETE methods in old statistics */
public static Update fromIssueTypeAware(final TestItem item, boolean isReset) {
    IssueCounter issueCounter = item.getStatistics().getIssueCounter();
    /* MongoDB Update object instance initialization */
    Update issueStatusAware = new Update();
    issueCounter.getAutomationBug().forEach((k, v) -> {
        int negative = v * -1;
        issueStatusAware
                .inc(ISSUE_COUNTER + "." + AUTOMATION_BUG.awareStatisticsField() + "." + k,
                        isReset ? negative : v)
                .inc(ISSUE_COUNTER + "." + AUTOMATION_BUG.awareStatisticsField() + ".total",
                        isReset ? negative : v);
    });
    issueCounter.getProductBug().forEach((k, v) -> {
        int negative = v * -1;
        issueStatusAware
                .inc(ISSUE_COUNTER + "." + PRODUCT_BUG.awareStatisticsField() + "." + k, isReset ? negative : v)
                .inc(ISSUE_COUNTER + "." + PRODUCT_BUG.awareStatisticsField() + ".total",
                        isReset ? negative : v);
    });
    issueCounter.getSystemIssue().forEach((k, v) -> {
        int negative = v * -1;
        issueStatusAware
                .inc(ISSUE_COUNTER + "." + SYSTEM_ISSUE.awareStatisticsField() + "." + k,
                        isReset ? negative : v)
                .inc(ISSUE_COUNTER + "." + SYSTEM_ISSUE.awareStatisticsField() + ".total",
                        isReset ? negative : v);
    });
    issueCounter.getNoDefect().forEach((k, v) -> {
        int negative = v * -1;
        issueStatusAware
                .inc(ISSUE_COUNTER + "." + NO_DEFECT.awareStatisticsField() + "." + k, isReset ? negative : v)
                .inc(ISSUE_COUNTER + "." + NO_DEFECT.awareStatisticsField() + ".total", isReset ? negative : v);
    });
    issueCounter.getToInvestigate().forEach((k, v) -> {
        int negative = v * -1;
        issueStatusAware
                .inc(ISSUE_COUNTER + "." + TO_INVESTIGATE.awareStatisticsField() + "." + k,
                        isReset ? negative : v)
                .inc(ISSUE_COUNTER + "." + TO_INVESTIGATE.awareStatisticsField() + ".total",
                        isReset ? negative : v);
    });
    return issueStatusAware;
}

From source file:no.nlf.dal.ParachutistController.java

public Parachutist update(Parachutist parachutist) {
    MongoParachutist mongoParachutist = new MongoParachutist(parachutist);

    Update updateMongoParacutist = new Update();

    Query queryMongoParachutists = new Query(Criteria.where("melwinId").is(mongoParachutist.getMelwinId()));

    updateMongoParacutist.set("memberclubs", mongoParachutist.getMemberclubs());
    updateMongoParacutist.set("licenses", mongoParachutist.getLicenses());
    updateMongoParacutist.set("firstname", mongoParachutist.getFirstname());
    updateMongoParacutist.set("lastname", mongoParachutist.getLastname());
    updateMongoParacutist.set("bithdate", mongoParachutist.getBirthdate());
    updateMongoParacutist.set("street", mongoParachutist.getStreet());
    updateMongoParacutist.set("gender", mongoParachutist.getGender());
    updateMongoParacutist.set("phone", mongoParachutist.getPhone());
    updateMongoParacutist.set("mail", mongoParachutist.getMail());
    updateMongoParacutist.set("postnumber", mongoParachutist.getPostnumber());
    updateMongoParacutist.set("postplace", mongoParachutist.getPostplace());

    mongoParachutist = appContext.mongoOperation().findAndModify(queryMongoParachutists, updateMongoParacutist,
            new FindAndModifyOptions().returnNew(true), MongoParachutist.class);

    if (mongoParachutist != null) {
        return mongoParachutist.toParachutist();
    }/*from www.j a  v  a 2  s. com*/

    return new Parachutist();
}

From source file:it.f2informatica.mongodb.repositories.impl.ConsultantRepositoryImpl.java

@Override
public int addEducation(Education education, String consultantId) {
    Query query = whereConsultantIdIs(consultantId);
    Update update = new Update().addToSet(EDUCATIONS, education);
    return updateConsultant(query, update).getN();
}

From source file:eu.trentorise.game.managers.DBPlayerManager.java

private StatePersistence persist(String gameId, String playerId, List<GenericObjectPersistence> concepts,
        CustomData customData, Map<String, Object> metadata) {
    if (StringUtils.isBlank(gameId) || StringUtils.isBlank(playerId)) {
        throw new IllegalArgumentException("field gameId and playerId of PlayerState MUST be set");
    }//from ww w . j  a v a  2 s.  com

    Criteria criteria = new Criteria();
    criteria = criteria.and("gameId").is(gameId).and("playerId").is(playerId);
    Query query = new Query(criteria);
    Update update = new Update();
    if (concepts != null) {
        update.set("concepts", concepts);
    }
    if (customData != null) {
        update.set("customData", customData);
    }
    if (metadata != null) {
        update.set("metadata", metadata);
    }
    FindAndModifyOptions options = new FindAndModifyOptions();
    options.upsert(true);
    options.returnNew(true);
    return mongoTemplate.findAndModify(query, update, options, StatePersistence.class);
}

From source file:com.trenako.repositories.mongo.WishListsRepositoryImpl.java

@Override
public void saveChanges(WishList wishList) {
    Update upd = new Update().set("name", wishList.getName()).set("slug", wishList.slug())
            .set("notes", wishList.getNotes()).set("budget", wishList.getBudget())
            .set("visibility", wishList.getVisibility()).set("lastModified", now());
    mongoTemplate.updateFirst(query(where("slug").is(wishList.getSlug())), upd, WishList.class);
}

From source file:it.f2informatica.mongodb.repositories.impl.ConsultantRepositoryImpl.java

@Override
public int updateEducation(Education education, String consultantId) {
    Query query = new Query(
            where(ID).is(consultantId).and(EDUCATIONS + "." + Fields.UNDERSCORE_ID).is(education.getId()));
    Update update = new Update().set(EDUCATIONS + ".$", education);
    return updateConsultant(query, update).getN();
}

From source file:it.f2informatica.mongodb.repositories.impl.ConsultantRepositoryImpl.java

@Override
public int removeEducation(String consultantId, String educationId) {
    Query query = new Query(
            where(ID).is(consultantId).and(EDUCATIONS + "." + Fields.UNDERSCORE_ID).is(educationId));
    Update update = new Update().pull(EDUCATIONS, findEducation(consultantId, educationId));
    return updateConsultant(query, update).getN();
}

From source file:com.enitalk.controllers.OpentokSessionController.java

public void enter(@RequestBody ObjectNode json) throws IOException {
    try {//from w  w w.  j a v  a 2 s  .  co m
        logger.info("Joined video session {}", json);
        String ev = json.path("i").asText();
        String dest = json.path("dest").asText();

        HashMap<String, Object> jev = new HashMap<>();
        jev.put("time", new Date());
        jev.put("dest", dest);

        mongo.updateFirst(Query.query(Criteria.where("ii").is(ev)), new Update().push("joins", jev), "events");
    } catch (Exception e) {
        logger.error(ExceptionUtils.getFullStackTrace(e));
    }
}

From source file:com.epam.ta.reportportal.database.dao.ReportPortalRepositoryImpl.java

@Override
public void partialUpdate(T t) {
    ID id = getEntityInformation().getId(t);
    if (null == id) {
        throw new IllegalArgumentException("ID property should not be null");
    }//from   ww  w  . j ava 2 s.co  m

    Update update = new Update();
    final MongoPersistentEntity<?> persistentEntity = mongoOperations.getConverter().getMappingContext()
            .getPersistentEntity(getEntityInformation().getJavaType());
    persistentEntity.doWithProperties((PropertyHandler<MongoPersistentProperty>) persistentProperty -> {
        if (!persistentEntity.isIdProperty(persistentProperty)) {
            Object value = Accessible.on(t).field(persistentProperty.getField()).getValue();
            if (null != value) {
                update.set(persistentProperty.getFieldName(), value);
            }
        }
    });

    WriteResult writeResult = mongoOperations.updateFirst(
            query(where(persistentEntity.getIdProperty().getFieldName()).is(id)), update,
            getEntityInformation().getCollectionName());
    if (1 != writeResult.getN()) {
        throw new IncorrectResultSizeDataAccessException(1, writeResult.getN());
    }
}

From source file:it.f2informatica.core.gateway.mongodb.UserRepositoryGatewayMongoDB.java

@Override
public void updateUser(UserModel userModel) {
    Query query = query(where("id").is(userModel.getUserId()));
    Update update = new Update().set("username", userModel.getUsername())
            .set("role", roleRepository.findOne(userModel.getRole().getRoleId()))
            .set("lastName", userModel.getLastName()).set("firstName", userModel.getFirstName())
            .set("email", userModel.getEmail());
    mongoTemplate.updateFirst(query, update, User.class).getLastError().ok();
}